% WV_1trans.m
%
% P. Flandrin

clf 

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

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

t = Ns/4:dt:3*Ns/4;
Lh = 255;
h = tftb_window(Lh,'Rect');
dh = (Lh-1)/2;

[wv,T,F] = tfrpwv(sig,t,Nbin,h);
wv(1,1) = max(max(abs(wv)));

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
		
P = 1/100 ;

for k = Ns/4:dt:Ns/2

    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(1:2*(k-1)+1) = sigrev(Ns-2*(k-1):Ns);
    plot(real(w))
    wh = zeros(Ns,1);
    wh(k-dh:k+dh) = h(1:Lh);
    plot(wh,'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(wv(:,1:1+(k-Ns/4)/dt)+abs(wv(:,1:1+(k-Ns/4)/dt))));
    colormap(jet)
    axis([1 max(size(t)) 1 Nbin])
    set(gca,'YTick',[]);set(gca,'XTick',[])
    title('Wigner-Ville')
        
    pause(P)

end

for k = Ns/2+1:dt:3*Ns/4+1

    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(2*(k-1)-Ns+1:Ns) = sigrev(1:2*Ns-2*(k-1));
    plot(real(w))
    wh = zeros(Ns,1);
    wh(k-dh:k+dh) = h(1:Lh);
    plot(wh,'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(wv(:,1:1+fix((k-Ns/4)/dt))+abs(wv(:,1:1+fix((k-Ns/4)/dt)))));
    colormap(jet)
    axis([1 max(size(t)) 1 Nbin])
    set(gca,'YTick',[]);set(gca,'XTick',[])
    title('pseudo-Wigner-Ville')
        
    pause(P)

end

