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='cubic', nbsym=2, **config)[source]

Empirical Mode Decomposition

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

Algorithm was validated with Rilling et al. [R7d832100fd35-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.
Parameters:
spline_kind : string, (default: ‘cubic’)

Defines type of spline, which connects extrema. Possible: cubic, akima, slinear.

nbsym : int, (default: 2)

Number of extrema used in boundary mirroring.

extrema_detection : string, (default: ‘simple’)

How extrema are defined.

  • simple - Extremum is above/below neighbours.
  • parabol - Extremum is a peak of a parabola.

References

[R7d832100fd35-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
[R7d832100fd35-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()
>>> emd.extrema_detection = "parabol"
>>> IMFs = emd.emd(S)
>>> IMFs.shape
(1, 100)
__init__(self, spline_kind='cubic', nbsym=2, **config)[source]

Initiate EMD instance.

Configuration, such as threshold values can be passed as config.

>>> config = {"std_thr": 0.01, "range_thr": 0.05}
>>> emd = EMD(**config)
check_imf(self, imf_new, imf_old, eMax, eMin)[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(self, S, T=None, max_imf=-1)[source]

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

Parameters:
S : numpy array,

Input signal.

T : numpy array, (default: None)

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

max_imf : int, (default: -1)

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

Returns:
IMF : numpy array

Set of IMFs produced from input signal.

end_condition(self, S, IMF)[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:
S : numpy array

Original signal on which EMD was performed.

IMF : numpy 2D array

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

Returns:
end : bool

Whether sifting is finished.

extract_max_min_spline(self, T, S)[source]

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

Parameters:
T : numpy array

Position or time array.

S : numpy array

Input data S(T).

Returns:
max_spline : numpy array

Spline spanned on S maxima.

min_spline : numpy array

Spline spanned on S minima.

find_extrema(self, T, S)[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:
T : numpy array

Position or time array.

S : numpy array

Input data S(T).

Returns:
local_max_pos : numpy array

Position of local maxima.

local_max_val : numpy array

Values of local maxima.

local_min_pos : numpy array

Position of local minima.

local_min_val : numpy array

Values of local minima.

get_imfs_and_residue(self)[source]

Provides access to separated imfs and residue from recently analysed signal. :return: (imfs, residue)

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

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

Parameters:
S : numpy array

Input signal.

T : numpy array

Position or time array.

max_pos : iterable

Sorted time positions of maxima.

max_vali : iterable

Signal values at max_pos positions.

min_pos : iterable

Sorted time positions of minima.

min_val : iterable

Signal values at min_pos positions.

Returns:
min_extrema : numpy array (2 rows)

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

min_extrema : numpy array (2 rows)

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

spline_points(self, T, extrema)[source]

Constructs spline over given points.

Parameters:
T : numpy array

Position or time array.

extrema : numpy array

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

Returns:
T : numpy array

Position array (same as input).

spline : numpy array

Spline array over given positions T.