function [out, tau2] = NonIDwt( x, index, wave, level )
%
% [out, tau2] = NonIDwt( x, index, wave, level );
%
% Funkce provede zpetnou vlnkovou transformaci bez decimace.
%
% VSTUP: x - vektor koeficientu ziskany z funkce NonDWT;
%        index - vektor indexu  -------- || ----------
%        wave, level - pouzite vlnky a pocet urovni rozkladu
% VYSTUP: out -  rekonstruovany signal
%         tau2 - zpozdeni rekonstrukcni casti
%
% SPUSTENI:  [out, tau2] = NonIDwt( x, index, 'db5', 5 );
%
% SEE: NonDWT,CancelDelay
%
x = x(:)';

[ LoD, HiD, LoR, HiR ] = wfilters( wave );

%LoD=LoD/sqrt(2);%pridal
%HiD=HiD/sqrt(2);%pridal
%LoR=LoR/sqrt(2);%pridal
%HiR=HiR/sqrt(2);%pridal

NLo = length( LoR );
NHi = length( HiR );

GH = HiR;
H = 1;
lenH = NLo;
lenG = 2*NHi-1;

% Zpocitani vysledne delky signalu a zpozdeni
i=0:(level-1);
CelkoveZpozdeni = round (( sum( NLo + (NLo-1)*(2.^i-1) )-(level-1) -1 )/2 );
VyslednaDelka = index(1) + ( sum( NLo + (NLo-1)*(2.^i-1) )-(level-1) -1 ) + 1;
i=0;

% uprava indexu, aby se to lepe pocitalo
index2 = sum(index) - cumsum( fliplr(index) );
ind1 = index2(1);
ind2 = length(x);

out = zeros( 1, VyslednaDelka );

for i = 1:level,
   
    GH = GH/(sqrt(2)); %vynechal

% Extrakce jedne urovne
   stage = x( ind1:ind2 );
   ind2 = ind1-1;
   ind1 = index2(i+1);
   
   % Filtrace
   pom = conv( GH, stage );
   
   pom = [zeros(1,CelkoveZpozdeni-round((length(GH)-1)/2) ) pom]/(2^(i-1));   % zpozdeni
   out = out + [pom zeros(1,VyslednaDelka-length(pom))];
  
 %  figure(2);	subplot(level+1,1,i);	stem( pom );

   if i==level, break, end,
   
   Hpom = zeros( 1, lenH );
   Hpom(1:(2^(i-1)):end) = LoR;
   H = conv( H, Hpom );            % dolni propust
   
   G = zeros( 1, lenG );
   G(1:(2^i):end) = HiR;			% horni propust
   
   GH = conv( G, H );
   
   lenH = (2^(i)-1)*(NLo-1) + NLo;
   lenG = (2^(i+1)-1)*(NHi-1) +  NHi;
end,

Hpom = zeros( 1, (2^(i-1)-1)*(NLo-1) + NLo );
Hpom(1:(2^(i-1)):end) = LoR;
GH = conv( H, Hpom );            % dolni propust
GH = GH/(sqrt(2)); %vynechal

stage = x(1:index(1));
pom = conv( GH, stage );
pom = [zeros(1,CelkoveZpozdeni-round((length(GH)-1)/2) ) 0 pom]/(2^(level-1));   % zpozdeni

out = out + pom;

if nargout==2,
   tau2 = CelkoveZpozdeni;
end

%figure(2);
%subplot(level+1,1,i+1);
%stem( pom);
