clear all;
[hh,gg,h,g] = wfilters('Db1');

C = [1 2 0 -1 1 2 0 -1]
D = zeros(1,length(C));
hlength = length(h);
glength = length(g);

CMatrix=0;
DMatrix=0;

iter = 0;
while (length(C) ~= 0)
iter = iter+1

Clength = length(C);
CMatrix(iter,1:Clength) = C(1,:);
DMatrix(iter,1:Clength) = D(1,:); 

M = zeros(Clength ,Clength);
for a=1:Clength/2
    for b=1:hlength
    M(a, mod(2*(a-1)+ b-1,Clength)+1) = M(a, mod(2*(a-1)+ b-1,Clength)+1) + h(b); 
    end;
    for b=1:glength
    M(a+Clength/2, mod(2*(a-1)+ b-1,Clength)+1) = M(a+Clength/2, mod(2*(a-1)+ b-1,Clength)+1) + g(b); 
    end;
end;

V = (M * C')'

%if length(V) == 4
%end

C = V(1:Clength/2);
D = V(Clength/2+1:Clength);

end



CC = CMatrix(size(CMatrix,1),1); 

for iter = size(DMatrix,1): -1 :2

CC = [CC DMatrix(iter,1:2^(size(DMatrix,1) - iter))];  
CClength = length(CC);

M = zeros(CClength ,CClength)
for a=1:CClength/2
    for b=1:hlength
    M(a, mod(2*(a-1)+ b-1,CClength)+1) = M(a, mod(2*(a-1)+ b-1,CClength)+1)+ h(b); 
    end;
    for b=1:glength
    M(a+CClength/2, mod(2*(a-1)+ b-1,CClength)+1) =  M(a+CClength/2, mod(2*(a-1)+ b-1,CClength)+1)+ g(b); 
    end;
end;

%if iter == size(DMatrix,1)-1   
%end

CC = (inv(M) * CC')';

end;
