%% Spectrogram and Reassigned Spectrogram of Chirp
% Generate a quadratic chirp sampled at 1 kHz for 2 seconds. The chirp has an initial frequency of 100 Hz that increases to 200 Hz at t = 1 second. Compute the spectrogram using the default settings of the pspectrum function.

fs = 1e3;
t = 0:1/fs:2;
y = chirp(t,100,1,200,'quadratic');

[sp,fp,tp] = pspectrum(y,fs,'spectrogram');

mesh(tp,fp,sp)
view(-15,60)
xlabel('Time (s)')
ylabel('Frequency (Hz)')

%
% Compute the reassigned spectrogram. Specify a frequency resolution of 10 Hz. Visualize the result using the pspectrum function with no output arguments.

pspectrum(y,fs,'spectrogram','FrequencyResolution',10,'Reassign',true)

%
% Recompute the spectrogram using a time resolution of 0.2 second.

pspectrum(y,fs,'spectrogram','TimeResolution',0.2)

%
% Compute the reassigned spectrogram using the same time resolution.

pspectrum(y,fs,'spectrogram','TimeResolution',0.2,'Reassign',true)

% Copyright 2012 The MathWorks, Inc.