% This routine illustrates the effect of a local change
% in the time and the wavelet domain for the FFT and the DWT
% 
% first the FWT

% generate a signal

 N = 128; sN = sqrt(1/N); x(1:N) = (1:N)*2*pi/N;
 a = [1 3 2 5]; b = [6 8 4 2];
 e1 = a*cos(b'*x);

% plot signal and its fft

 v = [1 128 -10 20]; u = [1 64 0 30];
 figure(1),clf,subplot(321),plot(e1);title('signal'),axis(v);
 ffte1 = sN*abs(myFFT(e1,N));
 figure(1),subplot(322),plot(ffte1(1:N/2));title('fft'), axis(u)

% change fft, inverse FFT and plot

 ffte1(1:16);
 ffte2 = ffte1; nc = 40; ffte2(nc) = 20; ffte2(N+1-nc) = 20;
 figure(1), subplot(324), plot(ffte2(1:N/2));
 title('local fft change'),axis(u)
 e2 = sN*real(myFFT(ffte2,N));
 figure(1), subplot(323), plot(e2);
 title('effect local fft change'),axis(v);

% change signal, fft and plot

 e3 = e1; e3(N/2:N/2+1) = 20;ffte3 = sN*abs(myFFT(e3,N));
 figure(1), subplot(325), plot(e3);
 title('local signal change'),axis(v)
 figure(1), subplot(326), plot(ffte3(1:N/2));
 title('effect local signal change'),axis(u)

% now the wavelet transform

% construct wavelet

 L = 2;
 % [qmf,dqmf] = MakeBSFilter('CDF',[2 2]); % WaveLab function
 qmf = ortfilt('Daubechies',3); % PiefLab function
 [h, g, ht, gt, sh, sg, sht, sgt] = qmf2hgs(qmf);

% plot signal and FWT

 figure(2),clf,subplot(321),plot(e1);
 title('signal'), axis(v);
 % w = FWT_PB(e1,L,qmf,dqmf); % WaveLab function
 w = FWT_BIO(e1,L,ht,gt,sht,sgt); % PiefLab function
 figure(2), subplot(322),plotscales(w,L),title('WT')

% change FWT, inverse FWT and plot

 w(1:5);
 w2 = w; w2(50) = 20;
 figure(2), subplot(324),plotscales(w2,L);
 title('local WT change')
 % e2 = IWT_PB(w2,L,qmf,dqmf); % WaveLab function
 e2 = IWT_BIO(w2,L,h,g,sh,sg); % PiefLab function
 figure(2), subplot(323),plot(e2);
 title('effect local WT change'),axis(v)

% change signal, FWT and plot

 figure(2), subplot(325),plot(e3);
 title('local signal change'),axis(v)
 % w3 = FWT_PB(e3,L,qmf,dqmf); % WaveLab function
 w3 = FWT_BIO(e3,L,ht,gt,sht,sgt); % PiefLab function
 figure(2), subplot(326),plotscales(w3,L),
 title('effect local signal change')
 

