%
m_per_ft = 0.3048;
ft_per_m = 1./m_per_ft;
%
mph_per_ftps = 0.68182;
%
disp(' ');
disp(' doppler.m      ver 1.0    December 22, 2008 ');
disp(' by Tom Irvine   Email: tomirvine@aol.com ');
%
disp(' ');
disp(' Select system');
disp(' 1=English  2=metric ');
isys=input(' ');
%
	if(isys ~=1 && isys ~=2 )
        isys=1;
    end    
%
    disp(' ');
	if(isys==1)
		disp(' Enter speed of sound (ft/sec) Typical speed = 1120 ft/sec ');
		unit='ft/sec';   
	else
		disp(' Enter speed of sound (m/sec)  Typical speed = 343 m/sec ');
		unit='m/sec';
    end    
%
	ssp=input(' ');
    c=ssp;
%
    disp(' ');
	disp(' Select analysis type.  Calculate ');
	disp(' 1=apparent frequency');
	disp(' 2=source frequency');
	disp(' 3=source velocity');
	disp(' 4=receiver velocity ');
%	
	itype=input(' ');
%
	if(itype==1)  % apparent frequency
%	
		disp(' Enter source frequency (Hz) ');
		fs=input(' ');
%        
		disp(' ');
        out5 = sprintf(' Enter source velocity (%s) ',unit);
        disp(out5);  
   		u=input(' ');     
%        
		disp(' ');
        out5 = sprintf(' Enter receiver velocity (%s) ',unit);
        disp(out5);  
   		v=input(' ');     
%
		if(u>=c)
			disp(' Error.  Source velocity must be less than speed of sound. ');
        end    
		if(v>=c)
			disp(' Error.  Receiver velocity must be less than speed of sound. ');
        end
		if(u<c && v<c)
			fa=fs*((c-v)/(c-u));
            out5 = sprintf(' Apparent frequency = %8.4g Hz  ',fa);
            disp(out5);             
        end
%
    end
	if(itype==2)  % source frequency
%
		disp(' Enter apparent frequency (Hz)  ');
		fa=input(' ');
		out5=sprintf(' Enter source velocity (%s) ',unit);
        disp(out5);
		u=input(' ');
		out6=sprintf(' Enter receiver velocity (%s) ',unit);
        disp(out6);
		v=input(' ');
%
		if(u>=c)
			disp(' Error.  Source velocity must be less than speed of sound. ');
        end    
		if(v>=c)
			disp(' Error.  Receiver velocity must be less than speed of sound. ');
        end
		if(u<c && v<c)
			fs=fa/((c-v)/(c-u));
			out5=sprintf(' Source frequency = %8.4g Hz ',fs);
            disp(out5);
        end    
    end
	if(itype==3)  % source velocity
%	
		disp(' Enter apparent frequency (Hz)  ');
		fa=input(' ');
		disp(' Enter source frequency (Hz)  ');
		fs=input(' ');
		out5 = sprintf(' Enter receiver velocity (%s) ',unit);
		disp(out5);
        v=input(' ');
%		
		if(v>=c)
			disp(' Error.  Receiver velocity must be less than speed of sound. ');
        end    
		if(v<c)
			u=-((fs/fa)*(c-v))+c;
			if(isys==1)
				uftps=u;
				umps=uftps*m_per_ft;
            else    
				umps=u;
				uftps=umps*ft_per_m;
            end    
			umph=uftps*mph_per_ftps;
%
			out5 = sprintf(' Source velocity = %8.4g ft/sec ',uftps);
		 	out6 = sprintf('                 = %8.4g mph ',umph);
			out7 = sprintf('                 = %8.4g m/sec ',umps);
            disp(out5)
            disp(out6)
            disp(out7)
        end
%
    end
	if(itype==4)  % receiver velocity
%	
		disp(' Enter apparent frequency (Hz)  ');
		fa=input(' ');
		disp(' Enter source frequency (Hz)  ');
		fs=input(' ');
		out7 = sprintf(' Enter source velocity (%s) ',unit);
        disp(out7)
		u=input(' ');
%
		if(u>=c)
			disp(' Error.  Source velocity must be less than speed of sound. ');
        end
		if(u<c)
			v=-((fa/fs)*(c-u))+c;
%
			if(isys==1)
				vftps=v;
				vmps=vftps*m_per_ft;
			else
				vmps=v;
				vftps=vmps*ft_per_m;
            end
%
			vmph=vftps*mph_per_ftps;
%
			out5 = sprintf(' Receiver velocity = %8.4g ft/sec ',vftps);
		 	out6 = sprintf('                   = %8.4g mph ',vmph);
			out7 = sprintf('                   = %8.4g m/sec ',vmps);	
            disp(out5)
            disp(out6)
            disp(out7)            
%
       end      
   end
%
df=fa-fs;
%
disp(' ');
out5=sprintf(' Frequency shift = %8.4g Hz ',df);
disp(out5)