Wavelab/wtransdemo.m

From CCM
Jump to: navigation, search
function wtransdemo

% create a test signal - uncomment what you like
n=64;
% x=abs([1:n]-(n+1)*2/3);
% x=1:n
x =double([1:n]<n/3).*[1:n]

% call the demo function
WT_PO_demo(x,2,'Coiflet',2)
% WT_PO_demo(x,1,'Coiflet',2)
% WT_PO_demo(x,2,'Daubechies',4)
% WT_PO_demo(x,2,'Daubechies',6)

end

function WT_PO_demo(x,L,Type,Par)
%  x - signal vector
%  L - see help FWT_PO
%  Type, Par - see help MakeONFilter

form='orthogonal, periodicized';
n=length(x);
qmf = MakeONFilter(Type,Par); % the filter vector
wc = FWT_PO(x,L,qmf);   % the wavelet transform of x
xc = IWT_PO(wc,L,qmf);  % the inverse transform
xe=xc-x;                % error vector
err=norm(xc-x)/norm(x)  % error norm - should be numerically zero
ix=1:length(x); % index vector for plots
figure(1)
plot(ix,x,ix,wc,ix,xc,ix,xe) 
title(sprintf('%s %i coarse %i (%s)',Type,Par,L,form))
legend('signal','wavelet transform','recovered','error')

% start the summation to xs
xs=zeros(1,n);
e=[];  % see the input command below
for i=1:n,
    % compute the contribution of wavelet i
    wi=zeros(1,n);
    wi(i)=wc(i);
    xi = IWT_PO(wi,L,qmf);
    xs = xs + xi;
    xe=xs-x;
    figure(2)
    plot(ix,x,ix,xs,ix,xi,ix,xe)
    title(sprintf('%s %i coarse %i  (%s)',Type,Par,L,form))
    legend('signal','sum',sprintf('increment %i',i),'error')
    drawnow
    if isempty(e),
       e=input('press enter to continue display, or anything to skip to the end >> ');
    end
end
err=norm(xs-x)/norm(x)  % error norm
end
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox