EMD

Empirical Mode Decomposition (EMD) is an iterative procedure which decomposes signal into a set of oscillatory components, called Intrisic Mode Functions (IMFs).

class PyEMD.EMD(spline_kind: str = 'cubic', nbsym: int = 2, **kwargs)[source]

Empirical Mode Decomposition

Method of decomposing signal into Intrinsic Mode Functions (IMFs) based on algorithm presented in Huang et al. [Huang1998].

Algorithm was validated with Rilling et al. [Rilling2003] Matlab’s version from 3.2007.

Threshold which control the goodness of the decomposition:
  • std_thr — Test for the proto-IMF how variance changes between siftings.

  • svar_thr – Test for the proto-IMF how energy changes between siftings.

  • total_power_thr — Test for the whole decomp how much of energy is solved.

  • range_thr — Test for the whole decomp whether the difference is tiny.

References

[Huang1998]

N. E. Huang et al., “The empirical mode decomposition and the Hilbert spectrum for non-linear and non stationary time series analysis”, Proc. Royal Soc. London A, Vol. 454, pp. 903-995, 1998

[Rilling2003]

G. Rilling, P. Flandrin and P. Goncalves, “On Empirical Mode Decomposition and its algorithms”, IEEE-EURASIP Workshop on Nonlinear Signal and Image Processing NSIP-03, Grado (I), June 2003

Examples

>>> import numpy as np
>>> T = np.linspace(0, 1, 100)
>>> S = np.sin(2*2*np.pi*T)
>>> emd = EMD(extrema_detection='parabol')
>>> IMFs = emd.emd(S)
>>> IMFs.shape
(1, 100)
__call__(S: ndarray, T: ndarray | None = None, max_imf: int = -1) ndarray[source]

Call self as a function.

__init__(spline_kind: str = 'cubic', nbsym: int = 2, **kwargs)[source]

Initiate EMD instance.

Configuration, such as threshold values, can be passed as kwargs (keyword arguments).

Parameters:
FIXEint (default: 0)
FIXE_Hint (default: 0)
MAX_ITERATIONint (default 1000)

Maximum number of iterations per single sifting in EMD.

energy_ratio_thrfloat (default: 0.2)

Threshold value on energy ratio per IMF check.

std_thr float(default 0.2)

Threshold value on standard deviation per IMF check.

svar_thr float(default 0.001)

Threshold value on scaled variance per IMF check.

total_power_thrfloat (default 0.005)

Threshold value on total power per EMD decomposition.

range_thrfloat (default 0.001)

Threshold for amplitude range (after scaling) per EMD decomposition.

extrema_detectionstr (default ‘simple’)

Method used to finding extrema.

DTYPEnp.dtype (default np.float64)

Data type used.

Examples

>>> emd = EMD(std_thr=0.01, range_thr=0.05)
__weakref__

list of weak references to the object (if defined)

check_imf(imf_new: ndarray, imf_old: ndarray, eMax: ndarray, eMin: ndarray) bool[source]

Huang criteria for IMF (similar to Cauchy convergence test). Signal is an IMF if consecutive siftings do not affect signal in a significant manner.

emd(S: ndarray, T: ndarray | None = None, max_imf: int = -1) ndarray[source]

Performs Empirical Mode Decomposition on signal S. The decomposition is limited to max_imf imfs. Returns IMF functions and residue in a single numpy array format.

Parameters:
Snumpy array,

Input signal.

Tnumpy array, (default: None)

Position or time array. If None is passed or self.extrema_detection == “simple”, then numpy range is created.

max_imfint, (default: -1)

IMF number to which decomposition should be performed. Negative value means all.

Returns:
IMFs and residuenumpy array

A numpy array which cointains both the IMFs and residual, if any, appended as the last slice.

end_condition(S: ndarray, IMF: ndarray) bool[source]

Tests for end condition of whole EMD. The procedure will stop if:

  • Absolute amplitude (max - min) is below range_thr threshold, or

  • Metric L1 (mean absolute difference) is below total_power_thr threshold.

Parameters:
Snumpy array

Original signal on which EMD was performed.

IMFnumpy 2D array

Set of IMFs where each row is IMF. Their order is not important.

Returns:
endbool

Whether sifting is finished.

extract_max_min_spline(T: ndarray, S: ndarray) Tuple[ndarray, ndarray, ndarray, ndarray][source]

Extracts top and bottom envelopes based on the signal, which are constructed based on maxima and minima, respectively.

Parameters:
Tnumpy array

Position or time array.

Snumpy array

Input data S(T).

Returns:
max_splinenumpy array

Spline spanned on S maxima.

min_splinenumpy array

Spline spanned on S minima.

max_extremanumpy array

Points indicating local maxima.

min_extremanumpy array

Points indicating local minima.

find_extrema(T: ndarray, S: ndarray) Tuple[ndarray, ndarray, ndarray, ndarray, ndarray][source]

Returns extrema (minima and maxima) for given signal S. Detection and definition of the extrema depends on extrema_detection variable, set on initiation of EMD.

Parameters:
Tnumpy array

Position or time array.

Snumpy array

Input data S(T).

Returns:
local_max_posnumpy array

Position of local maxima.

local_max_valnumpy array

Values of local maxima.

local_min_posnumpy array

Position of local minima.

local_min_valnumpy array

Values of local minima.

get_imfs_and_residue() Tuple[ndarray, ndarray][source]

Provides access to separated imfs and residue from recently analysed signal.

Returns:
imfsnp.ndarray

Obtained IMFs

residuenp.ndarray

Residue.

get_imfs_and_trend() Tuple[ndarray, ndarray][source]

Provides access to separated imfs and trend from recently analysed signal. Note that this may differ from the get_imfs_and_residue as the trend isn’t necessarily the residue. Residue is a point-wise difference between input signal and all obtained components, whereas trend is the slowest component (can be zero).

Returns:
imfsnp.ndarray

Obtained IMFs

trendnp.ndarray

The main trend.

prepare_points(T: ndarray, S: ndarray, max_pos: ndarray, max_val: ndarray, min_pos: ndarray, min_val: ndarray)[source]

Performs extrapolation on edges by adding extra extrema, also known as mirroring signal. The number of added points depends on nbsym variable.

Parameters:
Tnumpy array

Position or time array.

Snumpy array

Input signal.

max_positerable

Sorted time positions of maxima.

max_valiterable

Signal values at max_pos positions.

min_positerable

Sorted time positions of minima.

min_valiterable

Signal values at min_pos positions.

Returns:
max_extremanumpy array (2 rows)

Position (1st row) and values (2nd row) of minima.

min_extremanumpy array (2 rows)

Position (1st row) and values (2nd row) of maxima.

spline_points(T: ndarray, extrema: ndarray) Tuple[ndarray, ndarray][source]

Constructs spline over given points.

Parameters:
Tnumpy array

Position or time array.

extremanumpy array

Position (1st row) and values (2nd row) of points.

Returns:
Tnumpy array

Position array (same as input).

splinenumpy array

Spline array over given positions T.