sweep(startFreq, endFreq, timeLength, amplitude, Fs)
and it creates a sweep(chirp) that goes from the start frequency to the end frequency in timeLength/2, and then back to the starting frequency. So the total sweep time to go from start frequency to end frequency and back takes timeLength. I'm not entirely sure how to create a sweep though...suggestions/help?
Try the CHIRP function from the Signal Processing Toolbox.
If you don't have Sig Proc Tlbx, you can do it manually. Create the
vector of time values (0:1/Fs:timeLength), then create the vector of
frequencies at those instances and use cos().
HTH,
Idin
I looked at the chirp command and for some reason in simulink you can do a bidirectional chirp which is what i want to do, but you can't do one in the regular code. I tried to actually do it the way you described using cos() and i just can't get it to work out for whatever reason.
Fs = 8000; % sampling freq.
T = 1/Fs;
f1 = 10; % initial frequency in chirp
f2 = 20; % final frequency in chirp
tfinal = 3; % duration
amplitude = 1;
tHALF = 0:T:(tfinal/2 - T); % half the time function (length of sweep each way)
m = (f2 - f1)/(tfinal/2); % chirp slope
% create the "frequency" function
f1 = f1 + (m*tHALF);
f2 = f2 - (m*tHALF);
f = [f1 f2];
t = 0:T:tfinal - T; % time function
y = amplitude*cos(2*pi*f.*t);
for some reason it doesn't look right when i plot(t,y) but the values of f and t seem correct...
ZK,
The instantaneous frequency is the derivative of the phase. I haven't
played around with this too much... but try this in your code:
f1 = f1*tHALF + (m*tHALF).*tHALF/2;
f2 = f1(end)+f2*tHALF - (m*tHALF).*tHALF/2;
f = [f1 f2(2:end)];
Now doing a
spectrogram(y,hamming(128),110,[],8000)
shows a pretty clean bidirectional sweep (note that I'm avoiding a
discontinuity in the phase by making sure f2 starts where f1 leaves
off... and make sure no repeat values!)
You could also do something like this:
y1 = chirp(tHALF,10,tHALF(end),1000,'linear');
y2 = chirp(tHALF,1000,tHALF(end),10,'linear',rad2deg(acos(y1(end))));
y = [y1 y2(2:end)];
spectrogram(y,hamming(128),110,[],8000)
(Again, avoid phase discontinuity by using the ending phase of y1 as
initial phase of y2)
HTH,
Idin
--
Idin Motedayen-Aval
The MathWorks, Inc.
zq=[4 2 5 -15 -1 -3 24 -57 45 -12 19 -12 15 -8 3 -7 8 -69 53 12 -2];
char(filter(1,[1,-1],[105 zq])), clear zq