This example demonstrates the differences between the functions MODWT and MODWTMRA. The MODWT partitions a signal's energy across detail coefficients and scaling coefficients. The MODWTMRA projects a signal onto wavelet subspaces and a scaling subspace.

Choose the 'sym6' wavelet. Load and plot an ECG waveform. The ECG data is taken from the MIT-BIH Arrhythmia Database.

Take the MODWT of the signal.

The input data are samples of a function $$f(x)$$ evaluated at $$N$$-many time points. The function can be expressed as a linear combination of the scaling function $$\varphi (x)$$ and wavelet $$\psi (x)$$at varying scales and translations: $$f(x)=\sum _{k=0}^{N-1}{c}_{k}\phantom{\rule{0.16666666666666666em}{0ex}}{2}^{-{J}_{0}/2}\varphi ({2}^{-{J}_{0}}\phantom{\rule{0.16666666666666666em}{0ex}}x-k)+\sum _{j=1}^{{J}_{0}}{f}_{j}(x)$$ where $${f}_{j}(x)=\sum _{k=0}^{N-1}{d}_{j,k}\phantom{\rule{0.16666666666666666em}{0ex}}{2}^{-j/2}\phantom{\rule{0.16666666666666666em}{0ex}}\psi ({2}^{-j}x-k)$$ and $${J}_{0}$$ is the number of levels of wavelet decomposition. The first sum is the coarse scale approximation of the signal, and the $${f}_{j}(x)$$ are the details at successive scales. MODWT returns the $$N$$-many coefficients $$\{{c}_{k}\}$$and the $$({J}_{0}\times N)$$-many detail coefficients $$\{{d}_{j,k}\}$$ of the expansion. Each row in `wtecg`

contains the coefficients at a different scale.

When taking the MODWT of a signal of length $$N$$, there are $$\text{floor}({\mathrm{log}}_{2}(N))$$-many levels of decomposition (by default). Detail coefficients are produced at each level. Scaling coefficients are returned only for the final level. In this example, since $$N=10000$$, $${J}_{0}=\text{floor}(\mathrm{log}2(10000))=13$$ and the number of rows in `wtecg`

is $${J}_{0}+1=13+1=14$$.

The MODWT partitions the energy across the various scales and scaling coefficients: $${\left|\right|X\left|\right|}^{2}=\sum _{j=1}^{{J}_{0}}{\left|\right|{W}_{j}\left|\right|}^{2}+{\left|\right|{V}_{{J}_{0}}\left|\right|}^{2}$$ where $$X$$ is the input data, $${W}_{j}$$ are the detail coefficients at scale $$j$$, and $${V}_{{J}_{0}}$$ are the final-level scaling coefficients.

Compute the energy at each scale, and evaluate their sum.

Levels energy_by_scales
_______ ________________
{'D1' } 0.31592
{'D2' } 2.6504
{'D3' } 28.802
{'D4' } 159.37
{'D5' } 300.5
{'D6' } 431.33
{'D7' } 444.93
{'D8' } 182.37
{'D9' } 45.381
{'D10'} 11.578
{'D11'} 19.809
{'D12'} 4.5406
{'D13'} 3.308
{'A13'} 192.46

energy_total=*1×1 table*
sum_energy_by_scales
____________________
1827.3

Confirm the MODWT is energy-preserving by computing the energy of the signal and comparing it with the sum of the energies over all scales.

Take the MODWTMRA of the signal.

MODWTMRA returns the projections of the function $$f(x)$$ onto the various wavelet subspaces and final scaling space. That is, MODWTMRA returns $$\sum _{k=0}^{N-1}{c}_{k}\phantom{\rule{0.16666666666666666em}{0ex}}{2}^{-{J}_{0}/2}\varphi ({2}^{-{J}_{0}}\phantom{\rule{0.16666666666666666em}{0ex}}x-k)$$and the $${J}_{0}$$-many $$\{{f}_{j}(x)\}$$evaluated at $$N$$-many time points. Each row in `mraecg`

is a projection of $$f(x)$$ onto a different subspace. This means the original signal can be recovered by adding all the projections. This is *not* true in the case of the MODWT. Adding the coefficients in `wtecg`

will *not* recover the original signal.

Choose a time point, add the projections of $$f(x)$$ evaluated at that time point and compare with the original signal.

Confirm that, unlike MODWT, MODWTMRA is not an energy-preserving transform.

The MODWTMRA is a zero-phase filtering of the signal. Features will be time-aligned. Demonstrate this by plotting the original signal and one of its projections. To better illustrate the alignment, zoom in.

Make a similar plot using the MODWT coefficients at the same scale. Note that features will not be time-aligned. The MODWT is *not* a zero-phase filtering of the input.

References

Goldberger A. L., L. A. N. Amaral, L. Glass, J. M. Hausdorff, P. Ch. Ivanov, R. G. Mark, J. E. Mietus, G. B. Moody, C-K Peng, H. E. Stanley. "PhysioBank, PhysioToolkit, and PhysioNet: Components of a New Research Resource for Complex Physiologic Signals." Circulation 101. Vol.23, e215-e220, 2000. `http://circ.ahajournals.org/cgi/content/full/101/23/e215`

Moody, G. B. "Evaluating ECG Analyzers". `http://www.physionet.org/physiotools/wfdb/doc/wag-src/eval0.tex`

Moody G. B., R. G. Mark. "The impact of the MIT-BIH Arrhythmia Database." IEEE Eng in Med and Biol. Vol. 20, Number 3, 2001), pp. 45-50 .