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: numpy.ndarray, T: Optional[numpy.ndarray] = None, max_imf: int = -1) → numpy.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:
FIXE : int (default: 0)
FIXE_H : int (default: 0)
MAX_ITERATION : int (default 1000)

Maximum number of iterations per single sifting in EMD.

energy_ratio_thr : float (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_thr : float (default 0.005)

Threshold value on total power per EMD decomposition.

range_thr : float (default 0.001)

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

extrema_detection : str (default ‘simple’)

Method used to finding extrema.

DTYPE : np.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: numpy.ndarray, imf_old: numpy.ndarray, eMax: numpy.ndarray, eMin: numpy.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: numpy.ndarray, T: Optional[numpy.ndarray] = None, max_imf: int = -1) → numpy.ndarray[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 is passed or self.extrema_detection == “simple”, then numpy range 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(S: numpy.ndarray, IMF: numpy.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:
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(T: numpy.ndarray, S: numpy.ndarray) → Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray][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.

max_extrema : numpy array

Points indicating local maxima.

min_extrema : numpy array

Points indicating local minima.

find_extrema(T: numpy.ndarray, S: numpy.ndarray) → Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.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:
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() → Tuple[numpy.ndarray, numpy.ndarray][source]

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

Returns:
imfs : np.ndarray

Obtained IMFs

residue : np.ndarray

Residue.

get_imfs_and_trend() → Tuple[numpy.ndarray, numpy.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:
imfs : np.ndarray

Obtained IMFs

trend : np.ndarray

The main trend.

prepare_points(T: numpy.ndarray, S: numpy.ndarray, max_pos: numpy.ndarray, max_val: numpy.ndarray, min_pos: numpy.ndarray, min_val: numpy.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:
T : numpy array

Position or time array.

S : numpy array

Input signal.

max_pos : iterable

Sorted time positions of maxima.

max_val : 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:
max_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(T: numpy.ndarray, extrema: numpy.ndarray) → Tuple[numpy.ndarray, numpy.ndarray][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.