| 
View
 

EEN502 Project 1 Part 2

Page history last edited by Leon D\'Angio 16 years, 7 months ago

Description:

  • The sound source produces a single tone with frequency, f0.
  • The observer is standing at a distance, r, from the sound source's trajectory.

 

 

 

MatLab Code

M-File ::::  Proj1p2.m

____________________________________

%User Input

%User Input

disp('The sound source in this example is a single tone with frequency, F0.');

f0=input('Enter the frequency of the single tone: ');

disp('The tone has an inate loudness or amplitude, a');

a=input('Enter the amplitude of the signal: ');

disp('The sound source is moving at a constant velocity, v.');

v=input('Enter the velocity of the sound source: ');

disp('The sound source begins at a distance, d, from the observer.');

d=input('Enter the initial distance of the sound source: ');

disp('The observer is a distance, r, from the source`s trajectory,');

r=input('Enter the observer`s distance from the trajectory: ');

%Constants and Initialization

fs=8000;           %Sampling Rate

c=344;              %Speed of Sound in air

t=0:1/fs:2*(d/v);             %X-Axis, Time, seconds

fo=zeros(1,length(t));      %Initialization vector for perceived frequency

io=zeros(1,length(t));      %Initialization vector for perceived loudness

vo=zeros(1,length(t));      %Initialization vector for relative velocity

ango=zeros(1,length(t));    %Initialization vectory for angle

%Doppler Calculation Algorithm

for i=1:length(t)

    

    di=t(i)*v;              %Distance source has traveled since t=0

    di=abs(d-di);           %Distance from observer

    

    if i<=(d/v)*fs

        ango(i)=atan(-r/di);

        vo(i)=v*cos(ango(i));

        fo(i)=f0*(c/(c-vo(i)));

    end

    

    if i>(d/v)*fs

        ango(i)=atan(r/di);

        vo(i)=v*cos(ango(i));

        fo(i)=f0*(c/(c+vo(i)));

    end

    

    hyp(i)=sqrt(r^2 + di^2);

    io(i)=a/hyp(i);

end

s1=io.*sin(2*pi*fo.*t);

%Plots

subplot(311); plot(t, fo); title('Observed Frequency');

xlabel('Time, sec'); ylabel('Frequency, Hz');

subplot(312); plot(t, 20*log10(io)); title('Oberseved Loudness');

xlabel('Time, sec'); ylabel('Intensity, dB');

subplot(313); plot(t, vo); title('Relative Velocity');

xlabel('Time, sec'); ylabel('Velocity, m/s');

axis([0 2*d/v -v-10 v+10]);

%Wav Write

wavwrite(s1, fs, 'P2');

___________

 

 

Sample Execution 

 

The sound source in this example is a single tone with frequency, F0. 

Enter the frequency of the single tone: 440 

The tone has an inate loudness or amplitude, a 

Enter the amplitude of the signal: 3 

The sound source is moving at a constant velocity, v. 

Enter the velocity of the sound source: 10 

The sound source begins at a distance, d, from the observer. 

Enter the initial distance of the sound source: 15 

The observer is a distance, r, from the source`s trajectory,

Enter the observer`s distance from the trajectory: 5

 

 

Generated Wave File ::::::  P2.wav

 

 

-------------------------------------

LINKS

EEN502 Project 1 Part 1

EEN502 Project 1 Part 2

EEN502 Project 1 Part 3

EEN502 Project 1 Part 4 (A)

EEN502 Project 1 Part 4 (B)

 

 

 

 

Comments (0)

You don't have permission to comment on this page.