Description
- The circumstances in Part 1 and Part 3 are re-examined with the observer now being a human listening binaurally.
MatLab Code (Part 1)
M-File:::::::::
Proj1p4.m
________________
%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: ');
%Constants and Initializations
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
%Doppler Calculation Algorithm
for i=1:length(t)
di=t(i)*v; %Distance source has traveled since t=0
diR=abs(d-di+(.017/2));
diL=abs(d-di-(.017/2));
ioR(i)=a/diR;
ioL(i)=a/diL;
if i<(d/v)*fs
fo(i)=f0*(c/(c-v));
vo(i)=v;
end
if i>(d/v)*fs
fo(i)=f0*(c/(c+v));
vo(i)=-v;
end
if i==(d/v)*fs
fo(i)=f0;
vo(i)=v;
ioR(i)=a;
ioL(i)=a;
end
end
soR=[ioR.*sin(2*pi*fo.*t)]';
soL=[ioL.*sin(2*pi*fo.*t)]';
so=[soR, soL];
%Plots
subplot(411); plot(t, fo); title('Observed Frequency');
xlabel('Time, sec'); ylabel('Frequency, Hz');
subplot(412); plot(t, 20*log10(ioL)); title('Oberseved Loudness (Left Ear)');
xlabel('Time, sec'); ylabel('Intensity, dB');
subplot(413); plot(t, 20*log10(ioR)); title('Oberseved Loudness (Right Ear)');
xlabel('Time, sec'); ylabel('Intensity, dB');
subplot(414); 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(so, fs, 'P4');
_________________________
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: 1
The sound source is moving at a constant velocity, v.
Enter the velocity of the sound source: 20
The sound source begins at a distance, d, from the observer.
Enter the initial distance of the sound source: 30

Generated Wave File :::::
P4.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.