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 %first tone 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 x=sin(2*pi.*F4.*t); % signal equation %second tone F0a=8000; %frequency of source F1a=F0a*c./(c+v_o); %observed frequency as source gets closer F2a=F0a*c./(c-v_o); %observed frequency as source gets further F3a=fliplr(F2a); F4a=[F3a F1a]; %frequency matrix y=sin(2*pi.*F4a.*t); % signal equation %fthird tone F0b=5746; %frequency of source F1b=F0b*c./(c+v_o); %observed frequency as source gets closer F2b=F0b*c./(c-v_o); %observed frequency as source gets further F3b=fliplr(F2b); F4b=[F3b F1b]; %frequency matrix z=sin(2*pi.*F4b.*t); % signal equation three_tone=b3.*(x+y+z); % plot frequency, amplitude, & velocity figure(1) plot(t,three_tone); 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) subplot(3,1,1) plot(t,F4); xlabel('Time (s)'); ylabel('Frequency (Hz)'); Title('Dopper Effect: The apparent frequency of the source, F0=440Hz'); subplot(3,1,2) plot(t,F4a); xlabel('Time (s)'); ylabel('Frequency (Hz)'); Title('Dopper Effect: The apparent frequency of the source, F0a=8000Hz'); subplot(3,1,3) plot(t,F4b); xlabel('Time (s)'); ylabel('Frequency (Hz)'); Title('Dopper Effect: The apparent frequency of the source, F0b=5746Hz'); wavwrite(three_tone,Fs,'doppler3'); %save the sound