({{, (RefLink[DiscreteWaveletPacketTransform, paclet:ref/DiscreteWaveletPacketTransform])[data] 
gives the discrete wavelet packet transform (DWPT) of an array of data.}, {, (RefLink[DiscreteWaveletPacketTransform, paclet:ref/DiscreteWaveletPacketTransform])[data,wave]
gives the discrete wavelet packet transform using the wavelet wave.}, {, (RefLink[DiscreteWaveletPacketTransform, paclet:ref/DiscreteWaveletPacketTransform])[data,wave,r]
gives the discrete wavelet packet transform using r levels of refinement.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[DiscreteWaveletPacketTransform, paclet:ref/DiscreteWaveletPacketTransform]) gives a (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData]) object.

Properties of the (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData]) dwd can be found using dwd["prop"], and a list of available properties can be found using dwd["Properties"].

(RefLink[DiscreteWaveletPacketTransform, paclet:ref/DiscreteWaveletPacketTransform]) is a generalization of (RefLink[DiscreteWaveletTransform, paclet:ref/DiscreteWaveletTransform]) where the full tree of wavelet coefficients is computed.

The data can be any of the following:

The resulting wavelet coefficients are arrays of the same depth as the input data.

The possible wavelet wave include:

The default wave is (RefLink[HaarWavelet, paclet:ref/HaarWavelet])[].

With higher settings for the refinement level r, larger-scale features are resolved.

The default refinement level r is given by min((Floor[(Subscript[log, 2])(n)+1/2]),4), where n is the minimum dimension of data.

With refinement level (RefLink[Full, paclet:ref/Full]), r is given by (Floor[(Subscript[log, 2])(n)+1/2]).

The tree of wavelet coefficients at level j consists of coarse coefficients (Subscript[c, j,n]) and detail coefficients (Subscript[d, j,n]) with (Subscript[c, 0,n])=(Subscript[x, n]) representing the input data.

The forward transform is given by (Subscript[c, j+1,n]^0)=(Sqrt[2])(∑_m)(Subscript[a, m-2n+2]) (Subscript[c, j,m]^0), (Subscript[d, j+1,n]^0)=(Sqrt[2])(∑_m)(Subscript[b, m-2n+2]) (Subscript[c, j,m]^0), (Subscript[c, j+1,n]^1)=(Sqrt[2])(∑_m)(Subscript[a, m-2n+2]) (Subscript[d, j,m]^1), and (Subscript[d, j+1,n]^1)=(Sqrt[2])(∑_m)(Subscript[b, m-2n+2]) (Subscript[d, j,m]^1).

The inverse transform is given by (Subscript[c, j,n]^i)=(Sqrt[2]) ((∑_m)(Subscript[a, n-2 m+2]) (Subscript[c, j+1,n]^i)+ (∑_m)(Subscript[b, n-2 m+2]) (Subscript[d, j+1,m]^i)).

The (Subscript[a, i]) are lowpass filter coefficients and (Subscript[b, i]) are highpass filter coefficients that are defined for each wavelet family.

The dimensions of (Subscript[c, j]^i) and (Subscript[d, j]^i) are given by (Subscript[wd, j+1])=(Ceiling[(1/2) ((Subscript[wd, j])+fl-2)]) where (Subscript[wd, 0]) is the input data dimension and fl is the filter length for the corresponding wspec.

The following options can be given:

The settings for (RefLink[Padding, paclet:ref/Padding]) are the same as available in (RefLink[ArrayPad, paclet:ref/ArrayPad]).

(RefLink[InverseWaveletTransform, paclet:ref/InverseWaveletTransform]) gives the inverse transform.

By default, (RefLink[InverseWaveletTransform, paclet:ref/InverseWaveletTransform]) uses coefficients represented by dwd["BasisIndex"] for reconstruction. Use (RefLink[WaveletBestBasis, paclet:ref/WaveletBestBasis]) to compute and set an optimal basis.

OpenersPrimaryExamplesSection(Spacer1)Examples  (60)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Compute a wavelet packet transform:

dwd=DiscreteWaveletPacketTransform[{0,0,1,0,0}]

The resulting (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData]) represents a full tree of wavelet coefficients:

dwd["TreeView"]

The inverse transform reconstructs the input:

InverseWaveletTransform[dwd]

Transform an audio signal:

a=Audio["ExampleData/rule30.wav"]

dwd=DiscreteWaveletPacketTransform[a,Automatic,2]

Use dwd[…,"Audio"] to extract coefficient signals:

dwd[All,"Audio"]

Compute the inverse transform:

InverseWaveletTransform[dwd]

Transform an (RefLink[Image, paclet:ref/Image]) object:

dwd=DiscreteWaveletPacketTransform[,Automatic,2]

Use dwd[…,"Image"] to extract coefficient images:

dwd[All,"Image"]

Compute the inverse transform:

InverseWaveletTransform[dwd]

OpenersExampleSection1(Spacer1)Scope  (34)

OpenersExampleSubsection0(Spacer1)Basic Uses  (5)

Useful properties can be extracted from the (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData]) object:

dwd = DiscreteWaveletPacketTransform[RandomReal[1,{16}],DaubechiesWavelet[4],2]

Get a full list of properties:

dwd["Properties"]

Get data and coefficient dimensions:

dwd["DataDimensions"]

dwd["Dimensions"]

Use (RefLink[Normal, paclet:ref/Normal]) to get all wavelet coefficients explicitly:

dwd=DiscreteWaveletPacketTransform[Range[5]];

Normal[dwd]

Also use (RefLink[All, paclet:ref/All]) as an argument to get all coefficients:

dwd[All]

Use (RefLink[Automatic, paclet:ref/Automatic]) to get only the coefficients used in the inverse transform:

dwd[Automatic]

Use the "TreeView" or "IndexMap" to find out what wavelet coefficients are available:

dwd=DiscreteWaveletPacketTransform[Range[5]];

dwd["TreeView"]

dwd["IndexMap"]

Extract specific coefficient arrays:

dwd[{0}]

dwd[{0,0}]

Extract several wavelet coefficients corresponding to a list of wavelet index specifications:

dwd[{{0},{0,1}}]

Extract all coefficients whose wavelet indexes match a pattern:

dwd[{_}]

dwd[{{_,0},{_,1}}]

Use (RefLink[WaveletBestBasis, paclet:ref/WaveletBestBasis]) to compute an optimal basis of wavelet packet coefficients:

dwd=DiscreteWaveletPacketTransform[Table[Sin[x^2],{x,0,10,0.2}]];

dwd=WaveletBestBasis[dwd]

Highlight the best basis in a block grid of all coefficients:

dwd["BestBasisBlockView"]

Extract the best basis using "BasisIndex":

dwd["BasisIndex"]

The computed best basis is used by default in functions like (RefLink[WaveletListPlot, paclet:ref/WaveletListPlot]):

WaveletListPlot[dwd]

Use a higher refinement level to increase the frequency resolution:

data=Table[Sin[x^2]+RandomReal[{-0.2,0.2}],{x,0,10,0.02}];

ListLinePlot[data]

With a smaller refinement level, more of the signal energy is left in {0,0}:

dwd1=DiscreteWaveletPacketTransform[data,DaubechiesWavelet[4],2];

WaveletListPlot[dwd1,PlotLayout->"CommonYAxis"]

With further refinement, {0,0} is resolved into further components:

dwd2=DiscreteWaveletPacketTransform[data,DaubechiesWavelet[4],3];

WaveletListPlot[dwd2,PlotLayout->"CommonYAxis"]

OpenersExampleSubsection1(Spacer1)Wavelet Families  (10)

Compute the wavelet packet transform using different wavelet families:

data=Table[Sin[x^2],{x,0,10,0.02}];

dwd1=DiscreteWaveletPacketTransform[data,DaubechiesWavelet[4],3];
dwd2=DiscreteWaveletPacketTransform[data,SymletWavelet[4],3];

Compare the coefficients:

{WaveletListPlot[dwd1],WaveletListPlot[dwd2]}

Use different families of wavelets to capture different features:

data=Table[4 Exp[-100 (t-0.5)^2] +Sin[5Pi t],{t,0,1,0.01}];

ListLinePlot[data]

(RefLink[HaarWavelet, paclet:ref/HaarWavelet]) (default):

dwd=DiscreteWaveletPacketTransform[data,HaarWavelet[],3];

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis",Filling->Axis]

(RefLink[DaubechiesWavelet, paclet:ref/DaubechiesWavelet]):

data=Table[4 Exp[-100 (t-0.5)^2] +Sin[5Pi t],{t,0,1,0.01}];

dwd=DiscreteWaveletPacketTransform[data,DaubechiesWavelet[2],3];

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis",Filling->Axis]

(RefLink[BattleLemarieWavelet, paclet:ref/BattleLemarieWavelet]):

data=Table[4 Exp[-100 (t-0.5)^2] +Sin[5Pi t],{t,0,1,0.01}];

dwd=DiscreteWaveletPacketTransform[data,BattleLemarieWavelet[3],3];

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis",Filling->Axis]

(RefLink[BiorthogonalSplineWavelet, paclet:ref/BiorthogonalSplineWavelet]):

data=Table[4 Exp[-100 (t-0.5)^2] +Sin[5Pi t],{t,0,1,0.01}];

dwd=DiscreteWaveletPacketTransform[data,BiorthogonalSplineWavelet[4,2],3];

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis",Filling->Axis]

(RefLink[CoifletWavelet, paclet:ref/CoifletWavelet]):

data=Table[4 Exp[-100 (t-0.5)^2] +Sin[5Pi t],{t,0,1,0.01}];

dwd=DiscreteWaveletPacketTransform[data,CoifletWavelet[2],3];

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis",Filling->Axis]

(RefLink[MeyerWavelet, paclet:ref/MeyerWavelet]):

data=Table[4 Exp[-100 (t-0.5)^2] +Sin[5Pi t],{t,0,1,0.01}];

dwd=DiscreteWaveletPacketTransform[data,MeyerWavelet[3],3];

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis",Filling->Axis]

(RefLink[ReverseBiorthogonalSplineWavelet, paclet:ref/ReverseBiorthogonalSplineWavelet]):

data=Table[4 Exp[-100 (t-0.5)^2] +Sin[5Pi t],{t,0,1,0.01}];

dwd=DiscreteWaveletPacketTransform[data,ReverseBiorthogonalSplineWavelet[4,2],3];

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis",Filling->Axis]

(RefLink[ShannonWavelet, paclet:ref/ShannonWavelet]):

data=Table[4 Exp[-100 (t-0.5)^2] +Sin[5Pi t],{t,0,1,0.01}];

dwd=DiscreteWaveletPacketTransform[data,ShannonWavelet[8],3];

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis",Filling->Axis]

(RefLink[SymletWavelet, paclet:ref/SymletWavelet]):

data=Table[4 Exp[-100 (t-0.5)^2] +Sin[5Pi t],{t,0,1,0.01}];

dwd=DiscreteWaveletPacketTransform[data,SymletWavelet[3],3];

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis",Filling->Axis]

OpenersExampleSubsection2(Spacer1)Vector Data  (6)

Plot the coefficients over a common horizontal axis using (RefLink[WaveletListPlot, paclet:ref/WaveletListPlot]):

dwd=DiscreteWaveletPacketTransform[Table[Sin[x^2],{x,0,10,0.02}],Automatic,3];

WaveletListPlot[dwd,FrameTicks->Full]

Plot against a common vertical axis:

WaveletListPlot[dwd,PlotLayout->"CommonYAxis"]

Visualize coefficients as a function of time and refinement level using (RefLink[WaveletScalogram, paclet:ref/WaveletScalogram]):

dwd=DiscreteWaveletPacketTransform[Table[Sin[20x]+Sin[10x],{x,1,10,0.01}]];

The coefficient indexes appear as tooltips when the mouse pointer is moved over a coefficient:

WaveletScalogram[dwd,All]

(RefLink[WaveletScalogram, paclet:ref/WaveletScalogram]) of the best tree representation of the data:

WaveletScalogram[WaveletBestBasis[dwd]]

Constant data:

data=Table[1,{x,0,10,0.02}];

ListLinePlot[data]

All coefficients are small except coarse coefficients {0,0,…}:

dwd=DiscreteWaveletPacketTransform[data,DaubechiesWavelet[4],3];

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis"]

Data oscillating at the highest resolvable frequency (Nyquist frequency):

data=Table[(((-1))^n),{n,80}];

ListLinePlot[data]

Only the first detail coefficient {1} and its coarse child coefficients {1,0,0,…} are not small:

dwd=DiscreteWaveletPacketTransform[data,Automatic,3];

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis"]

Data with large discontinuities:

data=Table[({{\[Piecewise], ({{1, 1<x<3.1}, {0, True}})}}),{x,0,4,0.02}];

ListLinePlot[data]

Coarse coefficients {0,…} have the same large-scale structure as the data:

dwd=DiscreteWaveletPacketTransform[data,Automatic,3];

WaveletListPlot[dwd,{0..},FrameTicks->Full]

Detail coefficients are sensitive to discontinuities:

WaveletListPlot[dwd,Except[{0..}]]

Data with both spatial and frequency structure:

data=Table[({{\[Piecewise], ({{5, n≤30}, {2+(((-1))^n), 30<n≤60}, {5, 60<n}})}}),{n,90}];

ListLinePlot[data,PlotRange->{0,5}]

Coarse coefficients {0,…} track the local mean of the data:

dwd=DiscreteWaveletPacketTransform[data,Automatic,3];

WaveletListPlot[dwd,{0..},FrameTicks->Full]

First detail coefficient {1} and its coarse child coefficients {1,0,…} represent the oscillations:

WaveletListPlot[dwd,{1,0...},FrameTicks->Full]

All coefficients on a common vertical axis:

WaveletListPlot[dwd,All,PlotLayout->"CommonYAxis"]

OpenersExampleSubsection3(Spacer1)Matrix Data  (5)

Compute a two-dimensional wavelet packet transform:

dwd=DiscreteWaveletPacketTransform[(({{0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}, {1, 1, 1, 1, 1}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}}))]

View the tree of wavelet coefficients:

dwd[{"TreeView",Center}]

Inverse transform to get back the original signal:

InverseWaveletTransform[dwd]//Chop//MatrixForm

Use (RefLink[WaveletMatrixPlot, paclet:ref/WaveletMatrixPlot]) to visualize the different wavelet coefficients:

dwd=DiscreteWaveletPacketTransform[DiamondMatrix[32],Automatic,2]

WaveletMatrixPlot[dwd,ImageSize->Small]

(RefLink[WaveletMatrixPlot, paclet:ref/WaveletMatrixPlot]) of best tree representation:

WaveletMatrixPlot[WaveletBestBasis[dwd],ImageSize->Small]

In two dimensions, the vector of filtering operations in each direction can be computed:

Tuples[{0,1},2]/.{0->"lowpass",1->"highpass"}

Interpreting these vectors as binary digit expansions results in wavelet index numbers:

FromDigits[#,2]&/@Tuples[{0,1},2]

Get the lowpass and highpass filters for a Haar wavelet:

{lp,hp}=Map[Last,WaveletFilterCoefficients[HaarWavelet[],{"PrimalLowpass","PrimalHighpass"}],{2}]

The resulting 2D filters are outer products of filters in the two directions:

Apply[KroneckerProduct,Tuples[{lp,hp},2],{1}]

Map[MatrixPlot,%]

Wavelet transform of step data:

step[{a_,b_,c_,d_}]:=
ArrayFlatten[{{ConstantArray[a,{3,3}],ConstantArray[b,{3,5}]},{ConstantArray[c,{5,3}],ConstantArray[d,{5,5}]}}];

Data with a vertical discontinuity:

MatrixPlot[step[{0,1,0,1}],FrameTicks->False]

All horizontal and diagonal detail coefficients, wavelet index {___,2|3,___}, are zero:

WaveletMatrixPlot[DiscreteWaveletPacketTransform[step[{0,1,0,1}]],ImageSize->Small]

Data with horizontal discontinuity:

MatrixPlot[step[{0,0,1,1}],FrameTicks->False]

All vertical and diagonal detail coefficients, wavelet index {___,1|3,___}, are zero:

WaveletMatrixPlot[DiscreteWaveletPacketTransform[step[{0,0,1,1}]],ImageSize->Small]

Data with diagonal discontinuity:

MatrixPlot[Reverse@IdentityMatrix[8],FrameTicks->False]

All horizontal and vertical detail coefficients, wavelet index {___,1|2,___}, are zero:

WaveletMatrixPlot[DiscreteWaveletPacketTransform[Reverse@IdentityMatrix[8]],ImageSize->Small]

OpenersExampleSubsection4(Spacer1)Array Data  (2)

Compute a three-dimensional wavelet packet transform:

data = RandomReal[1,{16,16,16}];

dwd=DiscreteWaveletPacketTransform[data,Automatic,2]

Block grid view of all coefficients:

dwd["BestBasisBlockView"]

Wavelet transform of a three-dimensional cross array:

data = CrossMatrix[All,{8,8,8}];

Graphics3D[{Red,Cuboid/@Position[data,1]}]

dwd=DiscreteWaveletPacketTransform[data,Automatic,2]

Visualize lowpass wavelet coefficients {___,0}:

Table[i->Graphics3D[{If[Positive[Extract[dwd[i][[1,2]],#]],Red, Green],Cuboid[#]}&/@Position[dwd[i][[1,2]],u_/;Abs[u]>0],PlotRange->Automatic],{i,Cases[dwd["IndexMap"],{___,0}]}]

Energy of the original data is conserved within the transformed coefficients:

Total[((Flatten[data])^2)]== Total[((Flatten[dwd[Automatic][[All,2]]])^2)]

OpenersExampleSubsection5(Spacer1)Image Data  (3)

Transform an (RefLink[Image, paclet:ref/Image]) object:

img = Image[DiamondMatrix[All,{64,64}]]

dwd=DiscreteWaveletPacketTransform[img,HaarWavelet[],3]

The inverse transform yields a reconstructed (RefLink[Image, paclet:ref/Image]) object:

InverseWaveletTransform[dwd]

Wavelet coefficients are normally given as lists of data for each image channel:

dwd=DiscreteWaveletPacketTransform[,HaarWavelet[],2];

Dimensions[{1,1}/.dwd[{1,1}]]

Get all coefficients as (RefLink[Image, paclet:ref/Image]) objects instead:

dwd[All,{"Image",ImageSize->80}]

Get raw (RefLink[Image, paclet:ref/Image]) objects with no rescaling of color levels:

dwd[All,{"Image","ImageFunction"->Identity,ImageSize->80}]

Get the inverse transform of the {0,1} coefficient as an (RefLink[Image, paclet:ref/Image]) object:

dwd[{0,1},{"Image","Inverse"}]

Compute a best tree of coefficients from a packet transform of image data:

dwd=DiscreteWaveletPacketTransform[,HaarWavelet[],4];

best=WaveletBestBasis[dwd]

Plot the best tree in a hierarchical grid using (RefLink[WaveletImagePlot, paclet:ref/WaveletImagePlot]):

WaveletImagePlot[best,ImageSize->Medium]

OpenersExampleSubsection6(Spacer1)Sound Data  (3)

Transform a (RefLink[Sound, paclet:ref/Sound]) object:

snd=ExampleData[{"Sound","Apollo11ReturnSafely"}]

dwd=DiscreteWaveletPacketTransform[snd]

The inverse transform yields a reconstructed (RefLink[Sound, paclet:ref/Sound]) object:

InverseWaveletTransform[dwd]

By default, coefficients are given as lists of data for each sound channel:

dwd=DiscreteWaveletPacketTransform[ExampleData[{"Sound","PianoScale"}]];

Dimensions[{1,1}/.dwd[{1,1}]]

Get the {1,1} coefficient as a (RefLink[Sound, paclet:ref/Sound]) object:

dwd[{1,1},"Sound"]

Inverse transform of {1,1} coefficient as a (RefLink[Sound, paclet:ref/Sound]) object:

dwd[{1,1},{"Sound","Inverse"}]

Compute a best tree of coefficients from a packet transform of sound data:

dwd=DiscreteWaveletPacketTransform[ExampleData[{"Sound","Clarinet"}]];

best=WaveletBestBasis[dwd]

Browse the best tree coefficients using a (RefLink[MenuView, paclet:ref/MenuView]):

MenuView[best[Automatic,"Sound"]]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (3)

(RefLink[DiscreteWaveletPacketTransform, paclet:ref/DiscreteWaveletPacketTransform]) works on arrays of symbolic quantities:

dwd=DiscreteWaveletPacketTransform[{a,b,c,d},WorkingPrecision->∞];

Normal[dwd]//Simplify

Inverse transform recovers the input exactly:

InverseWaveletTransform[dwd]//Simplify

Specify any internal working precision:

dwd=DiscreteWaveletPacketTransform[{1,2,5,2},WorkingPrecision->20];

Normal[dwd]

Use complex-valued data:

data=Exp[I RandomReal[1,4]];

dwd=DiscreteWaveletPacketTransform[data]

The wavelets coefficients are complex:

dwd[Automatic]

OpenersExampleSection3(Spacer1)Options  (5)

OpenersExampleSubsection7(Spacer1)Padding  (2)

The settings for (RefLink[Padding, paclet:ref/Padding]) are the same as the methods for (RefLink[ArrayPad, paclet:ref/ArrayPad]), including "Periodic":

ArrayPad[{a,b,c},4, "Periodic"]

"Reversed":

ArrayPad[{a,b,c},4,"Reversed"]

"ReversedNegation":

ArrayPad[{a,b,c},4,"ReversedNegation"]

"Reflected":

ArrayPad[{a,b,c},4,"Reflected"]

"ReflectedDifferences":

ArrayPad[{a,b,c},3,"ReflectedDifferences"]

"ReversedDifferences":

ArrayPad[{a,b,c},4,"ReversedDifferences"]

"Extrapolated":

ArrayPad[{a,b,c},3,"Extrapolated"]

Padding can remove boundary effects:

data = Table[UnitStep[x],{x,-2,2,4/255}];

ListLinePlot[data]

Use the default "Periodic" padding:

dwt1 =DiscreteWaveletPacketTransform[data,DaubechiesWavelet[2],3];

WaveletListPlot[dwt1]

"Extrapolated" padding lessens boundary effects for nonperiodic data:

dwt2 =DiscreteWaveletPacketTransform[data,DaubechiesWavelet[2],3,Padding->"Extrapolated"];

WaveletListPlot[dwt2]

OpenersExampleSubsection8(Spacer1)WorkingPrecision  (3)

By default, (RefLink[WorkingPrecision, paclet:ref/WorkingPrecision])->(RefLink[MachinePrecision, paclet:ref/MachinePrecision]) is used:

data=RandomInteger[1,{10}];

dwd1=DiscreteWaveletPacketTransform[data]

dwd2=DiscreteWaveletPacketTransform[data,WorkingPrecision->MachinePrecision]

dwd1==dwd2

Use higher-precision computation:

data={0,0,1,1};

dwd=Normal@DiscreteWaveletPacketTransform[data,Automatic,2,WorkingPrecision->25]

With numbers close to zero, accuracy is the better indicator of the number of correct digits:

{Precision[dwd],Accuracy[dwd]}

Use (RefLink[WorkingPrecision, paclet:ref/WorkingPrecision])->∞ for exact computation:

data=RandomInteger[10,{4}];

Normal@DiscreteWaveletPacketTransform[data,WorkingPrecision->∞]//Simplify

OpenersExampleSection4(Spacer1)Applications  (3)

OpenersExampleSubsection9(Spacer1)Best Tree Analysis  (2)

The default reconstruction tree contains the coefficients at the maximum refinement level:

dwd=DiscreteWaveletPacketTransform[Table[({{\[Piecewise], ({{5, n≤30}, {2+(((-1))^n), 30<n≤60}, {5, 60<n}})}}),{n,90}]];

dwd["BestBasisBlockView"]

Choose a reconstruction tree with energy concentrated in a small number of coefficients:

best=WaveletBestBasis[dwd]

best["BestBasisBlockView"]

Plot the best tree coefficients against a common vertical axis:

WaveletListPlot[best,PlotLayout->"CommonYAxis"]

Visualize default reconstruction tree coefficients for image data:

dwd=DiscreteWaveletPacketTransform[,Automatic];

WaveletImagePlot[dwd,ImageSize->Small]

Compute the reconstruction tree whose coefficients have the smallest total log energy:

best=WaveletBestBasis[dwd,"ShannonEntropy"]

WaveletImagePlot[best,ImageSize->Small]

OpenersExampleSubsection10(Spacer1)Compression  (1)

Lossless compression of matrix data:

data = DiskMatrix[All,{12,12}];

MatrixPlot[data,FrameTicks->None]

In the best tree wavelet packet representation many coefficients are zero:

dwd =WaveletBestBasis[DiscreteWaveletPacketTransform[data]];

WaveletMatrixPlot[dwd,ImageSize->Small]

Count nonzero coefficients as a measure of compressed size:

Count[Last/@dwd[Automatic],Except[0.],{3}]

Nonzero values in original data:

Count[data,Except[0],{2}]

Length of data:

Times@@Dimensions[data]

OpenersExampleSection5(Spacer1)Properties & Relations  (11)

(RefLink[DiscreteWaveletPacketTransform, paclet:ref/DiscreteWaveletPacketTransform]) computes the full tree of wavelet coefficients:

dwpt=DiscreteWaveletPacketTransform[{1,1,3,1,1}];

dwpt[{"TreeView",Left}]

(RefLink[DiscreteWaveletTransform, paclet:ref/DiscreteWaveletTransform]) computes a subset of the full tree of coefficients:

dwt=DiscreteWaveletTransform[{1,1,3,1,1}];

dwt[{"TreeView",Left}]

(RefLink[DiscreteWaveletPacketTransform, paclet:ref/DiscreteWaveletPacketTransform]) coefficients halve in length with each level of refinement:

Normal[DiscreteWaveletPacketTransform[{1,2,3,4}]]

Rotated data gives different coefficients:

Normal[DiscreteWaveletPacketTransform[{2,3,4,1}]]

(RefLink[StationaryWaveletPacketTransform, paclet:ref/StationaryWaveletPacketTransform]) coefficients have the same length as the original data:

Normal[StationaryWaveletPacketTransform[{1,2,3,4}]]

Rotated data gives rotated coefficients:

Normal[StationaryWaveletPacketTransform[{2,3,4,1}]]

Multidimensional discrete wavelet transform is related to one-dimensional packet transform:

dwt=DiscreteWaveletTransform[(({{a, b}, {c, d}})),WorkingPrecision->∞];

Simplify[dwt[Automatic]]

dwpt=DiscreteWaveletPacketTransform[{a,b,c,d},WorkingPrecision->∞];

Simplify[dwpt[Automatic]]

For Haar wavelet (default) and data length (2^n), the computed coefficients are identical:

Flatten[Sort[Last/@dwt[Automatic]]]==Flatten[Sort[Last/@dwpt[Automatic]]]

The default refinement is given by (RefLink[Min, paclet:ref/Min])[(RefLink[Round, paclet:ref/Round])[(RefLink[Log2, paclet:ref/Log2])[(RefLink[Min, paclet:ref/Min])[(RefLink[Dimensions, paclet:ref/Dimensions])[data]]]],4]:

data=RandomReal[1,{100}];

r=Min[Round[Log2[Min[Dimensions[data]]]],4]

DiscreteWaveletPacketTransform[data]==DiscreteWaveletPacketTransform[data,Automatic,r]

In higher dimensions:

data = RandomReal[1,{100,10,10}];

r=Min[Round[Log2[Min[Dimensions[data]]]],4]

DiscreteWaveletPacketTransform[data]==DiscreteWaveletPacketTransform[data,Automatic,r]

The energy norm is conserved for orthogonal wavelet families:

data=RandomReal[1,{100}];

dwt=DiscreteWaveletPacketTransform[data,Padding->0.];

Norm[data]==Norm[Flatten[Last/@dwt[Automatic]]]

The energy norm is approximately conserved for biorthogonal wavelet families:

data=RandomReal[1,{100}];

dwt=DiscreteWaveletPacketTransform[data,BiorthogonalSplineWavelet[2,4],Padding->0.];

Norm[data]

Norm[Flatten[Last/@dwt[Automatic]]]

The mean of the data is captured at the maximum refinement level of the transform:

data=RandomReal[1,{64}];

dwt=DiscreteWaveletPacketTransform[data,HaarWavelet[],Full];

Extract the coefficient for the maximum refinement level:

r=dwt["Refinement"]

dwt[ConstantArray[0,{r}]]

Compensate for the (Sqrt[2]) normalization at each refinement level:

%[[1,2,1]]/((((Sqrt[2])))^r)

Mean[data]

The sum of inverse transforms from individual coefficient arrays gives the original data:

data=Table[DiscreteDelta[n],{n,-2,2}]

dwd=DiscreteWaveletPacketTransform[data];

dwd["TreeView"]

Individually inverse transform each wavelet coefficient array:

data1=InverseWaveletTransform[dwd,Automatic,{0,0}]

data2=InverseWaveletTransform[dwd,Automatic,{0,1}]

data3=InverseWaveletTransform[dwd,Automatic,{1,0}]

data4=InverseWaveletTransform[dwd,Automatic,{1,1}]

The sum gives the original data:

data1+data2+data3+data4

(RefLink[HaarWavelet, paclet:ref/HaarWavelet]) corresponds to averaging (lowpass filter) and differencing (highpass filter):

low[v_]:=Partition[v,2].{(1/(Sqrt[2])),(1/(Sqrt[2]))}
high[v_]:=Partition[v,2].{(1/(Sqrt[2])),-(1/(Sqrt[2]))}

HaarWaveletTransform[v_]:={{0}->low[v],{1}->high[v]};

Compute {0} and {1} wavelet coefficients:

HaarWaveletTransform[{a,b,c,d}]

Compare with (RefLink[DiscreteWaveletPacketTransform, paclet:ref/DiscreteWaveletPacketTransform]):

DiscreteWaveletPacketTransform[{a,b,c,d},HaarWavelet[],1,WorkingPrecision->∞][All]

In two dimensions a separate filter is applied in each dimension:

f2d[fx_,fy_]:=Composition[Map[fy,#\[Transpose]]&,Map[fx,#\[Transpose]]&]

Lowpass and highpass filters for Haar wavelet:

low[v_]:=Partition[v,2].{(1/(Sqrt[2])),(1/(Sqrt[2]))}
high[v_]:=Partition[v,2].{(1/(Sqrt[2])),-(1/(Sqrt[2]))}

Haar wavelet transform of matrix data:

data = Table[Sin[x y],{x,-2,2,4/63},{y,-2,2,4/63}];

Table[MatrixPlot[f2d[fx,fy][data],PlotLabel->{fx,fy},FrameTicks->None],{fx,{low,high}},{fy,{low,high}}]//Flatten

Compare with (RefLink[DiscreteWaveletPacketTransform, paclet:ref/DiscreteWaveletPacketTransform]) using (RefLink[HaarWavelet, paclet:ref/HaarWavelet]):

dwd=DiscreteWaveletPacketTransform[data,HaarWavelet[],1];

Table[MatrixPlot[Last[p],PlotLabel->First[p],FrameTicks->None],{p,Normal[dwd]}]

Image channels are transformed individually:

dwds=Map[DiscreteWaveletPacketTransform,ColorSeparate[]]

Combine {0} coefficients of separately transformed image channels:

w=Image[Table[First[{0}/.Normal[t]],{t,dwds}],Interleaving->False]

Compare with {0} coefficient of (RefLink[DiscreteWaveletPacketTransform, paclet:ref/DiscreteWaveletPacketTransform]) of original image:

dwd=DiscreteWaveletPacketTransform[];

{0}/.dwd[All,{"Image","ImageFunction"->Identity}]

The images are identical:

ImageSubtract[w,%]

OpenersExampleSection6(Spacer1)Possible Issues  (1)

Padding can affect the total energy of wavelet coefficients:

data=RandomReal[1,{10}];

dwd1=DiscreteWaveletPacketTransform[data,DaubechiesWavelet[4], Padding->"Fixed"];

Energy is not conserved:

{((Norm[data])^2),((Norm[Flatten[Last/@dwd1[Automatic]]])^2)}

Pad with 0s to ensure energy conservation in the coefficients:

dwd2=DiscreteWaveletPacketTransform[data,DaubechiesWavelet[4],Padding->0];

{((Norm[data])^2),((Norm[Flatten[Last/@dwd2[Automatic]]])^2)}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[WaveletBestBasis, paclet:ref/WaveletBestBasis])  ▪  (RefLink[InverseWaveletTransform, paclet:ref/InverseWaveletTransform])  ▪  (RefLink[DiscreteWaveletData, paclet:ref/DiscreteWaveletData])  ▪  (RefLink[WaveletMapIndexed, paclet:ref/WaveletMapIndexed])  ▪  (RefLink[WaveletThreshold, paclet:ref/WaveletThreshold])  ▪  (RefLink[DiscreteWaveletTransform, paclet:ref/DiscreteWaveletTransform])  ▪  (RefLink[StationaryWaveletTransform, paclet:ref/StationaryWaveletTransform])  ▪  (RefLink[StationaryWaveletPacketTransform, paclet:ref/StationaryWaveletPacketTransform])  ▪  (RefLink[ArrayPad, paclet:ref/ArrayPad])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Wavelet Analysis, paclet:guide/Wavelets])}, {▪(RefLinkPlain[Summation Transforms, paclet:guide/SummationTransforms])}})}})