pause off;
clear all; clc;
c = 345; % speed of sound in m/s
fs = 8000; % sampling rate
f0 = 440; % source frequency
A = 1; % source amplitude
T = 6; % total time in seconds
l = 100; % path length in meters
Vs = l/T; % speed of source - m/s
y = 0; % distance from observer to sound path in metets
t = -T/2:1/fs:T/2; % array of time
x = t .* Vs; % array of source position
d = sqrt(x.^2 + y.^2); % array of source distance in meters
Va = Vs .* cos((atan2(y,x))); % array of apparent velocity
d(d<1) = 1; % prevent divide by zero
env = 1./d; % array of amplitude envelope
Fa = f0.*(c./(c+Va)); % array of apparent frequency in hz
Wa = 2*pi*Fa; % array of apparent frequncy in rad/s
wav = env.*cos(Wa.* t); % array of waveform samples
%wav = .95 * wav ./ max(abs(wav));
soundsc (wav, fs);
wavwrite (wav,16,'prob1.wav');
subplot(3,1,1); plot(t, Va); title('Apparent Velocity of Source');
xlabel('time (s)'); ylabel('velocity (m/s)');
subplot(3,1,2); plot(t, env); title('Apparent Amplitude of Source');
xlabel('time (s)'); ylabel('amplitude');
subplot(3,1,3); plot(t, Fa); title('Apparent Frequency of Source');
xlabel('time (s)'); ylabel('frequency (hz)');
saveas(gcf,'prob1.png'); % save the graph as a png image