Generating sinusoidal signal with time dependent frequency in matlab
I want to generate a sine waveform y(t)
with a time dependent frequency f(t)
in Matlab.
I already tried to implement this using Matlab sine function:
h = 0.0001; npoints = 150/h; for i = 1:1:npoints f(i) = 2 - 0.01*i*h; y(i) = 0.5*sin(2*3.1415*f(i)*i*h)+0.5; end
where the frequency decreases with time and h
is the time step width.
My problem:
The signal y(t)
does not look like what I expected. An amplitude relief appears at a specific time (look at the graph below).
Does anyone know why this is happening and how to generate this sinusoidal signal correctly?
source to share
What about
y(i) = 0.5*real(exp(1i*2*pi*f(i)*i*h))+0.5;
If you only want a chirp
signal starting from 2Hz to 0.5Hz, the following job should be done
f_start = 2; % start frequency
f_end = 0.5; % end frequency
endtime = 150; % seconds
timestep = 0.0001;
times = timestep:timestep:endtime;
y = chirp(times,f_start,endtime,f_end);
and if you build it you get
figure(2);plot(times,y);
You can do the same manually using below
f_start = 2; % start frequency
f_end = 0.5; % end frequency
timestep = 0.0001;
T = 150;
rate_of_change = (f_start - f_end)/T;
times = timestep:timestep:T;
y = sin(2*pi*(f_start*times - times.^2*rate_of_change/2));
It might be helpful to read after the Wikipedia page on Chirp signal.
source to share
At 100, you have sin(2*pi*N)
which is 0. Change f a little, say to 2.0123-...
, and it goes back up.
For a general, probably unexpected form, consider which function you use at the end (= replace f in the formula). You can see that you have something like y = ...sin(Ai-B*i^2)...
that has a minimum of 100.
The simplest solution here is to just offset the frequency a little more and use something like f(i) = 3.1 - ...
that has a minimum outside the range in question.
source to share
It looks like there is actually no "shock frequency", but at 100 on the x-axis, the entire signal is 180 degrees shifted . Be aware that the amplitude is still 0 and not decreasing (e.g. 0.25 to 0.75)
This is because the i value gets so high that the f (i) value changes sign .
Another indicator of this is that the frequency starts to increase again after the shift, rather than gradually getting lower still.
Why are you starting with the value 2 in f (i)?
Sorry to ask for clarification here, but I cannot post it as a comment.
source to share