# cwtfreqbounds

CWT maximum and minimum frequency or period

## Syntax

## Description

`[`

returns the minimum and maximum wavelet bandpass frequencies in cycles/sample for a
signal of length `minfreq`

,`maxfreq`

] = cwtfreqbounds(`N`

)`N`

. The minimum and maximum frequencies are
determined for the default Morse (3,60) wavelet. The minimum frequency is determined
so that two time standard deviations of the default wavelet span the
`N`

-point signal at the coarsest scale. The maximum frequency
is such that the highest frequency wavelet bandpass filter drops to ½ of its peak
magnitude at the Nyquist frequency.

`[`

returns the bandpass periods for the sampling period `maxperiod`

,`minperiod`

] = cwtfreqbounds(`N`

,`Ts`

)`Ts`

.
`maxperiod`

and `minperiod`

are scalar
durations with the same format as `Ts`

. If the number of standard
deviations is set so that `log2(maxperiod/minperiod) < 1/NV`

where `NV`

is the number of voices per octave,
`maxperiod`

is adjusted to ```
minperiod ×
2^(1/NV)
```

.

`[___] = cwtfreqbounds(___,`

returns the minimum and maximum wavelet bandpass frequencies or periods with
additional options specified by one or more `Name=Value`

)`Name=Value`

arguments. For example, ```
[minf,maxf] =
cwtfreqbounds(1000,TimeBandwidth=30)
```

sets the time-bandwidth parameter
of the default Morse wavelet to 30.

## Examples

### Wavelet Bandpass Frequencies Using Default Values

Obtain the minimum and maximum wavelet bandpass frequencies for a signal with 1000 samples using the default values.

[minfreq,maxfreq] = cwtfreqbounds(1000)

minfreq = 0.0033

maxfreq = 0.4341

### Construct CWT Filter Bank With Peak Magnitude at Nyquist

Obtain the minimum and maximum wavelet bandpass frequencies for the default Morse wavelet for a signal of length 10,000 and a sampling frequency of 1 kHz. Set the cutoff to 100% so that the highest frequency wavelet bandpass filter peaks at the Nyquist frequency of 500 Hz.

sigLength = 10000; Fs = 1e3; [minfreq,maxfreq] = cwtfreqbounds(sigLength,Fs,cutoff=100);

Construct a CWT filter bank using the values `cwtfreqbounds`

returns. Obtain the frequency responses of the filter bank.

```
fb = cwtfilterbank(SignalLength=sigLength,SamplingFrequency=Fs,...
FrequencyLimits=[minfreq maxfreq]);
[psidft,f] = freqz(fb);
```

Construct a second CWT filter bank identical to the first, but instead use the default frequency limits. Obtain the frequency responses of the second filter bank.

fb2 = cwtfilterbank(SignalLength=sigLength,SamplingFrequency=Fs); [psidft2,~] = freqz(fb2);

For each filter bank, plot the frequency response of the filter with the highest center frequency. Confirm the frequency response from the first filter bank peaks at the Nyquist, and the frequency response from the second filter bank is 50% of the peak magnitude at the Nyquist.

plot(f,psidft(1,:)) hold on plot(f,psidft2(1,:)) hold off title("Frequency Responses") xlabel("Frequency (Hz)") ylabel("Magnitude") legend("First Filter Bank","Second Filter Bank",... Location="NorthWest")

### Decay Highest Frequency Wavelet in CWT Filter Bank to Specific Value

Obtain the minimum and maximum frequencies for the bump wavelet for a signal of length 5,000 and a sampling frequency of 10 kHz. Specify a cutoff value of $$100\times 1{0}^{-8}/2$$ so that the highest frequency wavelet bandpass filter decays to $$1{0}^{-8}$$ at the Nyquist.

`[minf,maxf] = cwtfreqbounds(5e3,1e4,wavelet="bump",cutoff=100*1e-8/2);`

Construct the filter bank using the values returned by `cwtfreqbounds`

. Plot the frequency responses.

fb = cwtfilterbank(SignalLength=5e3,Wavelet="bump",... SamplingFrequency=1e4,FrequencyLimits=[minf maxf]); freqz(fb)

### Frequency Range for Strictly Zero and Effectively Zero Cutoff Values

Obtain the minimum and maximum wavelet bandpass frequencies for a signal of length 4096. Specify a cutoff of 0. Display the minimum and maximum bandpass frequencies.

sLength = 4096; co = 0; [minfreq,maxfreq] = cwtfreqbounds(sLength,Cutoff=co); fprintf("Min Frequency: %f cycles/sample\nMax Frequency: %f cycles/sample", ... minfreq,maxfreq)

Min Frequency: 0.000805 cycles/sample Max Frequency: 0.103574 cycles/sample

Create a filter bank using the frequency limits. Obtain the two-sided wavelet frequency responses.

```
fb = cwtfilterbank(SignalLength=sLength,FrequencyLimits=[minfreq,maxfreq]);
[psif,f] = freqz(fb,FrequencyRange="twosided");
```

Obtain the minimum and maximum wavelet bandpass frequencies for a signal of length 4096, but this time specify a cutoff of $$100\times 1{0}^{-8}/2$$. Create a second filter bank using these new frequencies. Confirm the second frequency range is larger than the first frequency range.

co = 100*(1e-8/2); [minfreq2,maxfreq2] = cwtfreqbounds(sLength,Cutoff=co); fb2 = cwtfilterbank(SignalLength=sLength,FrequencyLimits=[minfreq2,maxfreq2]); fprintf("Min Frequency: %f cycles/sample\nMax Frequency: %f cycles/sample", ... minfreq2,maxfreq2);

Min Frequency: 0.000805 cycles/sample Max Frequency: 0.281770 cycles/sample

Obtain the two-sided wavelet frequency responses of the second filter bank.

`[psif2,f2] = freqz(fb2,FrequencyRange="twosided");`

Plot the frequency responses of the filter banks.

subplot(2,1,1) plot(f,psif) title("Frequency Responses: Zero Cutoff Filter Bank") ylabel("Magnitude") xlabel("Normalized Frequency (cycles/sample)") subplot(2,1,2) plot(f2,psif2) title("Frequency Responses: Nonzero Cutoff Filter Bank") ylabel("Magnitude") xlabel("Normalized Frequency (cycles/sample)")

For the wavelet filter with the highest center frequency in each filter bank, obtain the magnitude of the frequency response at the Nyquist. Observer there is minimal difference between the two values.

`fprintf("Zero Cutoff / Magnitude at Nyquist: %g",psif(1,floor(size(psif,2)/2)))`

Zero Cutoff / Magnitude at Nyquist: 2.43333e-309

`fprintf("Nonzero Cutoff / Magnitude at Nyquist: %g",psif2(1,floor(size(psif2,2)/2)))`

Nonzero Cutoff / Magnitude at Nyquist: 1.02265e-08

## Input Arguments

`N`

— Signal length

positive integer ≥ 4

Signal length, specified as a positive integer greater than or equal to 4.

**Data Types: **`double`

`Fs`

— Sampling frequency

positive scalar

Sampling frequency in hertz, specified as a positive scalar.

**Example: **```
[minf,maxf] =
cwtfreqbounds(2048,100)
```

**Data Types: **`double`

`Ts`

— Sampling period

scalar duration

Sampling period, specified as a positive scalar `duration`

.

**Example: **```
[minp,maxp] =
cwtfreqbounds(2048,seconds(2))
```

**Data Types: **`duration`

### 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: **```
[minf,maxf] =
cwtfreqbounds(1000,Wavelet="bump",VoicesPerOctave=10)
```

returns the
minimum and maximum bandpass frequencies using the bump wavelet and 10 voices per
octave for a signal with 1000 samples.

*
Before R2021a, use commas to separate each name and value, and enclose*
`Name`

*in quotes.*

**Example: **```
[minf,maxf] =
cwtfreqbounds(1000,"Wavelet","bump","VoicesPerOctave",10)
```

`Wavelet`

— Analysis wavelet

`"Morse"`

(default) | `"amor"`

| `"bump"`

Analysis wavelet used to determine the minimum and maximum frequencies
or periods, specified as `"Morse"`

,
`"amor"`

, or `"bump"`

. These
strings specify the analytic Morse, Morlet, and bump wavelet,
respectively. The default wavelet is the analytic Morse (3,60)
wavelet.

For Morse wavelets, you can also parametrize the wavelet using the
`TimeBandwidth`

or
`WaveletParameters`

name-value arguments.

**Example: **```
[minp,maxp] =
cwtfreqbound(2048,seconds(1),Wavelet="bump")
```

`Cutoff`

— Percentage of the peak magnitude

`50`

for the Morse wavelet,
`10`

for the analytic Morlet and bump
wavelets (default) | scalar between 0 and 100

Percentage of the peak magnitude at the Nyquist, specified as a scalar
between 0 and 100. Setting `Cutoff`

to
`0`

indicates that the wavelet frequency response
decays to 0 at the Nyquist. Setting `Cutoff`

to
`100`

indicates that the value of the wavelet
bandpass filters peaks at the Nyquist.

For `cwtfilterbank`

, the analytic wavelets filters
peak at a value of 2. As a result, you can ensure the highest frequency
wavelet decays to a value of α at the Nyquist frequency by setting
`Cutoff`

to 100 × α/2. In that case, you must have 0 ≤ α ≤ 2.

**Note**

Unless your application requires a strict cutoff value of 0,
consider setting `Cutoff`

to a small nonzero
value, for example, on the order of 10^{-8}. By specifying a small value, you can increase
the frequency range
`[`

and still obtain a wavelet frequency response that effectively
decays to 0 at the Nyquist. See Frequency Range for Strictly Zero and Effectively Zero Cutoff Values.`minfreq`

,`maxfreq`

]

**Data Types: **`double`

`StandardDeviations`

— Number of time standard deviations

`2`

(default) | positive integer ≥ 2

Number of time standard deviations used to determine the minimum
frequency (longest scale), specified as a positive integer greater than
or equal to 2. For the Morse, analytic Morlet, and bump wavelets, four
standard deviations generally ensures that the wavelet decays to zero at
the ends of the signal support. Incrementing
`StandardDeviations`

by multiples of 4, for example
4**M*, ensures that *M* whole
wavelets fit within the signal length. If the number of standard
deviations is set so that ```
log2(minfreq/maxfreq) >
-1/NV
```

, where `NV`

is the number of voices
per octave, `minfreq`

is adjusted to ```
maxfreq
× 2^(-1/NV)
```

.

**Data Types: **`double`

`TimeBandwidth`

— Time-bandwidth for the Morse wavelet

`60`

(default) | scalar greater than 3 and less than or equal to 120

Time-bandwidth for the Morse wavelet, specified as a positive scalar.
The symmetry (gamma) of the Morse wavelet is assumed to be 3. The larger
the time-bandwidth parameter, the more spread out the wavelet is in time
and narrower the wavelet is in frequency. The standard deviation of the
Morse wavelet in time is approximately
`sqrt(TimeBandwidth/2)`

. The standard deviation in
frequency is approximately
`1/2*sqrt(2/TimeBandwidth)`

.

If you specify `TimeBandwidth`

, you cannot specify
`WaveletParameters`

.

**Data Types: **`double`

`WaveletParameters`

— Morse wavelet parameters

`[3,60]`

(default) | two-element vector of scalars

Morse wavelet parameters, specified as a two-element vector. The first element is the symmetry parameter (gamma), which must be greater than or equal to 1. The second element is the time-bandwidth parameter, which must be greater than or equal to gamma. The ratio of the time-bandwidth parameter to gamma cannot exceed 40.

When gamma is equal to 3, the Morse wavelet is perfectly symmetric in the frequency domain. The skewness is equal to 0. Values of gamma greater than 3 result in positive skewness, while values of gamma less than 3 result in negative skewness.

If you specify `WaveletParameters`

, you cannot
specify `TimeBandwidth`

.

**Data Types: **`double`

`VoicesPerOctave`

— Number of voices per octave

`10`

(default) | integer between 1 and 48

Number of voices per octave to use in determining the necessary separation between the minimum and maximum scales, specified as an integer between 1 and 48. The minimum and maximum scales are equivalent to the minimum and maximum frequencies or maximum and minimum periods, respectively.

**Data Types: **`double`

## Output Arguments

`minfreq`

— Minimum wavelet bandpass frequency

scalar

Minimum wavelet bandpass frequency, returned as a scalar.
`minfreq`

is in cycles/sample if
`SamplingFrequency`

is not specified. Otherwise,
`minfreq`

is in hertz.

**Data Types: **`double`

`maxfreq`

— Maximum wavelet bandpass frequency

scalar

Maximum wavelet bandpass frequency, returned as a scalar.
`maxfreq`

is in cycles/sample if
`SamplingFrequency`

is not specified. Otherwise,
`maxfreq`

is in hertz.

**Data Types: **`double`

`maxperiod`

— Maximum wavelet bandpass period

scalar duration

Maximum wavelet bandpass period, returned as a scalar duration with the
same format as `Ts`

.

If the number of standard deviations is set so that
`log2(maxperiod/minperiod) < 1/NV`

, where
`NV`

is the number of voices per octave,
`maxperiod`

is adjusted to ```
minperiod ×
2^(1/NV)
```

.

**Data Types: **`duration`

`minperiod`

— Minimum wavelet bandpass period

scalar duration

Minimum wavelet bandpass period, returned as a scalar duration with the
same format as `Ts`

.

If the number of standard deviations is set so that
`log2(maxperiod/minperiod) < 1/NV`

, where
`NV`

is the number of voices per octave,
`maxperiod`

is adjusted to ```
minperiod ×
2^(1/NV)
```

**Data Types: **`duration`

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

The sampling period (

`Ts`

) input argument is not supported.

## Version History

**Introduced in R2018a**

## See Also

## 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)