%% ISTFT of Multichannel Signals
% Generate a three-channel signal consisting of three different chirps sampled at 1 kHz for 1 second.
% The first channel consists of a concave quadratic chirp with instantaneous frequency 100 Hz at t = 0 and crosses 300 Hz at t = 1 second. It has an initial phase equal to 45 degrees.
% The second channel consists of a convex quadratic chirp with instantaneous frequency 200 Hz at t = 0 and crosses 600 Hz at t = 1 second.
% The third channel consists of a logarithmic chirp with instantaneous frequency 300 Hz at t = 0 and crosses 500 Hz at t = 1 second.
% Compute the STFT of the multichannel signal using a periodic Hamming window of length 256 and an overlap length of 15 samples.

fs = 1e3;
t = 0:1/fs:1-1/fs;
x = [chirp(t,100,1,300,'quadratic',45,'concave');
      chirp(t,200,1,600,'quadratic',[],'convex');
      chirp(t,300,1,500,'logarithmic')]'; 
  
[S,F,T] = stft(x,fs,'Window',hamming(256,'periodic'),'OverlapLength',15);

%
% Plot the original and reconstructed versions of the first and second channels.

[ix,ti] = istft(S,fs,'Window',hamming(256,'periodic'),'OverlapLength',15);

plot(t,x(:,1)','LineWidth',1.5)
hold on
plot(ti,ix(:,1)','r--')
hold off
legend('Original Channel 1','Reconstructed Channel 1')
plot(t,x(:,2)','LineWidth',1.5)
hold on
plot(ti,ix(:,2)','r--')

legend('Original Channel 2','Reconstructed Channel 2')

% Copyright 2019 The MathWorks, Inc.