Fs = 1000;
T0 = 10;
F1 = 500;
t = [0:1/Fs:T0];
x = exp(1j*pi*(F1/T0)*t.^2);

L = 64; % Window size
N = 1024; % FFT size
S = 32; % Step size
w = rectwin(64).';
num = floor((length(x)-S)/(L-S));
X = ones(num,N);
freq = [0:N-1]/N;
time = [1:num];

figure(1); clf;
subplot(211);
han = imagesc(freq,time,20*log10(X),[-50 50]);
colorbar;
subplot(212);
h2 = plot(real(x)); hold on;
h3 = plot(w,'r'); hold off;

n = 0;
for i=1:num
  ind = n+[1:L];
  n = n + S;
  y = x(ind).*w; % Apply window
  Y = abs(fft(y,N)); % Zero padded FFT
  X(i,:) = 20*log10(Y);
  set(han,'CData',X);
  set(h3,'XData',ind);
  xlim([ind(1) ind(end)]);
  drawnow;
end
