# wentropy

Wavelet entropy

## Description

## Examples

### Obtain Wavelet Entropy

**Shannon Entropy**

Create a signal whose samples are alternating values of 0 and 2.

n = 0:499; x = 1+(-1).^n; stem(x) axis tight title("Signal") xlim([0 50])

Obtain the scaled Shannon entropy of the signal. Specify a one-level wavelet transform, use the default wavelet and wavelet transform.

ent = wentropy(x,Level=1); ent

`ent = `*2×1*
1.0000
1.0000

Obtain the unscaled Shannon entropy. Divide the entropy by `log(n)`

, where `n`

is the length of the signal. Confirm the result equals the scaled entropy.

ent2 = wentropy(x,Level=1,Scaled=false); ent2/log(length(x))

`ans = `*2×1*
1.0000
1.0000

Create a zero-mean signal from the first signal. Obtain the scaled Shannon entropy of the new signal using a one-level wavelet transform.

x = x-1; ent = wentropy(x,Level=1); ent

`ent = `*2×1*
1.0000
0

**Renyi Entropy**

Load the Kobe earthquake data. Obtain the level 4 tunable Q-factor wavelet transform of the data with a quality factor equal to 2.

```
load kobe
wt = tqwt(kobe,Level=4,QualityFactor=2);
```

Obtain the Renyi entropy estimates for the tunable Q-factor transform.

```
ent = wentropy(wt,Entropy="Renyi");
ent
```

`ent = `*5×1*
0.8288
0.8506
0.8582
0.8536
0.7300

Load the ECG data. Obtain the level 5 discrete wavelet transform of the signal using the `"db4"`

wavelet.

load wecg wv = "db4"; [C,L] = wavedec(wecg,5,wv);

Package the wavelet and approximation coefficients into a cell array suitable for computing the wavelet entropy.

```
X = detcoef(C,L,"cells");
X{end+1} = appcoef(C,L,wv);
```

Obtain the Renyi entropy by scale.

```
ent = wentropy(X,Entropy="Renyi");
ent
```

`ent = `*6×1*
0.2412
0.5239
0.5459
0.6520
0.7661
0.8547

**Tsallis Entropy**

Create a Kronecker delta sequence.

N = 512; seq = zeros(1,N); seq(N/2) = 1;

Obtain the scaled Shannon entropy of the signal. Specify a level 3 wavelet transform.

ShannonEntropy = wentropy(seq,Level=3);

Obtain the scaled Tsallis entropy of the signal for different values of exponents. Confirm that as the exponent goes to 1, the Tsallis entropy approaches the Shannon entropy.

exps = 3:-1/4:1; TsallisExponent = zeros(length(exps),1); TsallisEntropy = zeros(length(exps),4); ctr = 1; for k=exps ent2 = wentropy(seq,Level=3,Entropy="Tsallis",Exponent=k); TsallisExponent(ctr) = k; TsallisEntropy(ctr,:) = ent2'; ctr = ctr+1; end TsallisTable = table(TsallisExponent,TsallisEntropy)

`TsallisTable=`*9×2 table*
TsallisExponent TsallisEntropy
_______________ ________________________________________
3 0.71454 0.87888 0.97069 0.98285
2.75 0.67651 0.84955 0.95685 0.97233
2.5 0.63178 0.81187 0.93596 0.9552
2.25 0.57852 0.7628 0.90407 0.92718
2 0.51437 0.69812 0.85499 0.88149
1.75 0.43679 0.61258 0.77985 0.80825
1.5 0.34491 0.50213 0.66897 0.69658
1.25 0.24402 0.37071 0.52076 0.54417
1 0.1495 0.23839 0.356 0.37278

ShannonEntropy'

`ans = `*1×4*
0.1495 0.2384 0.3560 0.3728

## Input Arguments

`X`

— Input data

real-valued vector | real-valued matrix | cell array

Input data, specified as a real-valued row or column vector, a cell array of real-valued row or column vectors, or a real-valued matrix with at least two rows.

If

`X`

is a row or column vector,`X`

must have at least four samples, and the function assumes`X`

represents time data.If

`X`

is a cell array, the function assumes`X`

to be a decimated wavelet or wavelet packet transform of a real-valued row or column vector.If

`X`

is a matrix with at least two rows, the function assumes`X`

to be the maximal overlap discrete wavelet or wavelet packet transform of a real-valued row or column vector.

**Example: **`ent = wentropy(randn(1,1024))`

returns the
normalized Shannon wavelet entropy. `wentropy`

computes
the wavelet coefficients using the default options of
`modwt`

.

**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: **`ent = wentropy(X,Wavelet="coif4")`

uses the
`"coif4"`

wavelet to obtain the wavelet
transform.

`Entropy`

— Entropy

`"Shannon"`

(default) | `"Renyi"`

| `"Tsallis"`

Entropy returned by `wentropy`

, specified as one of
`"Shannon"`

, `"Renyi"`

, and
`"Tsallis"`

. For more information, see Wavelet Entropy.

`Exponent`

— Exponent

`2`

(default) | real scalar

Exponent to use in the Renyi and Tsallis entropy, specified as a real scalar.

For the Renyi entropy, the exponent must be nonnegative.

For the Tsallis entropy, the exponent must be greater than or equal to –1/2.

For the Renyi and Tsallis entropies, specifying

is a limiting
case and produces the Shannon entropy. Specifying
`Exponent`

=1`Exponent`

is valid only when
`Entropy`

is `"Renyi"`

or
`"Tsallis"`

.

**Note**

The Tsallis entropy is defined for all exponents not equal to 1,
with

as a
limiting case. However, for reasons of numerical stability,
`Exponent`

=1`wentropy`

supports only exponents greater
than or equal to -1/2 when `Entropy`

is
`"Tsallis"`

.

**Data Types: **`single`

| `double`

`Transform`

— Transform

`"modwt"`

(default) | `"dwt"`

| `"dwpt"`

| `"modwpt"`

Transform used to obtain the wavelet or wavelet packet coefficients
for the real-valued row or column vector `X`

,
specified as one of these:

`"dwt"`

— Discrete wavelet transform`"dwpt"`

— Discrete wavelet packet transform`"modwt"`

— Maximal overlap discrete wavelet transform`"modwpt"`

— Maximal overlap discrete wavelet packet transform

The default wavelet depends on the value of
`Transform`

.

If

`Transform`

is`"dwt"`

or`"modwt"`

,`wentropy`

uses the`"sym4"`

wavelet.If

`Transform`

is`"dwpt"`

or`"modwpt"`

,`wentropy`

uses the`"fk18"`

wavelet.

Periodic extension is used for all transforms.

`Level`

— Wavelet decomposition level

positive integer

Wavelet decomposition level if the input `X`

is
time data, specified as a positive integer. The
`wentropy`

function obtains the wavelet transform
down to the specified level. If unspecified, the default level depends
on the type of transform and the signal length *N*.

If

`Transform`

is`"dwt"`

or`"modwt"`

,`Level`

defaults to`floor(log2(`

.*N*))-1If

`Transform`

is`"dwpt"`

or`"modwpt"`

,`Level`

defaults to`min(4,floor(log2(`

.*N*))-1)

Specifying a level is invalid if the input data are wavelet or wavelet packet coefficients.

**Data Types: **`single`

| `double`

`Wavelet`

— Wavelet

character vector | string scalar

Wavelet used to obtain the wavelet or wavelet packet transform of a
real-valued row or column vector, specified as a character vector or
string scalar. If `Transform`

is
`"modwt"`

or `"modwpt"`

, the
wavelet must be orthogonal. For a list of supported orthogonal or
biorthogonal wavelets, see `wfilters`

.

Specifying a wavelet name is invalid if the input data are wavelet or wavelet packet coefficients.

**Data Types: **`char`

| `string`

`Distribution`

— Normalization method

`"scale"`

(default) | `"global"`

Normalization method to use to obtain the empirical probability
distribution for the wavelet transform coefficients, specified as
`"scale"`

or `"global"`

.

`"global"`

— The function normalizes the squared magnitudes of the coefficients by the total sum of squared magnitudes of all coefficients. Each scale in the wavelet transform yields a scalar and the vector of these values forms a probability vector. The function performs entropy calculations on this vector and the overall entropy is a scalar.`"scale"`

— The function normalizes the wavelet coefficients at each scale separately and calculates the entropy by scale yielding a vector output of size (*Ns*+1)-by-1, where*Ns*is the number of scales if the input is time series data. If the input is a cell array or matrix, the output is*M*-by-1, where*M*is the length of the cell array or number of rows in the matrix.

`Scaled`

— Scale wavelet entropy

`true`

or
`1`

(default) | `false`

or `0`

Scale wavelet entropy logical, specified as a numeric or logical
`1`

(`true`

) or
`0`

(`false`

). If specified as
`true`

, the `wentropy`

function
scales the wavelet entropy by the factor corresponding to a uniform
distribution for the specified entropy.

For the Shannon and Renyi entropies, the factor is

`1/log(`

, where*Nj*)*Nj*is the length of the data in samples by scale if`Distribution`

is`"scale"`

, or the number of scales if`Distribution`

is`"global"`

.For the Tsallis entropy, the factor is

`(`

.`Exponent`

-1)/(1-*Nj*^(1-`Exponent`

))

Setting

does not scale
the wavelet entropy.`Scaled`

=false

**Data Types: **`logical`

`EnergyThreshold`

— Energy threshold

`1e-8`

(default) | nonnegative scalar

Energy threshold, specified as a nonnegative scalar. The function
replaces all coefficients with energy by scale below
`EnergyThreshold`

with 0. A positive
`EnergyThreshold`

prevents the function from
treating wavelet or wavelet packet coefficients with nonsignificant
energy as a sequence with high entropy.

**Data Types: **`single`

| `double`

## Output Arguments

`ent`

— Entropy

scalar | vector

Entropy of `X`

, returned as a scalar or vector.

If

`X`

is time data,`ent`

is a real-valued (*Ns*+1)-by-1 vector of entropy estimates by scale, where*Ns*is the number of scales.If

`X`

is a wavelet or wavelet packet transform input,`ent`

is a real-valued column vector with length equal to the length of`X`

if`X`

is a cell array or the row dimension of`X`

if`X`

is a matrix.

See `Distribution`

to obtain global
estimates of the wavelet entropy. The `wentropy`

function
uses the natural logarithm to compute the entropy.

**Data Types: **`single`

| `double`

`re`

— Relative wavelet energy

vector | matrix

Relative wavelet energy, returned as a vector or matrix.

If

, the function returns the relative wavelet energies by coefficient and scale.`Distribution`

="scale"If

, the function returns the relative wavelet energies by scale.`Distribution`

="global"

Scales where the coefficient energy is below the value of
`EnergyThreshold`

are equal to 0.

**Data Types: **`single`

| `double`

## More About

### Wavelet Entropy

Wavelet entropy (WE) is often used to analyze nonstationary signals. WE combines a
wavelet or wavelet decomposition with a measure of order within the wavelet
coefficients by scale. These measures of order are referred to as *entropy
measures*. WE treats the normalized wavelet coefficients as an
empirical probability distribution and calculates its entropy.

You can normalize the wavelet coefficients *wt* in one of two ways.

The function normalizes all the coefficients by the total sum of their squared magnitudes: $$E={\displaystyle \sum _{i}{\displaystyle \sum _{j}|}}w{t}_{ij}{|}^{2},$$where

*j*corresponds to time, and*i*corresponds to scale. The probability mass function is: $$\mathbb{P}\left(w{t}_{ij}\right)=|w{t}_{ij}{|}^{2}/E.$$The function normalizes the coefficients at each scale separately by the sum of their squared magnitudes: $${E}_{i}={\displaystyle \sum _{j}|}w{t}_{ij}{|}^{2}.$$ The probability mass function is: $$\mathbb{P}\left(w{t}_{ij}\right)=|w{t}_{ij}{|}^{2}/{E}_{i}.$$

The `wentropy`

function supports three entropy measures.

**Shannon Entropy**For a discrete random variable

`X`

, the Shannon entropy is defined as:$$H(X)=-{\displaystyle \sum _{i}\mathbb{P}}(X={x}_{i})\mathrm{ln}(\mathbb{P}(X={x}_{i})),$$

where the sum is taken over all values that the random variable can take. By convention, 0 ln(0) = 0.

**Renyi Entropy**The Renyi entropy is defined as:

$${H}_{r}(X)=\frac{1}{1-\alpha}\text{ln}\left({\displaystyle \sum _{i}{\left(\mathbb{P}(X={x}_{i})\right)}^{\alpha}}\right),\text{\hspace{1em}}\alpha \ge \text{0}\text{.}$$

In the limit, the Renyi entropy becomes the Shannon entropy: $$\underset{\alpha \to 1}{\mathrm{lim}}{H}_{r}(X)=H(X).$$

**Tsallis Entropy**The Tsallis entropy is defined as:

$${H}_{t}(X)=\frac{1}{q-1}\left(1-{\displaystyle \sum _{i}{\left(\mathbb{P}(X={x}_{i})\right)}^{q}}\right),\text{\hspace{1em}}q\in \mathbb{R},\text{\hspace{1em}}q\ne 1.$$

Similar to the Renyi entropy, in the limit, the Tsallis entropy becomes the Shannon entropy: $$\underset{q\to 1}{\mathrm{lim}}{H}_{t}(X)=H(X).$$

## References

[1] Zunino, L., D.G. Pérez, M.
Garavaglia, and O.A. Rosso. “Wavelet Entropy of Stochastic Processes.”
*Physica A: Statistical Mechanics and Its Applications* 379,
no. 2 (June 2007): 503–12. https://doi.org/10.1016/j.physa.2006.12.057.

[2] Rosso, Osvaldo A., Susana
Blanco, Juliana Yordanova, Vasil Kolev, Alejandra Figliola, Martin Schürmann, and Erol
Başar. “Wavelet Entropy: A New Tool for Analysis of Short Duration Brain Electrical
Signals.” *Journal of Neuroscience Methods* 105, no. 1 (January
2001): 65–75. https://doi.org/10.1016/S0165-0270(00)00356-3.

[3] Alcaraz, Raúl, ed. "Wavelet
Entropy: Computation and Applications." Special issue, *Entropy* 17
(2015).
https://www.mdpi.com/journal/entropy/special_issues/wavelet-entropy.

## Version History

**Introduced before R2006a**

### R2022b: `wentropy`

input syntax has changed

The syntax used in the old version of `wentropy`

continues to
work, but is no longer recommended. The old version provides you minimal control
over how to estimate the entropy. The `wentropy`

function
automatically determines from the input syntax which version to use.

You can specify the Shannon entropy in both versions of
`wentropy`

. However, because the old version makes no
assumptions about the input data, reproducing the same results as the new version
can require extensive effort.

Old Version | New Version |
---|---|

load wecg n = numel(wecg); lev = 3; wt = modwt(wecg,lev); energy = sum(abs(wt).^2,2); wt2 = abs(wt)./sqrt(energy); ent = zeros(lev+1,1); for k=1:lev+1 ent(k) = wentropy(wt2(k,:),'shannon')/log(n); end ent ent = 0.3925 0.6512 0.6985 0.9329 |
```
load wecg
ent = wentropy(wecg,Level=3)
``` ent = 0.3925 0.6512 0.6985 0.9329 |

## MATLAB 명령

다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.

명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.

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