Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Doppler effect - how if possible

Subject: Doppler effect - how if possible

From: ZikO

Date: 26 Oct, 2008 15:26:48

Message: 1 of 13

Hi.

IS it possible to apply Doppler Effect in MATLAB?

This means that frequency in wave vector is going to be changed smoothly
according to another function which is for example velocity. Let's say
frequency is changed the most at the edge of wave file but not changed
at all in the middle of vector.
Is it possible to do that?

Thanks for any suggestions.

Subject: Doppler effect - how if possible

From: Lars

Date: 26 Oct, 2008 16:39:01

Message: 2 of 13

perhaps something like freq-modulation?

try:

t = (0:0.01:1)

f_1 = 1;
f_2 = 30;

sin( sin(2*pi*f_1*t) * 2*pi*f_2*t );

Lars

Subject: Doppler effect - how if possible

From: Lothar Schmidt

Date: 27 Oct, 2008 08:54:45

Message: 3 of 13

Lars schrieb:
> perhaps something like freq-modulation?
>
> try:
>
> t = (0:0.01:1)
>
> f_1 = 1;
> f_2 = 30;
>
> sin( sin(2*pi*f_1*t) * 2*pi*f_2*t );
>
> Lars

isn't FM like this:
sin( 2*pi*f_2*( t + somefactor*sin(2*pi*f_1*t) );

Subject: Doppler effect - how if possible

From: Lars

Date: 27 Oct, 2008 09:33:02

Message: 4 of 13

Exactely. It was just a 'shoot from the hip '. Thank you.

Subject: Doppler effect - how if possible

From: ZikO

Date: 27 Oct, 2008 21:18:31

Message: 5 of 13

Lothar Schmidt wrote:
> Lars schrieb:
>> perhaps something like freq-modulation?
>>
>> try:
>>
>> t = (0:0.01:1)
>>
>> f_1 = 1;
>> f_2 = 30;
>>
>> sin( sin(2*pi*f_1*t) * 2*pi*f_2*t );
>>
>> Lars
>
> isn't FM like this:
> sin( 2*pi*f_2*( t + somefactor*sin(2*pi*f_1*t) );
can u please elaborate it. I dont know how FM is related to Doppler
Effect and what that factor "somefactor" depends on :/

Subject: Doppler effect - how if possible

From: ZikO

Date: 27 Oct, 2008 21:24:19

Message: 6 of 13

Lars wrote:
> perhaps something like freq-modulation?
>
> try:
>
> t = (0:0.01:1)
>
> f_1 = 1;
> f_2 = 30;
>
> sin( sin(2*pi*f_1*t) * 2*pi*f_2*t );
>
> Lars

Im affraid I have more complex problem than simulating Doppler Effect on
simple sin wave. I need to resample wavfile according to Doppler effect
such that frequency rate of wave file might change between 1.1*f0 to
0.9*f0. RESAMPLE and INTERP function work only on integer numbers I need
more complex function, somthing wich resample wavefile and filter it
getting rid of unwanted high freq components :/

Subject: Doppler effect - how if possible

From: aasim Azooz

Date: 28 Oct, 2008 00:17:03

Message: 7 of 13

ZikO <zebik@op.pl> wrote in message <ge227s$947$1@news.onet.pl>...
> Hi.
>
> IS it possible to apply Doppler Effect in MATLAB?
>
> This means that frequency in wave vector is going to be changed smoothly
> according to another function which is for example velocity. Let's say
> frequency is changed the most at the edge of wave file but not changed
> at all in the middle of vector.
> Is it possible to do that?
>
> Thanks for any suggestions.
Dear Ziko
if f0 is your static frequency, V,V0 and Vs are wave, observer and sourse velocities respectively, the our wave will be
y=sin(2*pi*f0*((V+Vs)/(V-V0))*t).
if the sourse is vibrating with frequency F then
Vs=(1./2*pi*F)*cos(2*pi*F*t).
The same applies to observer.
This should do the job
I refer you to my paper in American Journal of Physics
Am. J. Phys., Vol. 75, No. 2, February 2007

Subject: Doppler effect - how if possible

From: ZikO

Date: 29 Oct, 2008 08:51:14

Message: 8 of 13

aasim Azooz wrote:
> ZikO <zebik@op.pl> wrote in message <ge227s$947$1@news.onet.pl>...
>> Hi.
>>
>> IS it possible to apply Doppler Effect in MATLAB?
>>
>> This means that frequency in wave vector is going to be changed smoothly
>> according to another function which is for example velocity. Let's say
>> frequency is changed the most at the edge of wave file but not changed
>> at all in the middle of vector.
>> Is it possible to do that?
>>
>> Thanks for any suggestions.
> Dear Ziko
> if f0 is your static frequency, V,V0 and Vs are wave, observer and sourse velocities respectively, the our wave will be
> y=sin(2*pi*f0*((V+Vs)/(V-V0))*t).
> if the sourse is vibrating with frequency F then
> Vs=(1./2*pi*F)*cos(2*pi*F*t).
> The same applies to observer.
> This should do the job
> I refer you to my paper in American Journal of Physics
> Am. J. Phys., Vol. 75, No. 2, February 2007
>
>
Thanks. It helped me a lot =)

Subject: Doppler effect - how if possible

From: Lothar Schmidt

Date: 29 Oct, 2008 11:32:05

Message: 9 of 13

ZikO schrieb:
> Lothar Schmidt wrote:
>> Lars schrieb:
>>> perhaps something like freq-modulation?
>>>
>>> try:
>>>
>>> t = (0:0.01:1)
>>>
>>> f_1 = 1;
>>> f_2 = 30;
>>>
>>> sin( sin(2*pi*f_1*t) * 2*pi*f_2*t );
>>>
>>> Lars
>>
>> isn't FM like this:
>> sin( 2*pi*f_2*( t + somefactor*sin(2*pi*f_1*t) );
> can u please elaborate it. I dont know how FM is related to Doppler
> Effect and what that factor "somefactor" depends on :/

i will shurely elaborate it as soon as i'll have the same problem as
you. I bet you'll find a faster solution if you try it yourself. As far
as I remeber somefactor will depend on modulation depth and your
samplingrate.

Subject: Doppler effect - how if possible

From: ZikO

Date: 31 Oct, 2008 18:08:20

Message: 10 of 13

>
> i will shurely elaborate it as soon as i'll have the same problem as
> you. I bet you'll find a faster solution if you try it yourself. As far
> as I remeber somefactor will depend on modulation depth and your
> samplingrate.

thanks you =)

Subject: Doppler effect - how if possible

From: ZikO

Date: 31 Oct, 2008 18:39:29

Message: 11 of 13

ZikO wrote:
> Hi.
>
> IS it possible to apply Doppler Effect in MATLAB?

Hi again.
I am going to show you what I have done so far and where is my next
problems. This post is much longer than usual one here. Sorry I really
didnt know how I would do that other way. I wanted to show my problem here.

I have generated a simulation of siren by formulae below:

[code]
..fs = 11025;
..t = linspace(0,5,5*fs);
..y = sin(2*pi*660.*(t + 0.04*sin(2*pi*2.*t)));
[/code]

and next I wanted to apply frequency changes due to Doppler Effect when
source of sound is coming closer, getting point where velocity changes =
0 and going away. The curve of frequency changes is highly non-linear.
So what I have done is I tried to "chop" wafile into chunks as well as
freq coefficinet vector (see below in my code). For all chunks I have
calculated average freq coefficient and I have applied RESAMPLE
function. Then I joint all chunks to one another. That is supposed to be
output vector.

Sorry if code is long but I have no idea how to do it other way

[code]
function [yout f_coeff] = doppler_effect(input, v, x0, y0)
% [yout f_coeff] = doppler_effect(input, v_mph, x0, y0)

%% generating vector of changes of frequency due to doppler effect
% ************ First part
N = length(input);
x = linspace(-x0, x0, N);
alpha = atan(y0./-x); % angle between line the source is moving along
and line connected source and receiver
index = find(alpha < 0, 1, 'first'); % index of first
negative value
alpha(index:N) = pi + alpha(index:N); % atan counts angle
between (-pi, pi)
                                                 % to compensate that, pi
                                                 % is added to all
negative alphas
c = 343; % sound velocity
v2 = v*1.61/3.6; % mile per hour -> meter
per sec
vdoppler = v2.*cos(alpha); % velocity changes due
to the
                                                 % angle between source and
                                                 % receiver
v0 = 0; % the velocity of the
receiver is = 0
f_coeff = (c + vdoppler)/(c - v0); % coefficient f/f0 where
f0 is a base frequency

%% Applying Doppler effect to resample wavfile
% ************ Second part
chunk_length = 50; % length of one chunk
no_of_chunks = floor(N/chunk_length); % no of chunks
yout = 0;
for chunk_no = 0:no_of_chunks
     istart = chunk_length*chunk_no + 1;
     if chunk_no < no_of_chunks
         iend = chunk_length*(chunk_no + 1);
     else
         if(mod(N,no_of_chunks) ~= 0)
             iend = chunk_length*chunk_no + mod(N,no_of_chunks);
         else
             iend = chunk_length*(chunk_no + 1);
         end
     end
     fcoeff_av = floor(mean(f_coeff(istart:iend))*100)/100;
     yout = [yout resample(input(istart:iend), 100, floor(fcoeff_av*100))];
end
[/code]

Example

fs = 11025;
t = linspace(0,5,5*fs);
y = sin(2*pi*660.*(t + 0.04*sin(2*pi*2.*t)));

Let us say source speed is 70 mph; receiver is staying at 3.5 m from the
"line" the source is moving along and simulation starts where source
starts to move at 100 m to 100 m to the other direction.

[y2 f] = doppler_effect(y, 70, 100, 3.5);

The problem I found here is the resampled sound is distorted. I tried to
filetr this but it does not quite work. I suspect that I generated a lot
of discontinuities in yout vector when I resampled chunks.

I dont know how to get rid of them. Does any1 has any idea. Thank you.

Subject: Doppler effect - how if possible

From: Kristian Beedholm

Date: 1 Feb, 2013 21:43:08

Message: 12 of 13

If your sampled signal is of a reasonable size, you can do this easily by applying the fft method of interpolation.

An example might be this:

function [sigout]=interpolate2(sigin,fak) %fak is the Doppler factor
L=length(sigin);
IN=fft(sigin);
IN(round(length(IN)/2)+1:floor(fak*L))=0;
if N<1,IN(round(fak*L/2)+1:L)=0;end;
IN=fak*IN(1:floor(fak*L));
IN(1)=IN(1)/2; %a tricky one, the DC is!
sigout=2*real(ifft(IN)); %times 2 because the spectrum is onesided

If the signal is VERY long, you may have to do this in parts.

Subject: Doppler effect - how if possible

From: Rod Lopez

Date: 26 Sep, 2013 21:24:04

Message: 13 of 13

I found on the forum a note about a pass work that you did it with a Doppler Effect. If doesn't bother you, I need to simulate a similar Project with a Siren oscillating between 300Hz and 600Hz passing in front of stationary observer to certain distance between the source path.Also I need to write the sound, similar what you did it.
Could I see the code that you write for your project?
Thank you,
Rod.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us