Documentation

# modwtmra

Multiresolution analysis based on MODWT

## Syntax

``mra = modwtmra(w)``
``mra = modwtmra(w,wname) ``
``mra = modwtmra(w,Lo,Hi)``
``mra = modwtmra(___,'reflection')``

## Description

example

````mra = modwtmra(w)` returns the multiresolution analysis (MRA) of the maximal overlap discrete wavelet transform (MODWT) matrix, `w`. The MODWT matrix, `w`, is the output of the `modwt` function. ```

example

````mra = modwtmra(w,wname) ` constructs the MRA using the wavelet corresponding to `wname`. The `wname` wavelet must be the same wavelet used to obtain the MODWT. ```

example

````mra = modwtmra(w,Lo,Hi)` constructs the MRA using the scaling filter `Lo` and wavelet filter `Hi`. The `Lo` and `Hi` filters must be the same filters used to obtain the MODWT.```

example

````mra = modwtmra(___,'reflection')` uses the reflection boundary condition in the construction of the MRA using any of the arguments from previous syntaxes. If you specify `'reflection'`, `modwtmra` assumes that the length of the original signal is one half the number of columns in the input coefficient matrix. ```

## Examples

collapse all

Obtain the MODWTMRA of a simple time-series signal and demonstrate perfect reconstruction.

Create a time-series signal

```t = 1:10; x =sin(2*pi*200*t);```

Obtain the MODWT and the MODWTMRA and sum the MODWTMRA rows.

```m = modwt(x); mra = modwtmra(m); xrec = sum(mra);```

Use the maximum of the absolute values to show that the difference between the original signal and the reconstruction is extremely small. The largest absolute value is on the order of $1{0}^{-25}$, which demonstrates perfect reconstruction.

`max(abs(x-xrec))`
```ans = 5.5738e-25 ```

Construct an MRA of an ECG signal down to level four using the 'db2' wavelet.

```load wecg; lev = 4; wtecg = modwt(wecg,'db2',lev); mra = modwtmra(wtecg,'db2');```

Plot the ECG waveform and the MRA.

```subplot(6,1,1) plot(wecg) for kk = 2:lev+2 subplot(6,1,kk) plot(mra(kk-1,:)) end``` Construct a multiresolution analysis for the Southern Oscillation Index data. The sampling period is one day. Plot the level eight details corresponding to a scale of ${2}^{8}$ days. The details at this scale capture oscillations on a scale of approximately one year.

```load soi wtsoi = modwt(soi); mrasoi = modwtmra(wtsoi); plot(mrasoi(8,:)) title('Level 8 Details')``` Obtain the MRA for the Deutsch Mark - U.S. Dollar exchange rate data using the minimum bandwidth scaling and wavelet filters with four coefficients.

```load DM_USD; Lo = [0.4801755, 0.8372545, 0.2269312, -0.1301477]; Hi = qmf(Lo); wdm = modwt(DM_USD,Lo,Hi); mra = modwtmra(wdm,Lo,Hi);```

Obtain the MRA for an ECG signal using `'reflection'` boundary handling.

```load wecg; wtecg = modwt(wecg,'reflection'); mra = modwtmra(wtecg,'reflection');```

Show that the number of columns in the MRA is equal to the number of elements in the original signal.

`isequal(size(mra,2),numel(wecg))`
```ans = logical 1 ```

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.

```load mit200 wv = 'sym6'; plot(ecgsig) grid on title(['Signal Length = ',num2str(length(ecgsig))])``` Take the MODWT of the signal.

`wtecg = modwt(ecgsig,wv);`

The input data are samples of a function $f\left(x\right)$ evaluated at $N$-many time points. The function can be expressed as a linear combination of the scaling function $\varphi \left(x\right)$ and wavelet $\psi \left(x\right)$at varying scales and translations: $f\left(x\right)=\sum _{k=0}^{N-1}{c}_{k}\phantom{\rule{0.16666666666666666em}{0ex}}{2}^{-{J}_{0}/2}\varphi \left({2}^{-{J}_{0}}\phantom{\rule{0.16666666666666666em}{0ex}}x-k\right)+\sum _{j=1}^{{J}_{0}}{f}_{j}\left(x\right)$ where ${f}_{j}\left(x\right)=\sum _{k=0}^{N-1}{d}_{j,k}\phantom{\rule{0.16666666666666666em}{0ex}}{2}^{-j/2}\phantom{\rule{0.16666666666666666em}{0ex}}\psi \left({2}^{-j}x-k\right)$ 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}\left(x\right)$ are the details at successive scales. MODWT returns the $N$-many coefficients $\left\{{c}_{k}\right\}$and the $\left({J}_{0}×N\right)$-many detail coefficients $\left\{{d}_{j,k}\right\}$ 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}\left({\mathrm{log}}_{2}\left(N\right)\right)$-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}\left(\mathrm{log}2\left(10000\right)\right)=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: ${||X||}^{2}=\sum _{j=1}^{{J}_{0}}{||{W}_{j}||}^{2}+{||{V}_{{J}_{0}}||}^{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.

```energy_by_scales = sum(wtecg.^2,2); Levels = {'D1';'D2';'D3';'D4';'D5';'D6';'D7';'D8';'D9';'D10';'D11';'D12';'D13';'A13'}; energy_table = table(Levels,energy_by_scales); disp(energy_table)```
``` 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 = varfun(@sum,energy_table(:,2))`
```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.

```energy_ecg = sum(ecgsig.^2); max(abs(energy_total.sum_energy_by_scales-energy_ecg))```
```ans = 4.0875e-09 ```

Take the MODWTMRA of the signal.

`mraecg = modwtmra(wtecg,wv);`

MODWTMRA returns the projections of the function $f\left(x\right)$ 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 \left({2}^{-{J}_{0}}\phantom{\rule{0.16666666666666666em}{0ex}}x-k\right)$and the ${J}_{0}$-many $\left\{{f}_{j}\left(x\right)\right\}$evaluated at $N$-many time points. Each row in `mraecg` is a projection of $f\left(x\right)$ 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\left(x\right)$ evaluated at that time point and compare with the original signal.

```time_point = 1000; abs(sum(mraecg(:,time_point))-ecgsig(time_point))```
```ans = 3.0942e-13 ```

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

```energy_ecg = sum(ecgsig.^2); energy_mra_scales = sum(mraecg.^2,2); energy_mra = sum(energy_mra_scales); max(abs(energy_mra-energy_ecg))```
```ans = 534.7949 ```

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.

```figure plot(ecgsig) hold on plot(mraecg(4,:),'-') grid on xlim([4000 5000]) legend('Signal','Projection','Location','northwest')``` 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.

```figure plot(ecgsig) hold on plot(wtecg(4,:),'-') grid on xlim([4000 5000]) legend('Signal','Coefficients','Location','northwest')``` 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 .

## Input Arguments

collapse all

Maximal overlap discrete wavelet transform, specified as a matrix. `w` is the output of `modwt`.

The input `w` is an L+1-by-N matrix containing the MODWT of an N-point input signal down to level L. By default, `modwtmra` assumes that you obtained the MODWT using the symlet wavelet with four vanishing moments, `'sym4'`, and using periodic boundary handling.

Data Types: `double`

Synthesis wavelet, specified as a character vector or string scalar. The synthesis wavelet must be the same wavelet used to obtain the MODWT with the `modwt` function.

Scaling filter, specified as an even-length real-valued vector. You can specify `Lo` only if you do not specify `wname`. `Lo` must be the same scaling filter used to obtain the MODWT with the `modwt` function.

Wavelet filter, specified as an even-length real-valued vector. You can specify `Hi` only if you do not specify `wname`. `Hi` must be the same wavelet filter used to obtain the MODWT with the `modwt` function.

## Output Arguments

collapse all

Multiresolution analysis, returned as a matrix. By default, the `mra` is the same size as the input transform matrix `w`. If you specify reflection boundary handling, then `mra` has one half the number of columns as the input matrix `w`.

The output `mra` is an L+1-by-N matrix. The kth row of `mra` contains the details for the kth level. The (L+1)th row of `mra` contains the Lth level smooth.

 Percival, D. B., and Walden, A. T. Wavelet Methods for Time Series Analysis. Cambridge, U.K: Cambridge University Press, 2000.

 Whitcher, B., P. Guttorp, and D. B. Percival. "Wavelet analysis of covariance with application to atmospheric time series." Journal of Geophysical Research, Vol. 105, 2000, pp. 14941–14962.

##### Support Get trial now