# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

# cwt

Continuous 1-D wavelet transform

See `cwt` for information on the older version of the `cwt`. The older version is no longer recommended.

## Syntax

``wt = cwt(x)``
``wt = cwt(x,wname)``
``````[wt,f] = cwt(___,fs)``````
``````[wt,period] = cwt(___,ts)``````
``````[wt,f,coi] = cwt(___,fs)``````
``````[wt,period,coi] = cwt(___,ts)``````
``[___] = cwt(___,Name,Value)``
``cwt(___)``

## Description

example

````wt = cwt(x)` returns the continuous wavelet transform (CWT) of `x`. The input, `x`, is a double-precision real- or complex-valued vector and must have at least four samples. The CWT is obtained using the analytic Morse wavelet with the symmetry parameter (gamma) equal to 3 and the time-bandwidth product equal to 60. `cwt` uses 10 voices per octave. The minimum and maximum scales are determined automatically based on the wavelet's energy spread in frequency and time. If `x` is real-valued, `wt` is a 2-D matrix where each row corresponds to one scale. The column size of `wt` is equal to the length of `x`. If `x` is complex-valued, `wt` is a 3-D matrix, where the first page is the CWT for the positive scales (analytic part or counterclockwise component) and the second page is the CWT for the negative scales (anti-analytic part or clockwise component).```

example

````wt = cwt(x,wname)` uses the analytic wavelet specified by `wname` to compute the CWT. Valid options for `wname` are `'morse'`, `'amor'`, and `'bump'`, which specify the Morse, Morlet, and bump wavelet, respectively. If you do not specify `wname`, `wname` defaults to `'morse'`.```

example

``````[wt,f] = cwt(___,fs)``` specifies the sampling frequency, `fs`, in Hz as a positive scalar. `cwt` uses `fs` to determine the scale-to-frequency conversions and returns the frequencies, `f`, in Hz. If you do not specify a sampling frequency, `cwt` returns `f` in cycles per sample. If the input `x` is complex, the scale-to-frequency conversions apply to both pages of `wt`.```

example

``````[wt,period] = cwt(___,ts)``` specifies the sampling interval, `ts`, as a positive `duration` scalar. The `duration` can be in years, days, hours, minutes, or seconds. `cwt` uses `ts` to compute the scale-to period conversion and returns the time periods in `period`. The array of durations in `period` have the same format property as `ts`. If the input `x` is complex, the scale-to-period conversions apply to both pages of `wt`.```

example

``````[wt,f,coi] = cwt(___,fs)``` returns the cone of influence, `coi`, which shows where edge effects of the CWT become significant. The cone of influence for the CWT is in Hz. If the input `x` is complex, the cone of influence applies to both pages of `wt`.```
``````[wt,period,coi] = cwt(___,ts)``` returns the cone of influence, `coi`, which shows where edge effects of the CWT become significant. The cone of influence for the CWT is in cycles per sample. . If the input `x` is complex, the cone of influence applies to both pages of `wt`.```
````[___] = cwt(___,Name,Value)` returns the CWT with additional options specified by one or more `Name,Value` pair arguments.```
````cwt(___)` with no output arguments plots the CWT scalogram, which is the absolute value of the CWT as a function of time and frequency. The cone of influence showing where edge effects become significant is also plotted. Gray regions outside the dashed white line delineate regions where edge effects are significant. If the input signal is complex-valued, the positive (counterclockwise) and negative (clockwise) components are plotted in separate scalograms.If you do not specify a sampling frequency, `fs`, or time interval, `ts`, the frequencies are plotted in cycles per sample. If you specify a sampling frequency, `fs`, the frequencies are in Hz. If you specify a sampling duration, the plot is a function of time and periods. The y-axis of the scalogram uses a log2 scale. If you use a data cursor, the actual y-value is displayed. For example, if the axis value is approximately 0.125, the data cursor y-value is –3.01, which you can verify using `pow2(3.01)`. ```

## Examples

collapse all

Obtain the continuous wavelet transform of a speech sample using default values.

```load mtlb; w = cwt(mtlb);```

Obtain the continuous wavelet transform of a speech sample using the bump wavelet instead of the default Morse wavelet.

```load mtlb; cwt(mtlb,'bump',Fs);```

Compare the result obtained from the CWT using the default Morse wavelet.

`cwt(mtlb,Fs);`

Create two sine waves with frequencies of 32 and 64 Hz. The data is sampled at 1000 Hz. The two sine waves have disjoint support in time.

```Fs = 1e3; t = 0:1/Fs:1; x = cos(2*pi*32*t).*(t>=0.1 & t<0.3) + sin(2*pi*64*t).*(t>0.7);```

Add white Gaussian noise with a standard deviation of 0.05.

```wgnNoise = 0.05*randn(size(t)); x = x + wgnNoise;```

Obtain and plot the cwt using a Morse wavelet.

`cwt(x,1000)`

Create two complex exponentials, of different amplitudes, with frequencies of 32 and 64 Hz. The data is sampled at 1000 Hz. The two complex exponentials have disjoint support in time.

```Fs = 1e3; t = 0:1/Fs:1; z = exp(1i*2*pi*32*t).*(t>=0.1 & t<0.3)+2*exp(-1i*2*pi*64*t).*(t>0.7);```

Add complex white Gaussian noise with a standard deviation of 0.05.

```wgnNoise = 0.05/sqrt(2)*randn(size(t))+1i*0.05/sqrt(2)*randn(size(t)); z = z+wgnNoise;```

Obtain and plot the cwt using a Morse wavelet.

`cwt(z,Fs)`

Note the magnitudes of the complex exponential components in the colorbar are essentially their amplitudes even though they are at different scales. This is a direct result of the L1 normalization. You can verify this by executing this script and exploring each subplot with a datacursor.

Obtain the CWT of Kobe earthquake data. The sampling frequency is 1 Hz.

`load kobe;`

Plot the earthquake data.

```plot((1:numel(kobe))./60,kobe); xlabel('mins'); ylabel('nm/s^2'); grid on title('Kobe Earthquake Data');```

Obtain the CWT, frequencies, and cone of influence.

`[wt,f,coi] = cwt(kobe,1);`

Plot the data, including the cone of influence.

`cwt(kobe,1);`

Obtain the CWT, time periods, and cone of influence by specifying a time duration instead of a sampling frequency.

`[wt,periods,coi] = cwt(kobe,minutes(1/60));`

View the same data by specifying a sampling period input instead of a frequency.

`cwt(kobe,minutes(1/60));`

## Input Arguments

collapse all

Input signal, specified as a row or column vector. `x` is a double-precision real- or complex-valued vector and must have at least four samples.

Analytic wavelet used to compute the CWT, specified as `'morse'`, `'amor'`, or `'bump'`. These character vectors specify the analytic Morse, Morlet, and bump wavelet, respectively.

The default Morse wavelet uses a symmetry parameter, $\gamma$, that is equal to 3 and has a time-bandwidth product that of 60.

Sampling frequency, in Hz, specified as a positive scalar. If you specify `fs`, then you cannot specify `ts`.

Time duration, also known as the sampling interval, specified as a positive `duration` scalar. Valid durations are `years`, `days`, `hours`, `minutes`, and `seconds`. You cannot use calendar durations. If you specify `ts`, then you cannot specify `fs`.

Example: `wt = cwt(x,hours(12))`

Data Types: `duration`

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside single quotes (`' '`). You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: `'ExtendSignal',false` indicates that the signal is not extended.

collapse all

Option to extend the input signal symmetrically by reflection, specified as the comma-separated pair consisting of `'ExtendSignal'` and either `true` or `false`. Extending the signal symmetrically can mitigate boundary effects. If you specify `true`, then the signal is extended. If you specify `false`, then the signal is not extended.

Number of voices per octave to use for the CWT, specified as the comma-separated pair consisting of `'VoicesPerOctave'` and an even integer from 4 to 48. The CWT scales are discretized using the specified number of voices per octave. The energy spread of the wavelet in frequency and time automatically determines the minimum and maximum scales.

Number of octaves, specified as the comma-separated pair consisting of `'NumOctaves'` and a positive integer. The number of octaves cannot exceed `floor(log2(numel(x)))-1`. Specifying a `NumOctaves` value overrides the automatic determination of the maximum scale. If you do not need to examine lower frequency values, use a smaller `NumOctaves` value.

Time-bandwidth product of the Morse wavelet, specified as the comma-separated pair consisting of `'TimeBandwidth'` and a scalar greater than 3 and less than or equal to 120. The symmetry parameter, gamma ($\gamma$), is fixed at 3. Wavelets with larger time-bandwidth products have larger spreads in time and narrower spreads in frequency. The standard deviation of the Morse wavelet in time is approximately `1/2*sqrt(TimeBandwidth/2)`.

If you specify `'TimeBandwidth'`, you cannot specify `'WaveletParameters'`. To specify both the symmetry and time-bandwidth product, use `'WaveletParameters'` instead.

Symmetry and time-bandwidth product of Morse wavelet, specified as the comma-separated pair consisting of `'WaveletParameters'` and a two-element vector of scalars.

The first element is the symmetry, $\gamma$, which must be greater than or equal to 1. The second element is the time-bandwidth product which must be greater than $\gamma$. The ratio of the time-bandwidth product to $\gamma$ cannot exceed 40.

When $\gamma$ is equal to 3, the Morse wavelet is perfectly symmetric in the frequency domain and the skewness is 0. When $\gamma$ is greater than 3, the skewness is positive. When $\gamma$ is less than 3, the skewness is negative.

If you specify `'WaveletParameters'`, you cannot specify `'TimeBandwidth'`.

## Output Arguments

collapse all

Continuous wavelet transform, returned as a matrix of complex values. By default, `cwt` uses the analytic Morse (3,60) wavelet, where 3 is the symmetry and 60 is the time-bandwidth product. `cwt` uses 10 voices per octave. If `x` is real-valued, `wt` is an Na-by-N matrix, where Na is the number of scales, and N is the number of samples in `x`. If `x` is complex-valued, `wt` is a 3-D matrix, where the first page is the CWT for the positive scales (analytic part or counterclockwise component) and the second page is the CWT for the negative scales (anti-analytic part or clockwise component). The minimum and maximum scales are determined automatically based on the energy spread of the wavelet in frequency and time. See Algorithms for information on how the scales are determined.

Data Types: `double`
Complex Number Support: Yes

Frequencies of the CWT, returned as a vector. If you specify a sampling frequency, `fs`, then `f` is in Hz. If you do not specify `fs`, `cwt` returns `f` in cycles per sample.

Time periods, returned as an array of durations. The durations are in the same format as `ts`. Each row corresponds to a period.

Cone of influence for the CWT, returned as either an array of doubles or array of durations. The cone of influence indicates where edge effects occur in the CWT. If you specify a sampling frequency, `fs`, the cone of influence is in Hz. If you specify a time duration, `ts`, the cone of influence is in periods. Due to the edge effects, give less credence to areas that are outside or overlap the cone of influence.

## Algorithms

collapse all

### Minimum Scale

To determine the minimum scale, first obtain the Fourier transform, ${\omega }_{x}$ of the base wavelet. Then, find the peak frequency of that transformed data. For Morse wavelets, dilate the wavelet so that the Fourier transform of the wavelet at $\pi$ radians is equal to 10% of the peak value. The smallest scale occurs at the largest frequency:

`${s}_{0}=\frac{{\omega }_{x}^{\text{'}}}{\pi }$`
As a result, the smallest scale is the minimum of (2, ${s}_{0}$). For Morse wavelets, the smallest scale is usually ${s}_{0}$. For the Morlet wavelet, the smallest scale is usually 2.

### Maximum Scale

Both the minimum and maximum scales of the CWT are determined automatically based on the energy spread of the wavelet in frequency and time. To determine the maximum scale, CWT uses the following algorithm.

The standard deviation of the Morse wavelet in time, ${\sigma }_{t}$, is approximately $\sqrt{\frac{P}{2}}$, where $P$ is the time-bandwidth product. The standard deviation in frequency, ${\sigma }_{f}$, is approximately $\frac{1}{2}\sqrt{\frac{2}{P}}$. If you scale the wavelet by some $s>1$, the time duration changes to $2s{\sigma }_{t}=N$, which is the wavelet stretched to equal the full length (N samples) of the input. You cannot translate this wavelet or stretch it further without causing it to wrap, so the largest scale is $floor\left(\frac{N}{2{\sigma }_{t}}\right)$.

Wavelet transform scales are powers of 2 and are denoted by ${s}_{0}{\left({2}^{\frac{1}{NV}}\right)}^{j}$. NV is the number of voices per octave, and j is from 0 to the largest scale. For a specific small scale, ${s}_{0}$:

`${s}_{0}{\left({2}^{\frac{1}{NV}}\right)}^{j}\le \frac{N}{2{\sigma }_{t}}$`

Converting to log2:

`$j{\mathrm{log}}_{2}\left({2}^{\frac{1}{NV}}\right)\le {\mathrm{log}}_{2}\left(\frac{N}{2{\sigma }_{t}{s}_{0}}\right)$`
`$j\le NV{\mathrm{log}}_{2}\frac{N}{2{\sigma }_{t}{s}_{0}}$`
Therefore, the maximum scale is
`${2}^{floor\left(NV{\mathrm{log}}_{2}\frac{N}{2{\sigma }_{t}{s}_{0}}\right)}$`

### L1 Norm for CWT

In integral form, the CWT preserves energy. However, when you implement the CWT numerically, energy is not preserved. In this case, regardless of the normalization you use, the CWT is not an orthonormal transform. The `cwt` function uses L1 normalization

Wavelet transforms commonly use L2 normalization of the wavelet. For the L2 norm, dilating a signal by 1/s, where s is greater than 0, is defined as follows:

`${‖x\left(\frac{t}{s}\right)‖}_{2}^{2}=s{‖x\left(t\right)‖}_{2}^{2}$`
The energy is now s times the original energy. When included in the Fourier transform, multiplying by $1}{\sqrt{s}}$ produces different weights being applied to different scales, so that the peaks at higher frequencies are reduced more than the peaks at lower frequencies.

In many applications, L1 normalization is better. The L1 norm definition does not include squaring the value, so the preserving factor is 1/s instead of $1}{\sqrt{s}}$. Instead of high-frequency amplitudes being reduced as in the L2 norm, for L1 normalization, all frequency amplitudes are normalized to the same value. Therefore, using the L1 norm shows a more accurate representation of the signal. See example Continuous Wavelet Transform of Two Complex Exponentials.

## References

[1] Lilly, J. M., and S. C. Olhede. “Generalized Morse Wavelets as a Superfamily of Analytic Wavelets.” IEEE Transactions on Signal Processing. Vol. 60, No. 11, 2012, pp. 6036–6041.

[2] Lilly, J. M., and S. C. Olhede. “Higher-Order Properties of Analytic Wavelets.” IEEE Transactions on Signal Processing. Vol. 57, No. 1, 2009, pp. 146–160.

[3] Lilly, J. M. jLab: A data analysis package for Matlab, version 1.6.2. 2016. http://www.jmlilly.net/jmlsoft.html.