%% Reconstruction of Linear Chirps
% Generate a signal that consists of two chirps. The signal is sampled at 3 kHz for one second. The first chirp has an initial frequency of 400 Hz and reaches 800 Hz at the end of the sampling. The second chirp starts at 500 Hz and reaches 1000 Hz at the end. The second chirp has twice the amplitude of the first chirp.

fs = 3000;
t = 0:1/fs:1-1/fs;   

x1 = chirp(t,400,t(end),800);
x2 = 2*chirp(t,500,t(end),1000);

%
% Compute and plot the Fourier synchrosqueezed transform of the signal. Display the time on the x-axis and the frequency on the y-axis.

[sst,f] = fsst(x1+x2,fs);
fsst(x1+x2,fs,'yaxis')

%
% Extract the ridge corresponding to the higher-energy component of the signal, which is the chirp with the larger amplitude. Use the ridge to reconstruct the signal.

[~,iridge] = tfridge(sst,f);
 
xrec = ifsst(sst,[],iridge);

%
% Plot the spectrogram for the higher-energy component. Divide the component into 256-sample sections and specify an overlap of 255 samples. Use 512 DFT points and a rectangular window.

spectrogram(xrec,rectwin(256),255,512,fs,'yaxis')

%
% To extract the second chirp, specify that tfridge search for two ridges. The second column of the output is the lower-energy component of the signal.

[~,iridge] = tfridge(sst,f,'NumRidges',2);

xrec = ifsst(sst,[],iridge(:,2));

spectrogram(xrec,rectwin(256),255,512,fs,'yaxis')

%
% Copyright 2012 The MathWorks, Inc.