Description
- The circumstances in Part 1 and Part 3 are re-examined with the observer now being a human listening binaurally.
MatLab Code (Part 2)
M-File ::::::
Proj1p4b.m
___________________
%User Input
disp('The sound source is a tone generated by the linear combination of three tones.');
f01=input('Enter the 1st frequency: ');
f02=input('Enter the 2nd frequency: ');
f03=input('Enter the 3rd frequency: ');
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
fo1R=zeros(1,length(t)); %Initialization vector for perceived frequency
fo2R=zeros(1,length(t));
fo3R=zeros(1,length(t));
fo1L=zeros(1,length(t));
fo2L=zeros(1,length(t));
fo3L=zeros(1,length(t));
ioR=zeros(1,length(t)); %Initialization vector for perceived loudness
ioL=zeros(1,length(t)); %Initialization vector for perceived loudness
voR=zeros(1,length(t)); %Initialization vector for relative velocity
voL=zeros(1,length(t)); %Initialization vector for relative velocity
angoR=zeros(1,length(t)); %Initialization vectory for angle
angoL=zeros(1,length(t)); %Initialization vectory for angle
%Doppler Calculation Algorithm
for i=1:length(t)
dt=t(i)*v;
diR=abs(d-dt-(.017/2));
diL=abs(d-dt+(.017/2));
if i<=(d/v)*fs
angoR(i)=atan(-r/diR);
angoL(i)=atan(-r/diL);
voR(i)=v*cos(angoR(i));
voL(i)=v*cos(angoL(i));
fo1R(i)=f01*(c/(c-voR(i)));
fo2R(i)=f02*(c/(c-voR(i)));
fo3R(i)=f03*(c/(c-voR(i)));
fo1L(i)=f01*(c/(c-voL(i)));
fo2L(i)=f02*(c/(c-voL(i)));
fo3L(i)=f03*(c/(c-voL(i)));
end
if i>(d/v)*fs
angoR(i)=atan(r/diR);
angoL(i)=atan(r/diL);
voR(i)=v*cos(angoR(i));
voL(i)=v*cos(angoL(i));
fo1R(i)=f01*(c/(c+voR(i)));
fo2R(i)=f02*(c/(c+voR(i)));
fo3R(i)=f03*(c/(c+voR(i)));
fo1L(i)=f01*(c/(c+voL(i)));
fo2L(i)=f02*(c/(c+voL(i)));
fo3L(i)=f03*(c/(c+voL(i)));
end
hypR(i)=sqrt(r^2 + diR^2);
hypL(i)=sqrt(r^2 + diL^2);
ioR(i)=a/hypR(i);
ioL(i)=a/hypL(i);
end
s1R=ioR.*sin(2*pi*fo1R.*t);
s2R=ioR.*sin(2*pi*fo2R.*t);
s3R=ioR.*sin(2*pi*fo3R.*t);
s1L=ioL.*sin(2*pi*fo1L.*t);
s2L=ioL.*sin(2*pi*fo2L.*t);
s3L=ioL.*sin(2*pi*fo3L.*t);
sR=(1/3)*(s1R+s2R+s3R);
sL=(1/3)*(s1L+s2L+s3L);
sR=sR';
sL=sL';
s=[sR, sL];
%Plots
subplot(321); plot(t, fo1R); title('Observed Frequency 1 (Right Ear)');
xlabel('Time, sec'); ylabel('Frequency, Hz');
subplot(323); plot(t, fo2R); title('Observed Frequency 2 (Right Ear)');
xlabel('Time, sec'); ylabel('Frequency, Hz');
subplot(325); plot(t, fo3R); title('Observed Frequency 3 (Right Ear)');
xlabel('Time, sec'); ylabel('Frequency, Hz');
subplot(322); plot(t, fo1L); title('Observed Frequency 1 (Left Ear)');
xlabel('Time, sec'); ylabel('Frequency, Hz');
subplot(324); plot(t, fo2L); title('Observed Frequency 2 (Left Ear)');
xlabel('Time, sec'); ylabel('Frequency, Hz');
subplot(326); plot(t, fo3L); title('Observed Frequency 3 (Left Ear');
xlabel('Time, sec'); ylabel('Frequency, Hz');
figure;
subplot(221); plot(t, 20*log10(ioR)); title('Oberseved Loudness (Right Ear)');
xlabel('Time, sec'); ylabel('Intensity, dB');
subplot(222); plot(t, 20*log10(ioL)); title('Oberseved Loudness (Left Ear');
xlabel('Time, sec'); ylabel('Intensity, dB');
subplot(223); plot(t, voR); title('Relative Velocity');
xlabel('Time, sec'); ylabel('Velocity, m/s');
%Wav Write
wavwrite(s, fs, 'P4b');
___________________
Sample Execution
The sound source is a tone generated by the linear combination of three tones.
Enter the 1st frequency: 440
Enter the 2nd frequency: 550
Enter the 3rd frequency: 1000
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: 25
The sound source begins at a distance, d, from the observer.
Enter the initial distance of the sound source: 35
The observer is a distance, r, from the source`s trajectory.
Enter the observer`s distance from the trajectory: 5


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