Doppler shift in Matlab?

Status
Not open for further replies.

Rahp

Newbie level 3
Joined
Apr 10, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,295
Hi,

I need to apply the Doppler effect to a music file, I invoke the music file by using the waveread command,

How do I proceed next (frequency spectrum, apparent frequency etc.)?
 

Code:
%}
pause off;
clear all; clc;
c = 345;						% speed of sound in m/s
fs = 8000;						% sampling rate

[x,fs] = wavread('001.wav');
X = fft(x);
f = -fs/2:fs;fs/2;
W = 2*pi*f;					       
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 = f.*(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');

I want this code to apply doppler effect to the input wav file, for this an apparent frequency change must be applied to the wav file's frequency spectrum right?

I get this error at this line Fa = f.*(c./(c+Va));
Code:
??? Error using ==> times
Matrix dimensions must agree.
 

Code:
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

How can I make a GUI using guide from this code?
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…