function out=filtIF(in,thcel,fs,wavtype,L)

%tvrdé prahovani wavelet banka, vyp z celkoveho prahu



Nnulzac=0;
Kt=1;
Kth=1;
diftype=[0.5 -0.5]*fs/pi;
[cf,f]=freqz(diftype,1,1024);


%-----------vypocet mod derivacniho filtru---------------

Nc=length(cf);
for k=1:L
   prdif(k)=sum(abs(cf(Nc/2^k:Nc/2^(k-1))))/(Nc/2^k); 
   xx(k)=Nc/2^(k-1);
   maxpr(k)=abs(cf(Nc/2^(k-1)));
   minpr(k)=abs(cf(Nc/2^k));
end
prdif(k+1)=sum(abs(cf(1:Nc/2^k)))/(Nc/2^k); 
xx(k+1)=Nc/2^k;
maxpr(k+1)=abs(cf(Nc/2^k));
minpr(k+1)=0.1;


c=in;
c=[zeros(1,Nnulzac) c];

%-----------uprava delky---------------

if log2(length(c))-fix(log2(length(c)))~=0;
    c=[c zeros(1,2^(fix(log2(length(c)))+1)-length(c))];
end
%-----------zjisteni smer. odchylky u FID---------------


%-----------vypocet IF a obalky FID a jeji filtrace---------------

uhel=unwrap(angle(c));
frekv=filter(diftype,1,uhel);

%a=obalka(real(c));
a=abs(c);

dkoa=swt(a,L,'db1');
for lev=1:L %neprahuju posledi tj nejspodnejsi pasmo jinak L2+1

for k=1:length(dkoa(lev,:))
   if abs(dkoa(lev,k))<thcel*20
      dkoa(lev,k)=0;
  end
end

end

a=iswt(dkoa,'db1');


%-----------vypocet prahu IF---------------


%-----------vypočet z celkového prahu-----------------------

for k=1:length(c)
    df(k)=2*abs(abs(atan2(a(k)/(2^(0.5))+thcel,a(k)/(2^(0.5))-thcel))-abs(atan2(a(k)/(2^(0.5))-thcel,a(k)/(2^(0.5))+thcel)));
end

% for k=1:L
% thif(k,:)=df*fs/2/pi*Kth;
% end

for k=1:L
thif(k,:)=df*minpr(k);
end

for k=1:L
thif(k,:)=thif(k,:)*2^(0.5*k);
end

%-----------posun prahu-----------------------
pom=[zeros(1,1000) 1 zeros(1,1047)];

dkopom=swt(pom,L,wavtype);

for k = 1:L,
    [asdfa,dtsub(k)]=max(dkopom(k,:));
end;

a=iswt(dkopom,wavtype);

dtsub=abs(dtsub-1000)+1;
for k=1:L
thif(k,:)=[thif(k,dtsub(k):end) thif(k,end)*ones(1,dtsub(k)-1)];
end


%-----------prahovani IF---------------
dko2=swt(frekv,L,wavtype);


%-----------prahovani tvrde---------------
for lev=1:L %neprahuju posledi tj nejspodnejsi pasmo jinak L2+1

for k=1:length(dko2(lev,:))
   if abs(dko2(lev,k))<thif(lev,k)
      dko2(lev,k)=0;
  end
end

end

frekv2=iswt(dko2,wavtype);

out=frekv2;
