%% Deep Learning Short-Time Fourier Transform of Chirp
% Generate a signal sampled at 600 Hz for 2 seconds. The signal consists of a chirp with sinusoidally varying frequency content.

fs = 6e2;
t = 0:1/fs:2;
x = vco(sin(2*pi*t),[0.1 0.4]*fs,fs);

% Store the signal in an unformatted deep learning array. Compute the short-time Fourier transform of the signal. Input the sample time as a duration scalar. (Alternatively, input the sample rate as a numeric scalar.) Specify that the input array is in 'CTB' format.

dlx = dlarray(x);

[yr,yi,f,t] = dlstft(dlx,seconds(1/fs),'DataFormat','CTB');

% Convert the outputs to numeric arrays. Compute the magnitude of the short-time Fourier transform and display it as a waterfall plot.

yr = extractdata(yr);
yi = extractdata(yi);

f = extractdata(f);
t = seconds(t);

waterfall(f,t,squeeze(hypot(yr,yi))')

ax = gca;
ax.XDir = 'reverse';
view(30,45)

ylabel('Time (s)')
xlabel('Frequency (Hz)')
zlabel('Magnitude')

% Copyright 2020 The MathWorks, Inc.