Sweep / chirp signal ends at incorrect frequency

The following code explains how to generate a frequency-variable sin wave.

freq1=20; %start freq
freq2=200; %end freq
dur=1; %duration of signal in seconds


freq=@(t)freq1+(freq2-freq1)/dur*t;
%another example, may help to understand the code
%dur=2
%freq=@(t)heaviside(t-1)*10+heaviside(t-1.5)*-9;
%Integerate over the time-local frequency, gives the average frequency until t which later on gives the sin with the right phase
%In case you don't have symbolic toolbox, integrate manually. For the given numbers Ifreq=@(x)x.*(x.*9.0+2.0)
Ifreq=matlabFunction(int(freq(sym('x'))));
%Defining wave function based on `Ifreq`
wave=@(t)(sin(Ifreq(t)*2*pi));
t=0:.00001:dur;
plot(t,wave(t));

Leave a Comment