Maximal overlap discrete wavelet packet transform
MODWPT Using Default Wavelet
Obtain the terminal nodes of the MODWPT of an electrocardiogram (ECG) signal by using
modwpt with default settings. The signal is sampled at 180 Hz. Because the signal has 2048 elements, by default, the terminal nodes are at level 4.
load wecg wpt = modwpt(wecg);
wpt is a 16-by-2048 matrix containing the sequency-ordered wavelet packet coefficients for the terminal nodes. Each node corresponds to an approximate passband filtering of , where n = 0,...,15, and is the sampling frequency. Plot the wavelet packet coefficients at node (4,2), which is level 4, node 2.
plot(wpt(3,:)) axis tight title("Node (4,2) Wavelet Packet Coefficients")
MODWPT Using Daubechies Extremal Phase Wavelet with Two Vanishing Moments
Obtain the MODWPT of Southern Oscillation Index data with the Daubechies extremal phase wavelet with two vanishing moments (
load soi wsoi = modwpt(soi,"db2");
Verify that the size of the resulting transform contains 16 nodes. Each node is in a separate row.
ans = 1×2 16 12998
MODWPT Full Packet Tree and Passband Center Frequencies
Obtain the MODWPT and full wavelet packet tree of an ECG waveform using the default length 18 Fejér-Korovkin (
'fk18') wavelet. Extract and plot the node coefficients at level 3, node 2.
load wecg [wpt,packetlevels,cfreq] = modwpt(wecg,FullTree=true); p3 = wpt(packetlevels==3,:); node=2; plot(p3(node+1,:)) axis tight title("Node (3,2) Wavelet Coefficients")
Display the center frequencies at level 3.
ans = 8×1 0.0312 0.0938 0.1562 0.2188 0.2812 0.3438 0.4062 0.4688
MODWPT Energy and Relative Energy
Obtain the MODWPT energy and relative energy of an ECG waveform.
load wecg [wpt,~,cfreq,energy,relenergy] = modwpt(wecg);
Show that the sum of the MODWPT energies is equal to the total energy in the original signal.
ans = 298.2759
ans = 298.2759
Plot the MODWPT energy by node.
bar(1:16,energy) xlabel("Node") ylabel("Energy") title("Energy by Node")
Plot the relative energy by node.
bar(1:16,relenergy*100) xlabel("Node") ylabel("Percent Energy") title("Energy Relative to Signal Energy by Node")
Create a signal consisting of two intermittent sine waves in noise. The sine wave frequencies are 150 Hz and 200 Hz. The data is sampled at 1000 Hz.
Fs = 1000; t = 0:1/Fs:1-1/Fs; x = cos(2*pi*150*t).*(t>=0.2 & t<0.4)+ ... sin(2*pi*200*t).*(t>0.6 & t<0.9); y = x+0.05*randn(size(t));
Obtain the default and time-aligned MODWPT of the signal.
[wptn,~,Fnon] = modwpt(y); [wpta,~,Falign] = modwpt(y,TimeAlign=true);
Plot the signal. Compare with the default and time-aligned time-frequency plots.
tiledlayout(3,1) nexttile plot(t,x) title("Signal") ylabel("Amplitude") nexttile contour(t,Fs*Fnon,abs(wptn).^2) grid on ylabel("Hz") title("Time-Frequency Plot") nexttile contour(t,Fs*Falign,abs(wpta).^2) grid on xlabel("Time (s)") ylabel("Hz") title("Time-Frequency Plot (Time-Aligned)")
x — Input signal
Input signal, specified as a row or column vector.
must have at least two elements.
Complex Number Support: Yes
wname — Analyzing wavelet
"fk18" (default) | character vector | string scalar
Analyzing wavelet, specified as a character vector or string scalar. The
wavelet must be orthogonal. Orthogonal wavelets are designated as type 1
wavelets in the wavelet manager,
Valid built-in orthogonal wavelet families are: Best-localized Daubechies
"bl"), Beylkin (
"coif"), Daubechies (
"fk"), Haar (
Han linear-phase moments (
"sym"), and Vaidyanathan
For a list of wavelets in each family, see
wfilters. You can also use
waveinfo with the
wavelet family short name. For example,
wname is orthogonal (returns 1). For
wavemngr("type","db6") returns 1.
lo,hi — Filters
even-length real-valued vectors
Filters, specified as a pair of even-length real-valued vectors.
lo is the scaling (lowpass) filter and
hi is the wavelet (highpass) filter. The filters must
satisfy the conditions for an orthogonal wavelet. For more information, see
isorthwfb. You cannot specify both
wname and a filter pair
By default, the
returns two pairs of filters associated with an orthogonal or
biorthogonal wavelet you specify. To agree with the usual convention
in the implementation of
MODWPT in numerical
packages, when you specify an orthogonal wavelet
function internally uses the second pair of filters returned by
is equivalent to
[~,~,lo,hi] = wfilters("db2"); wpt =
This convention is different from the one followed by most Wavelet Toolbox™ discrete wavelet transform functions when decomposing a signal. Most functions internally use the first pair of filters.
lev — Transform level
Transform level, specified as a positive integer less than or equal to
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
wpt = modwpt(x,FullTree=true) returns the full wavelet
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
wpt = modwpt(x,'FullTree',true) returns the full wavelet
FullTree — Full packet tree
Option to return the full wavelet packet tree, specified as a numeric or logical
false). If you specify
only the terminal (final-level) wavelet packet nodes. If you specify
the full wavelet packet tree down to the specified level.
FullTree=true specifies to return the full wavelet packets
TimeAlign — Signal time alignment
0 (default) |
Option to time align wavelet packet coefficients with signal features, specified as a numeric
true) to time align
false) to not align.
The scaling and wavelet filters have a time delay. Circularly
shifting the wavelet packet coefficients in all nodes aligns the signal
and wavelet coefficients in time. If you want to reconstruct the signal,
such as by using
do not shift the coefficients because time alignment is done during
the inversion process.
TimeAlign=true specifies to time-align the wavelet packet
coefficients with the signal.
wpt — Wavelet packet transform
Wavelet packet tree, returned as a matrix with each row containing
the sequency-ordered wavelet packet coefficients. By default,
only the terminal level for the MODWPT. The default terminal level
is either level 4 or
is smaller. At level 4,
wpt is a 16-by-
matrix. For the full tree, at level j,
matrix, with each row containing the packet coefficients by level
and index. The approximate passband for the nth
wpt at level j is cycles/sample,
where n = 1,2,...2j.
packetlevs — Transform levels
Transform levels, returned as a vector. The levels correspond to the rows of
wptcontains only the terminal level coefficients,
packetlevsis a vector of constants equal to the terminal level.
wptcontains the full wavelet packet table,
packetlevsis a vector with 2j elements for each level, j. To select all the wavelet packet nodes at a particular level, use
packetlevswith logical indexing.
cfreq — Center frequencies of passbands
Center frequencies of the approximate passbands in the
returned as a vector. The center frequencies are in cycles/sample.
To convert the units to cycles/unit time, multiply
the sampling frequency.
energy — Energy of the wavelet packet coefficients
Energy of the wavelet packet coefficients for the
returned as a vector. The sum of the energies (squared L2 norms) for
the wavelet packets at each level equals the energy in the signal.
relenergy — Relative energy
Relative energy for each level, returned as a vector. The relative energy is the proportion of energy in each wavelet packet by level, relative to the total energy of that level. The sum of relative energies in all packets at each level equals 1.
MODWPT and MODWPT Details
The output of the MODWPT (
modwpt) is time-delayed compared to
the input signal. Most filters used to obtain the MODWPT have a nonlinear phase
response, which makes compensating for the time delay difficult. This is true for
all orthogonal scaling and wavelet filters, except the Haar wavelet. It is possible
to time-align the coefficients with the signal features, but the result is an
approximation, not an exact alignment with the original signal. The MODWPT
partitions the energy among the wavelet packets at each level. The sum of the energy
over all the packets equals the total energy of the input signal. The output of
MODWPT is useful for applications where you want to analyze the energy levels in
The MODWPT details (
modwptdetails) are the result of
zero-phase filtering of the signal. The features in the MODWPT details align exactly
with features in the input signal. For a given level, summing the details for each
sample returns the exact original signal. The output of the MODWPT details is useful
for applications that require time-alignment, such as nonparametric regression
Sequency-ordered Wavelet Packet Tree
modwpt function performs a discrete wavelet packet
transform and produces a sequency-ordered wavelet packet tree. Compare the
sequency-ordered and normal (Paley)-ordered trees. is the scaling (lowpass) analysis filter, and represents the wavelet (highpass) analysis filter. The labels at
the bottom show the partition of the frequency axis [0,1/2] into subbands.
 Percival, Donald B., and Andrew T. Walden. Wavelet Methods for Time Series Analysis. Cambridge Series in Statistical and Probabilistic Mathematics. Cambridge ; New York: Cambridge University Press, 2000.
 Walden, A. T., and A. Contreras Cristan. “The Phase–Corrected Undecimated Discrete Wavelet Packet Transform and Its Application to Interpreting the Timing of Events.” Proceedings of the Royal Society of London. Series A: Mathematical, Physical and Engineering Sciences 454, no. 1976 (August 8, 1998): 2243–66. https://doi.org/10.1098/rspa.1998.0257.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
wnamemust be constant.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version HistoryIntroduced in R2016a
R2023b: Supports complex-valued signals
modwpt function supports complex-valued signals.
R2023a: Supports single-precision data and GPU acceleration
Supports single-precision data.
You must have Parallel Computing Toolbox™ to use