%% ISTFT of Real Signal Using COLA Compliant Window and Overlap
% Generate a sinusoid sampled at 2 kHz for 1 second.

fs = 2e3;
t = 0:1/fs:1-1/fs;
x = 5*sin(2*pi*10*t);

%
% Design a periodic Hamming window of length 120. Check the COLA constraint for the window with an overlap of 80 samples. The window-overlap combination is COLA compliant.

win = hamming(120,'periodic');
noverlap = 80;
tf = iscola(win,noverlap)

%
% Set the FFT length to 512. Compute the short-time Fourier transform.

fftlen = 512;
s = stft(x,fs,'Window',win,'OverlapLength',noverlap,'FFTLength',fftlen);

%
% Calculate the inverse short-time Fourier transform.

[X,T] = istft(s,fs,'Window',win,'OverlapLength',noverlap,'FFTLength',fftlen,'Method','ola','ConjugateSymmetric',true);

%
% Plot the original and reconstructed signals.

plot(t,x,'b')
hold on
plot(T,X,'-.r')
xlabel('Time (s)')
ylabel('Amplitude (V)')
title('Original and Reconstructed Signal')
legend('Original Signal','Reconstructed Signal')
hold off

%
% Copyright 2018 The MathWorks, Inc.