% test funkce pilot.m

load s38_v3
x=xIDWT;
brum = 100*cos(2*pi*50/500*linspace(0,length(x)-1,length(x))); % pro pokus o filtraci brumu
x=x+brum;                                                     

figure(1)
plot(x)

% zadani vstupnich hodnot: *********************************
[xx,yy] = ginput(2);
oddo = round(xx);
%od=xx(1); do=xx(2);

PocetUrovni = 4;
filtry = 'db5';

Ksigma = 2;
prahovani = 2; % 1=tvrde, 2=mekke, 3=garrote

% potrebujeme zpozdit meze intervalu pro odhad urovne sumu,
% protoze jsou stanoveny pro vstupni signal
[xDWT,index,tau1] = NonDwt(x,filtry,PocetUrovni,1);
oddo = oddo + 2*tau1;

% *********************************************************

[xp,xDWTprah] = pilot(x,oddo,filtry,PocetUrovni,Ksigma,prahovani);

% *********************************************************

figure(2) % kresby pasem po DTWD --------------------------------------------
pasem = PocetUrovni+1;
pasmo = pasem;
z = 1;

for k = 1:pasem
    subplot(pasem,1,pasmo), plot(xDWT(z:z+index(k)-1),'red'); hold on
    subplot(pasem,1,pasmo), plot(xDWTprah(z:z+index(k)-1),'black'); hold off
    origmax=1.1*max(xDWT(z:z+index(k)-1));
    origmin=1.1*min(xDWT(z:z+index(k)-1));
    axis([1 length(xDWT(z:z+index(k)-1)) origmin origmax]);
    line([od od],[origmin origmax])
    line([do do],[origmin origmax])
    z = z+index(k);
    zac(k) = z;
    pasmo = pasmo-1;
end
tit=['DTWT vstupu (cervene) a po prahovani (cerne)'];
tit=[tit ', filtry: ' filtry ];
title(tit);

figure(3) % kresba vstupu, vystupu a jejich rozdilu ------------------------
subplot(2,1,1), plot(x,'red'), hold on, grid on,
subplot(2,1,1), plot(xp,'black'), hold off
tit=['vstup x(n) (cervene), vystup y(n) (cerne)'];
tit=[tit ', filtry: ' filtry ];
title(tit);
ylabel('x(n), y(n) [\muV]')

chyba=[]; 
chyba=x-xp;
subplot(2,1,2), plot(chyba,'black'), grid on
ylabel('e(n)=x(n)-y(n) [uV]'),
