Fs=8000; Ts=1/Fs; c=345; L=input('What is the distance from the source to the observer? '); d=input('What is the distance of the observer offset from the source path? '); v=input('What is the velocity of the source? '); T=L/v; % time it takes for source to move to the midway point is distance/velocity ti=0:Ts:T; % time from the beginning to the midpoint tf=T:Ts:(2*T); % time from the midpoint to the end t=[ti tf]; %matrix for times L1=v*ti; %distance traveled after ti v_o=v.*cos(atan(d./L1)); %observed velocity H=sqrt((L1.^2)+(d^2)); %hypotenuse, distance between observer and source at time 0 b=.8; %amplitude b1=b./(H+1); b2=fliplr(b1); b3=[b2 b1]; %amplitude matrix F0=440; %frequency of source F1=F0*c./(c+v_o); %observed frequency as source gets closer F2=F0*c./(c-v_o); %observed frequency as source gets further F3=fliplr(F2); F4=[F3 F1]; %frequency matrix y=b3.*sin(2*pi.*F4.*t); % signal equation % plot frequency, amplitude, & velocity figure(1) plot(t,y); xlabel('Time (s)'); ylabel('Velocity (m/s)'); Title('Dopper Effect: Velocity of source relative to observer'); figure(2) plot(t,b3); xlabel('Time (s)'); ylabel('Amplitude'); Title('Dopper Effect: The signal envelope'); figure(3) plot(t,F4); xlabel('Time (s)'); ylabel('Frequency (Hz)'); Title('Dopper Effect: The apparent frequency of the source'); wavwrite(y,Fs,'doppler2'); %save the sound