# dlmodwt

Deep learning maximal overlap discrete wavelet transform and multiresolution analysis

## Syntax

## Description

returns
the maximal overlap discrete wavelet transform (MODWT) of `w`

= dlmodwt(`x`

)`x`

using the
lowpass (scaling) and highpass (wavelet) filters associated with the Daubechies
least-asymmetric wavelet with four vanishing moments (`"sym4"`

) . By
default, `dlmodwt`

uses periodic boundary extension and computes the
MODWT to the maximum level. `dlmodwt`

requires Deep Learning Toolbox™.

`[___] = dlmodwt(___,`

specifies options using one or more name-value arguments in addition to the input arguments
in previous syntaxes. For example, `Name=Value`

)`BOUNDARY="periodic"`

specifies periodic
extension at the boundary.

## Examples

### Deep Learning Maximal Overlap Discrete Wavelet Transform

Load the 23 channel Espiga3 EEG data set. The data is sampled at 200 Hz. There are 995 samples in each channel. The data set is arranged as a 995-by-23(-by-1) array.

`load Espiga3`

Store the signal in an unformatted deep learning array.

x = dlarray(Espiga3);

Obtain the MODWT and MRA of the data. Specify the data format as `'TCB'`

.

`[wt,mra] = dlmodwt(x,DataFormat='TCB');`

Confirm that both `wt`

and `mra`

are unformatted `dlarray`

objects.

whos wt mra

Name Size Bytes Class Attributes mra 10x23x1x995 1830800 dlarray wt 10x23x1x995 1830800 dlarray

dims(wt)

ans = 0x0 empty char array

dims(mra)

ans = 0x0 empty char array

Plot the reconstruction based on the MRA. Compare with the original data set.

xrec = sum(mra); subplot(2,1,1) plot(Espiga3) title("Original EEG Dataset") subplot(2,1,2) plot(extractdata(squeeze(xrec))') title("MODWT MRA Reconstruction")

## Input Arguments

`x`

— Input array

`dlarray`

object | numeric array

Input array, specified as an unformatted `dlarray`

(Deep Learning Toolbox), a
formatted `dlarray`

in `'CBT'`

format, or a numeric
array.

If `x`

is a numeric array or an unformatted
`dlarray`

, `x`

must be compatible with the
`'CBT'`

format. You must specify the
`'DataFormat'`

as some permutation of `'CBT'`

.
`x`

must have at least two samples along the time dimension.

**Example: **`dlarray(cos(pi./[4;2]*(0:159)),'CTB')`

and
`dlarray(cos(pi./[4;2]*(0:159))','TCB')`

both specify one batch
observation of a two-channel sinusoid in the `'CBT'`

format.

**Data Types: **`single`

| `double`

**Complex Number Support: **Yes

`Lo,Hi`

— Filters

numeric vectors |
`dlarray`

objects

Filters used in the MODWT computation, specified as a pair of even-length
real-valued numeric vectors or unformatted `dlarray`

objects.
`Lo`

is the scaling (lowpass) filter, and `Hi`

is
the wavelet (highpass) filter.

In order to satisfy the MODWT requirements, `Lo`

and
`Hi`

must be the lowpass and highpass filters corresponding to an
orthogonal wavelet. The wavelet manager `wavemngr`

designates orthogonal wavelets as type 1 wavelets.

Valid built-in orthogonal wavelet families are: Best-localized Daubechies
(`"bl"`

), Beylkin (`"beyl"`

), Coiflets
(`"coif"`

), Daubechies (`"db"`

), Fejér-Korovkin
(`"fk"`

), Haar (`"haar"`

), Han linear-phase moments
(`"han"`

), Morris minimum-bandwidth (`"mb"`

),
Symlets (`"sym"`

), and Vaidyanathan (`"vaid"`

). For a
list of wavelets in each family, see `wfilters`

. You can also use `waveinfo`

with the wavelet family short name. For example,
`waveinfo("db")`

. Use `wavemngr("type",wn)`

to
determine if the wavelet `wn`

is orthogonal (returns 1). For example,
`wavemngr("type","db6")`

returns 1.

If you have `Lo`

and `Hi`

as numeric vectors,
you can use `isorthwfb`

to determine orthogonality: `[tf,checks] = isorthwfb(Lo,Hi)`

.

If unspecified, `Lo`

and `Hi`

default to:
`[~,~,Lo,Hi] = wfilters("sym4")`

.

**Note**

You can specify a pair of empty inputs for `Lo`

and
`Hi`

. In this case, the `dlmodwt`

function
uses the default filters. For example, `dlmodwt(x,[],[])`

is
equivalent to `dlmodwt(x)`

. For more information, see Version
History.

**Data Types: **`single`

| `double`

`level`

— Transform level

`floor(log2(T))`

, where `T`

is the
size of `x`

along the time dimension (default) | positive integer

Transform level of the MODWT, specified as a positive integer less than or equal to
`floor(log2(T))`

, where `T`

is the size of
`x`

along the time dimension. If unspecified,
`dlmodwt`

computes the MODWT down to level
`floor(log2(T))`

.

**Data Types: **`single`

| `double`

### Name-Value Arguments

Specify optional pairs of arguments as
`Name1=Value1,...,NameN=ValueN`

, where `Name`

is
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.

**Example: **`w = dlmodwt(x,DataFormat='TCB')`

specifies the data format as
`'TCB'`

.

`BOUNDARY`

— Extension method

`"periodic"`

(default) | `"reflection"`

Extension method to apply at the boundary in the computation of the MODWT, specified as one of these:

`"periodic"`

— Extend signal periodically`"reflection"`

— Extend signal by reflection. The function computes the MODWT using a reflected signal along the`T`

dimension twice the original length of`x`

. The MODWT transform coefficients are also twice the length of the input.

**Example: **`w = dlmodwt(x,DataFormat="TCB",BOUNDARY="reflection")`

extends the signal by reflection.

`DataFormat`

— Data format of input

character vector | string scalar

Data format of input `x`

, specified as some permutation of
`'CBT'`

. This argument is valid only if `x`

is
unformatted.

Each character in this argument must be one of these labels:

`C`

— Channel`B`

— Batch`T`

— Time

The `dlmodwt`

function accepts any permutation of
`'CBT'`

. Each element of the argument labels the matching dimension
of `x`

.

**Example: **`w = dlmodwt(x,DataFormat="BCT")`

specifies the data
format of the unformatted `dlarray`

object as
`"BCT"`

.

**Data Types: **`char`

| `string`

## Output Arguments

`w`

— Maximal overlap discrete wavelet transform

formatted `dlarray`

object | unformatted `dlarray`

object

Maximal overlap discrete wavelet transform of `x`

, returned as a
`'SCBT'`

formatted `dlarray`

. `w`

contains the wavelet coefficients and final-level scaling coefficients of
`x`

. The MODWT partitions the energy of the signal across the
various scales and scaling coefficients. For more information, see `modwt`

.

The size of `w`

depends on the boundary extension method used in
the computation of the MODWT.

If the signal is extended periodically, then

`w`

is`level`

+1-by-`C`

-by-`B`

-by-`T`

.If the signal is extended by reflection, then

`w`

is`level`

+1-by-`C`

-by-`B`

-by-2×`T`

.

`level`

is the transform level of the MODWT.
`C`

and `B`

correspond to the channel and batch
dimensions, respectively. The *k*th row of `w`

contains the wavelet coefficients for the *k*th level. The
(`level`

+1)th row of `w`

contains the
approximation coefficients.

If you specify `'DataFormat'`

, `w`

is an
unformatted `dlarray`

.

`mra`

— Multiresolution analysis

formatted `dlarray`

object | unformatted `dlarray`

object

Multiresolution analysis of the MODWT of `x`

, returned as a
`'SCBT'`

formatted `dlarray`

. `mra`

contains the projections of `x`

onto wavelet subspaces and a scaling
space. For more information, see `modwtmra`

.

`mra`

is
`level`

+1-by-`C`

-by-`B`

-by-`T`

,
where `level`

is the transform level of the MODWT. The
*k*th row of `mra`

contains the details for the
*k*th level. The (`level`

+1)th row of
`mra`

contains the `level`

th level
smooth.

If you specify `'DataFormat'`

, `mra`

is an
unformatted `dlarray`

compatible with `'SCBT'`

format.

To learn more about the differences between the MODWT and the MRA, see Comparing MODWT and MODWTMRA.

## Extended Capabilities

### GPU Arrays

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 History

**Introduced in R2022a**

### R2022b: `dlmodwt`

behavior change

You can now specify a pair of empty inputs for the lowpass and highpass filters. The
`dlmodwt`

function continues to generate an error if one filter input
is empty and the other filter input is nonempty.

Functionality | Previous Behavior | New Behavior |
---|---|---|

`w = dlmodwt(x,[],[])`
| Errors | `w = dlmodwt(x,[],[])` is equivalent to `w = dlmodwt(x)` |

`w = dlmodwt(x,[],[],level)` | Errors | `w = dlmodwt(x,[],[],level)` is equivalent to ```
w =
dlmodwt(x,Lo,Hi,level)
``` ,where ```
[~,~,Lo,Hi] =
wfilters('sym4')
``` |

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

# Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)