%
% PWV_realtime_2trans.m
%
% (c) P. Flandrin, 11 mai 1999 - 20 novembre 2000
%
% calcule et trace le calcul en ligne d'un pseudo-WV
%

%clear

clf 

Ns = 1024;
f0 = .15;
tone = fmconst(Ns,f0).*amexpo1s(Ns,Ns/4+Ns/8+Ns/16,Ns/64)+fmconst(Ns,f0).*amexpo1s(Ns,Ns/2+Ns/16,Ns/64);
sig = zeros(Ns,1);
sig(Ns/4+Ns/8:Ns/2+Ns/8) = tone(Ns/4+Ns/8:Ns/2+Ns/8);
sigrev = flipud(sig);

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

t = Ns/4+Ns/8:dt:Ns/2+Ns/8;
Lh = 511;
h = tftb_window(Lh,'Rect');
dh = (Lh-1)/2;
P = 1/100 ;

[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+Ns/8 Ns/2+Ns/8 -amp amp])
        set(gca,'YTick',[]);set(gca,'XTick',[])
        hold on
		plot([Ns/4+Ns/8 Ns/2+Ns/8],[0 0],'r')
        title('signal')
        hold off
		pause


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

        subplot(2,1,1)
        plot(real(sig))
        amp = 1.2*max(max(real(sig)),abs(min(real(sig))));
        axis([Ns/4+Ns/8 Ns/2+Ns/8 -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+Ns/8 Ns/2+Ns/8],[0 0],'r')
        title('signal')
        hold off

        subplot(2,1,2)
        imagesc(flipud(wv(:,1:1+(k-Ns/4-Ns/8)/dt)+abs(wv(:,1:1+(k-Ns/4-Ns/8)/dt))));
        colormap(jet)
        axis([1 max(size(t)) 1 Nbin])
        set(gca,'YTick',[]);set(gca,'XTick',[])
        title('pseudo-Wigner-Ville')
        
        pause(P)

end

for k = Ns/2+1:dt:Ns/2+Ns/8+1

        subplot(2,1,1)
        plot(real(sig))
        amp = 1.2*max(max(real(sig)),abs(min(real(sig))));
        axis([Ns/4+Ns/8 Ns/2+Ns/8 -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+Ns/8 Ns/2+Ns/8],[0 0],'r')
        title('signal')
        hold off

        subplot(2,1,2)
        imagesc(flipud(wv(:,1:1+fix((k-Ns/4-Ns/8)/dt))+abs(wv(:,1:1+fix((k-Ns/4-Ns/8)/dt)))));
        colormap(jet)
        axis([1 max(size(t)) 1 Nbin])
        set(gca,'YTick',[]);set(gca,'XTick',[])
        title('pseudo-Wigner-Ville')
        
        pause(P)

end

