%% Instantaneous Frequency of Chirp
% Generate a quadratic chirp modulated by a Gaussian. Specify a sample rate of 2 kHz and a signal duration of 4 seconds.

fs = 2000;
t = 0:1/fs:4-1/fs;

q = chirp(t-1,0,1/2,20,'quadratic',100,'convex').*exp(-1.7*(t-2).^2);
plot(t,q)

%
% Use the pspectrum function with default settings to estimate the power spectrum of the signal. Use the estimate to compute the instantaneous frequency.

[p,f,t] = pspectrum(q,fs,'spectrogram');

instfreq(p,f,t)

%
% Repeat the calculation using the synchrosqueezed Fourier transform. Use a 500-sample Hann window to divide the signal into segments and window them.

[s,sf,st] = fsst(q,fs,hann(500));

instfreq(abs(s).^2,sf,st)

%
% Compare the instantaneous frequencies found using the two different methods.

[psf,pst] = instfreq(p,f,t);
[fsf,fst] = instfreq(abs(s).^2,sf,st);

plot(fst,fsf,pst,psf)

% Copyright 2012 The MathWorks, Inc.