% realloc_principe.m
%
% P. Flandrin

clf 

load batrich.mat
sig = [zeros(1,56) x' zeros(1,56)]';
sig = hilbert(sig-mean(sig));
sig = sig/max(abs(sig));

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

td = 56;
tf = 512-td;
t = td:dt:tf;

w = tfrwv(sig,t,Nbin,1);

Lh = 95;%15;%35; % largeur de la fenêtre à court-terme
h = window(Lh,'Kaiser');
dh = (Lh-1)/2;
[s,rs] = tfrrsp(sig,t,2*Nbin,h,1);
rs(1,1) = max(max(rs));

subplot(121)
imagesc(flipud(w+abs(w)))
set(gca,'YTick',[]);set(gca,'XTick',[])
axis('square')
title('Wigner-Ville')
xlabel('time')
ylabel('frequency')

pause

subplot(122)
imagesc(flipud(s(1:Nbin,:)))
set(gca,'YTick',[]);set(gca,'XTick',[])
axis('square')
title('spectrogram')
xlabel('time')
ylabel('frequency')


tt = (0:101)*2*pi/102;
r = (Lh-1)/10;

cx = 25;
cy = 225;

subplot(122)
hold on
plot(cx,cy,'+y')
plot(cx+r*cos(tt),cy+r*sin(tt),'y')
hold off
subplot(122)
hold on
plot(cx,cy,'+y')
plot(cx+r*cos(tt),cy+r*sin(tt),'y')
hold off

pause

cx = 50;
cy = 168;

subplot(121)
hold on
plot(cx,cy,'+y')
plot(cx+r*cos(tt),cy+r*sin(tt),'y')
hold off
subplot(122)
hold on
plot(cx,cy,'+y')
plot(cx+r*cos(tt),cy+r*sin(tt),'y')
hold off

pause

cx = 75;
cy = 135;

subplot(121)
hold on
plot(cx,cy,'+y')
plot(cx+r*cos(tt),cy+r*sin(tt),'y')
hold off
subplot(122)
hold on
plot(cx,cy,'+y')
plot(cx+r*cos(tt),cy+r*sin(tt),'y')
hold off

pause

subplot(121)
imagesc(flipud(w+abs(w)))
set(gca,'YTick',[]);set(gca,'XTick',[])
axis('square')
title('Wigner-Ville')
xlabel('time')
ylabel('frequency')

subplot(122)
imagesc(flipud(rs(1:Nbin,:)))
set(gca,'YTick',[]);set(gca,'XTick',[])
axis('square')
title('reassigned spectrogram')
xlabel('time')
ylabel('frequency')
