% S_1trans_L.m
%
% P. Flandrin

clf 

Ns = 512;
f0 = .15;
tone = fmlin(Ns,.5,-.15).*amexpo1s(Ns,3*Ns/8,Ns/3);sig = zeros(Ns,1);
sig(3*Ns/8:5*Ns/8) = tone(3*Ns/8:5*Ns/8);

Nbin = 128; % nombre de bins fréquentiels
dt = 2; % écart (en échantillons) entre dates de calcul

t = Ns/4:dt:3*Ns/4;

Lh = 195; % 15 95 
h = window(Lh,'Kaiser');
dh = (Lh-1)/2;
[s,T,F] = tfrsp(sig,t,2*Nbin,h);
s(1,1) = max(max(s));

subplot(2,1,1)
plot(real(sig))
amp = 1.2*max(max(real(sig)),abs(min(real(sig))));
axis([Ns/4 3*Ns/4 -amp amp])
set(gca,'YTick',[]);set(gca,'XTick',[])
hold on
plot([Ns/4 3*Ns/4],[0 0],'r')
title('signal')
hold off
pause

for k = Ns/4:dt:3*Ns/4

	subplot(2,1,1)
	plot(real(sig))
	amp = 1.2*max(max(real(sig)),abs(min(real(sig))));
	axis([Ns/4 3*Ns/4 -amp amp])
	set(gca,'YTick',[]);set(gca,'XTick',[])
	hold on
	w = zeros(Ns,1);
	w(k-dh:k+dh) = h(1:Lh);
	plot(w,'r')
	plot([k k],[-amp amp],'r')
	plot([Ns/4 3*Ns/4],[0 0],'r')
	title('signal')
	hold off

	subplot(2,1,2)
	imagesc(flipud(s(1:128,1:1+(k-Ns/4)/dt)));
	colormap(jet)
	axis([1 max(size(t)) 1 Nbin])
	set(gca,'YTick',[]);set(gca,'XTick',[])
	title('spectrogramme')
	
	pause(.3)

end
