%
%  evaluate a fitted wavenet at given points
%
%   [ y ] = wavenet( x, cc, w, l )
%
%  y     = fitted data (size(x) points)
%  x     = original data (2^l+1 points)
%  cc    = wavenet coefficients (2^l+1, l+2)
%  w     = wavelet type (see function wavefunc)
%  l     = resolution
%
function y = wavenet( x, cc, w, l )
%
x = x(:);
%
% calculate scaling function nodes
c = cc(1:2,1);
%
% generate regression matrix
a = [];
for k = 0:2^l:2^l,
  a = [ a wavefunc( x, w, l, l, k ) ];
end;
%
% calculate function
y = a * c;
%
% now calculate wavelet nodes
for m = l:-1:0,
  c = cc(1:2^(l-m)+1,l-m+2);
%
% generate regression matrix
  a = [];
  for k = 0:2^m:2^l,
    a = [ a wavefunc( x, w, l, m, k ) ];
  end;
%
% calculate function
  y = y + a * c;
%
end;
%