%
disp(' ');
disp(' aliasing.cpp  ver 1.2   February 16, 2011    ');
disp(' ');
disp(' by Tom Irvine  Email: tomirvine@aol.com  ');
disp(' ');
disp('  Select calculation type: '); 
disp('     1=find resulting aliasing frequency ');
disp('     2=find candidate energy source frequencies ');
%
itype=input(' ');
%
nc=1;
%
if(itype==1)
%
    while(nc==1)
%	
        disp(' ');
		disp(' Enter the sampling rate (samples/sec)');
		sf=input(' ');
        disp(' ');
		disp(' Enter the energy frequency (Hz) ');
		ef=input(' ');
%        
		if(ef<0.5*sf)
            disp(' Aliasing does not occur for this case. ');
        end
		if(ef==0.5*sf)
			disp(' Borderline case. ');
        end
		if(0.5*sf < ef && ef< sf)
			af=sf-ef;
			iflag=1;
        end
		for(m=1:20)
			if(ef==m*sf)
				af=0.;
				iflag=1;
				break;
            end
			if(m*sf < ef && ef< (m+0.5)*sf)	
				af=ef-m*sf;
				iflag=1;
				break;
            end
			if((m+0.5)*sf < ef && ef< (m+1)*sf)
				af=af-ef+(m+1)*sf;
				iflag=1;
				break;
            end
        end
		if(iflag==1)
			out1=sprintf('\n\n aliasing frequency = %8.4g Hz \n',af);
            disp(out1);
        end
        disp(' ');
		disp(' another calculation? 1=yes 2=no ');
		nc=input(' ');
    end
%
else
%
    while(nc==1)
%
        disp(' ');
		disp(' Enter the sampling rate (samples/sec)');
        sf=input(' ');
%
        disp(' ');
		disp(' Enter the resulting aliasing frequency (Hz) ');
        af=input(' ');
%
        disp(' ');
		disp('  Candidate energy frequencies (Hz) ');
	    nf=sf/2.;
		for(m=1:10)
			ef=m*sf-af;
			out1=sprintf('  %9.5g  ',ef);
            disp(out1);
			ef=m*sf+af;
			out2=sprintf('  %9.5g  ',ef);
            disp(out2);
        end
        disp(' ');
		disp('another calculation? 1=yes 2=no ');
		nc=input(' ');
    end
%
end