www.gusucode.com > wavelet 源码程序 matlab案例代码 > wavelet/BuildWaveletPacketTreeExample.m

    %% Build Wavelet Packet Tree
% This example shows how to build a wavelet packet tree in two ways: 1.) By
% filling the wavelet packet tree with coefficients, and 2.) By creating
% the wavelet packet tree and using |write|
%%
% Load an image and obtain the wavelet packet decomposition down to level
% 2 with the |'sym4'| wavelet.

% Copyright 2015 The MathWorks, Inc.

load detail;
imagesc(X); colormap gray; title('Original Image');
Tr = wpdec2(X,2,'sym4');
%%
% Read the coefficients from the wavelet packet tree. Add $N(0,40^2)$
% noise to the coefficients and plot the new wavelet packet tree.

cfs = read(Tr,'allcfs');
noisyCfs = cfs + 40*rand(size(cfs));
noisyT = cfs2wpt('sym4',size(X),tnodes(Tr),4,noisyCfs);
plot(noisyT)
%%
% To illustrate building a wavelet packet tree using |write|, construct
% an admissible binary wavelet packet tree with terminal nodes |[2 3 9
% 10]|. The analyzing wavelet is |'sym4'| and the signal length is 1024.

tr = cfs2wpt('sym4',[1 1024],[2 3 9 10]',2);
%%
% Fill terminal nodes |[3 9]| with $N(0,1)$ coefficients.
sN = read(tr,'sizes',[3,9]);
sN3 = sN(1,:); sN9 = sN(2,:);
cfsN3 = randn(sN3);
cfsN9 = randn(sN9);
tr = write(tr,'cfs',3,cfsN3,'cfs',9,cfsN9);
%%
% Plot the resulting wavelet packet tree and synthesized signal.

plot(tr)