pysdkit.emd#
Created on 2025/02/03 18:36:18 @author: Whenxuan Wang @email: wwhenxuan@gmail.com
Created on Sat Mar 5 22:09:45 2024 @author: Whenxuan Wang @email: wwhenxuan@gmail.com The following code is mainly used to find extreme points in the EMD algorithm |
|
Created on Sat Mar 5 21:38:26 2024 @author: Whenxuan Wang @email: wwhenxuan@gmail.com The following code is mainly used to find extreme points in the EMD algorithm |
|
Created on Sat Mar 4 21:58:54 2024 @author: Whenxuan Wang @email: wwhenxuan@gmail.com |
|
Created on 2025/02/03 18:36:18 @author: Whenxuan Wang @email: wwhenxuan@gmail.com Code taken from laszukdawid/PyEMD |
|
Created on 2025/02/04 15:19:08 @author: Whenxuan Wang @email: wwhenxuan@gmail.com |
|
Created on 2025/02/05 13:15:49 @author: Whenxuan Wang @email: wwhenxuan@gmail.com |
|
Created on 2025/02/04 13:10:33 @author: Whenxuan Wang @email: wwhenxuan@gmail.com We refactored from mariogrune/MEMD-Python- |
|
Created on 2025/02/01 22:06:04 @author: Whenxuan Wang @email: wwhenxuan@gmail.com |
emd._splines#
Created on Sat Mar 5 22:09:45 2024 @author: Whenxuan Wang @email: wwhenxuan@gmail.com The following code is mainly used to find extreme points in the EMD algorithm
- pysdkit._emd._splines.akima(X, Y, x)[source]#
Akima Interpolation.
This function uses the Akima interpolation method to interpolate values at specified points x.
Akima interpolation is known for its smoothness and is suitable for curves with rapid changes.
- Parameters:
X – Array-like, the x-coordinates of the data points.
Y – Array-like, the y-coordinates of the data points.
x – Array-like, the x-coordinates where interpolation is desired.
- Returns:
Array-like, the interpolated y-coordinates.
- pysdkit._emd._splines.cubic(X, Y, x)[source]#
Cubic Spline Interpolation.
This function uses the Cubic Spline interpolation method to interpolate values at specified points x.
Cubic Spline interpolation ensures that the second derivatives are continuous, resulting in a smooth curve.
- Parameters:
X – Array-like, the x-coordinates of the data points.
Y – Array-like, the y-coordinates of the data points.
- Returns:
Array-like, the interpolated y-coordinates.
- pysdkit._emd._splines.cubic_hermite(X, Y, x)[source]#
Cubic Hermite Spline Interpolation.
This function uses the Cubic Hermite Spline interpolation method to interpolate values at specified points x.
Cubic Hermite Spline interpolation ensures that the first derivatives are continuous.
- Parameters:
X – Array-like, the x-coordinates of the data points.
Y – Array-like, the y-coordinates of the data points.
x – Array-like, the x-coordinates where interpolation is desired.
- Returns:
Array-like, the interpolated y-coordinates.
- pysdkit._emd._splines.cubic_spline_3pts(x, y, T)[source]#
Custom Cubic Spline Interpolation for 3 Data Points. This function implements a cubic spline interpolation specifically for 3 data points. Scipy’s interp1d does not support cubic spline interpolation for less than 4 points. The function calculates the interpolated values at specified points T.
- Parameters:
x – Array-like, the x-coordinates of the 3 data points.
y – Array-like, the y-coordinates of the 3 data points.
T – Array-like, the x-coordinates where interpolation is desired.
- Returns:
Tuple (t, q), where t is the interpolated x-coordinates and q is the interpolated y-coordinates.
- pysdkit._emd._splines.pchip(X, Y, x)[source]#
Piecewise Cubic Hermite Interpolating Polynomial (PCHIP) Interpolation.
This function uses the PCHIP interpolation method to interpolate values at specified points x.
PCHIP interpolation ensures that the interpolated curve is monotonic in regions where the data is monotonic.
- Parameters:
X – Array-like, the x-coordinates of the data points.
Y – Array-like, the y-coordinates of the data points.
x – Array-like, the x-coordinates where interpolation is desired.
- Returns:
Array-like, the interpolated y-coordinates.
emd._find_extrema#
Created on Sat Mar 5 21:38:26 2024 @author: Whenxuan Wang @email: wwhenxuan@gmail.com The following code is mainly used to find extreme points in the EMD algorithm
Code taken from laszukdawid/PyEMD
- pysdkit._emd._find_extrema.find_extrema_parabol(time: ndarray, signal: ndarray) Tuple[ndarray, ndarray, ndarray, ndarray, ndarray][source]#
Performs parabolic estimation of extremum in a one-dimensional signal array S. This method not only identifies the positions and values of local maxima and minima by fitting a parabola to three consecutive points (where the middle point is the vertex of the parabola), but also provides zero crossing points which are essential for signal analysis.
- Parameters:
time – Array representing the time or sequence indices.
signal – One-dimensional array representing the signal values.
- Returns:
Positions and values of local maxima and minima, and positions of zero crossings.
- pysdkit._emd._find_extrema.find_extrema_simple(time: ndarray, signal: ndarray) Tuple[ndarray, ndarray, ndarray, ndarray, ndarray][source]#
Performs extrema detection in a given one-dimensional signal array S. This method identifies local maxima and minima by analyzing the first differences of the signal. The approach is straightforward and computationally efficient, making it suitable for signal processing applications where quick identification of critical turning points in the signal is required.
- Parameters:
time – Array representing the time or sequence indices.
signal – One-dimensional array representing the signal values.
- Returns:
Positions and corresponding values of local maxima and minima, and the positions of zero crossings.
emd._prepare_points#
Created on Sat Mar 8 22:53:11 2024 @author: Whenxuan Wang @email: wwhenxuan@gmail.com The following code is mainly used to Performs extrapolation on edges by adding extra extrema in the EMD algorithm
Code taken from laszukdawid/PyEMD
- pysdkit._emd._prepare_points.prepare_points_parabol(T: ~numpy.ndarray, S: ~numpy.ndarray, max_pos: ~numpy.ndarray, max_val: ~numpy.ndarray, min_pos: ~numpy.ndarray, min_val: ~numpy.ndarray, nbsym: int, DTYPE=<class 'numpy.float64'>) Tuple[ndarray, ndarray][source]#
Performs mirroring on signal which extrema do not necessarily
belong on the position array.
max_pos, max_val: the position and corresponding value of the local maximum. min_pos, min_val: the position and corresponding value of the local minimum.
Used to perform a mirror operation at the extreme points of the signal so that smoother and more complete boundaries can be obtained when constructing the upper and lower envelopes of the signal.
This processing is especially important at the beginning and end edges of the signal, because these areas may lack enough data points to accurately estimate the extreme values.
The mirror operation helps provide enough data points to make interpolation (such as spline interpolation) more accurate and natural.
emd.emd#
Created on Sat Mar 4 21:58:54 2024 @author: Whenxuan Wang @email: wwhenxuan@gmail.com
Code taken from laszukdawid/PyEMD
- class pysdkit._emd.emd.EMD(spline_kind: str = 'cubic', energy_ratio_thr: float | None = 0.2, nbsym: int = 2, std_thr: float | None = 0.2, svar_thr: float | None = 0.001, total_power_thr: float | None = 0.005, range_thr: float | None = 0.001, extrema_detection: str | None = 'simple', max_imfs: int | None = -1, max_iteration: int = 1000, **kwargs)[source]#
Bases:
objectEmpirical Mode Decomposition
Huang, Norden E., et al. “The empirical mode decomposition and the Hilbert spectrum for nonlinear and non-stationary time series analysis.” Proceedings of the Royal Society of London. Series A: mathematical, physical and engineering sciences 454.1971 (1998): 903-995. The algorithm first interpolates the signal extreme values and averages the upper and lower envelopes to obtain the local mean of the signal, which can be regarded as an estimate of the low-frequency components in the signal; then, the low-frequency components are iteratively separated from the input signal to obtain the high-frequency (fast oscillation) components.
This completes a screening. Repeat the screening process until all the main oscillation modes in the input signal are extracted.
Python code: laszukdawid/PyEMD
MATLAB code: https://www.mathworks.com/help/signal/ref/emd.html
R code: https://rdrr.io/github/PierreMasselot/Library–emdr/f/README.md
- __call__(signal, time: ndarray | None = None, max_imfs: int | None = None) ndarray[source]#
allow instances to be called like functions
- __init__(spline_kind: str = 'cubic', energy_ratio_thr: float | None = 0.2, nbsym: int = 2, std_thr: float | None = 0.2, svar_thr: float | None = 0.001, total_power_thr: float | None = 0.005, range_thr: float | None = 0.001, extrema_detection: str | None = 'simple', max_imfs: int | None = -1, max_iteration: int = 1000, **kwargs) None[source]#
Configuration, such as threshold values, can be passed as kwargs (keyword arguments).
- Parameters:
spline_kind – The specific interpolation algorithm used to construct the upper and lower envelope spectra, optional: [akima, cubic, pchip, cubic_hermite, slinear, quadratic, linear]
extrema_detection – method used to finding extrema, choices: [‘parabol’, ‘simple’]
nbsym
max_imfs – maximum number of the IMFs to be decomposed
max_iteration – maximum number of iterations per single sifting in EMD
std_thr – threshold value on standard deviation per IMF check
svar_thr – threshold value on scaled variance per IMF check
total_power_thr – threshold value on total power per EMD decomposition
range_thr – threshold for amplitude range (after scaling) per EMD decomposition
energy_ratio_thr – threshold value on energy ratio per IMF check
kwargs – other parameters passed to EMD
- __module__ = 'pysdkit._emd.emd'#
- __weakref__#
list of weak references to the object (if defined)
- static _check_length(signal: ndarray, time: ndarray | None = None)[source]#
Check input timing and signal length are equal
- static _check_shape(signal: ndarray, time: ndarray) None[source]#
Check input timing and signal shape are equal
- check_imf(imf_new: ndarray, imf_old: ndarray, eMax: ndarray, eMin: ndarray) bool[source]#
Evaluate if the current IMF (Intrinsic Mode Function) satisfies the end condition based on Huang’s criteria, similar to the Cauchy convergence test.
This function ensures that consecutive siftings of the signal have minimal impact, indicating that the IMF component has been properly extracted. The criteria include checking if all local maxima are positive, all local minima are negative, and various convergence tests based on the differences between consecutive IMFs.
- Parameters:
imf_new – np.ndarray - the newly extracted IMF in the current iteration.
imf_old – np.ndarray - the previously extracted IMF from the last iteration.
eMax – np.ndarray - array of values at local maxima points, used for validation.
eMin – np.ndarray - array of values at local minima points, used for validation.
- Returns:
True if the current IMF meets the stopping criteria, False otherwise.
- Return type:
bool
- end_condition(signal: ndarray, IMF: ndarray) bool[source]#
Evaluate whether the Empirical Mode Decomposition (EMD) process should terminate.
The process stops when either the absolute amplitude of the residue is below a threshold or the mean absolute difference of the residue is below another threshold.
This function ensures that the decomposition stops when further significant intrinsic mode functions (IMFs) cannot be extracted reliably due to the minimal variation in the remaining signal.
- Parameters:
signal – np.ndarray - The original signal on which EMD was performed.
IMF – np.ndarray - A 2D array containing all extracted IMFs, where each row represents an IMF.
- Returns:
True if the EMD process should terminate, False otherwise.
- Return type:
bool
- extract_max_min_spline(time: ndarray, signal: ndarray) list[int] | tuple[ndarray, ndarray, ndarray, ndarray][source]#
Extracts top and bottom envelopes based on the signal, which are constructed based on maxima and minima, respectively. Based on the local maximum and minimum values of the signal, the upper envelope and the lower envelope are constructed.
This method is one of the key steps in constructing IMF, because IMF is obtained by the difference between the original signal and its mean.
- Parameters:
time – position or time array of numpy
signal – input signal of numpy ndarray
- 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
- find_extrema(time: ndarray, signal: 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_detectionvariable, set on initiation of EMD.- Parameters:
time – position or time array of numpy
signal – input signal of numpy ndarray
- 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
- fit_transform(signal: ndarray, time: ndarray | None = None, max_imfs: int | None = None) ndarray[source]#
Signal decomposition using EMD algorithm
- Parameters:
signal – the time domain signal (1D numpy array) to be decomposed
time – the time array of the input signal
max_imfs – the maximum number of IMFs to extract
- Returns:
the decomposed results of IMFs
- get_imfs_and_residue() Tuple[ndarray, ndarray][source]#
Provides access to separated imfs and residue from recently analysed signal
- Returns:
obtained IMFs and residue through EMD
- 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:
obtained IMFs and main trend through EMD
- prepare_points(time: ndarray, signal: ndarray, max_pos: ndarray, max_val: ndarray, min_pos: ndarray, min_val: ndarray) Tuple[ndarray, ndarray][source]#
Further processing of the maximum and minimum points of the input signal makes the upper and lower envelope spectra smoother.
- Parameters:
time – position or time array of numpy
signal – input signal of numpy ndarray
max_pos – numpy array, Position of local maxima.
max_val – numpy array, Values of local maxima
min_pos – numpy array, Position of local minima
min_val – numpy array, Values of local minima
- Returns:
max_extrema and min_extrema for input signal in numpy ndarray
- spline_points(time: ndarray, extrema: ndarray) Tuple[ndarray, ndarray][source]#
Constructs spline over given points. Generates spline curves using different interpolation methods (depending on the spline_kind parameter) for given extreme points. These curves are used as the upper and lower envelopes of the signal.
- Parameters:
time – position or time array of numpy
extrema – the max_extrema and min_extrema for input signal in numpy ndarray
- Returns:
spline_points array of numpy ndarray
emd.eemd#
Created on 2025/02/03 18:36:18 @author: Whenxuan Wang @email: wwhenxuan@gmail.com Code taken from laszukdawid/PyEMD
- class pysdkit._emd.eemd.EEMD(ext_EMD=None, trials: int = 100, noise_width: float = 0.05, parallel: bool = False, separate_trends: bool = False, noise_kind: str | None = 'normal', processes: int | None = None, max_imfs: int | None = -1, max_iter: int | None = 1000, random_seed: int | None = 42)[source]#
Bases:
objectEnsemble Empirical Mode Decomposition
Ensemble empirical mode decomposition (EEMD) [Wu2009] is noise-assisted technique, which is meant to be more robust than simple Empirical Mode Decomposition (EMD). The robustness is checked by performing many decompositions on signals slightly perturbed from their initial position. In the grand average over all IMF results the noise will cancel each other out and the result is pure decomposition. Wu, Zhaohua, and Norden E. Huang. “Ensemble empirical mode decomposition: a noise-assisted data analysis method.” Advances in adaptive data analysis 1.01 (2009): 1-41.
Python code: laszukdawid/PyEMD
MATLAB code: https://www.mathworks.com/help/signal/ref/emd.html
- __call__(signal: ndarray, time: ndarray | None = None, max_imfs: int | None = None, progress: bool | None = False) ndarray[source]#
allow instances to be called like functions
- __init__(ext_EMD=None, trials: int = 100, noise_width: float = 0.05, parallel: bool = False, separate_trends: bool = False, noise_kind: str | None = 'normal', processes: int | None = None, max_imfs: int | None = -1, max_iter: int | None = 1000, random_seed: int | None = 42) None[source]#
- Parameters:
ext_EMD – pre-defined EMD algorithms to be integrated
trials – number of trials or EMD performance with added noise
noise_width – standard deviation of Gaussian noise
parallel – flag whether to use multiprocessing in EEMD execution. Since each EMD(s+noise) is independent this should improve execution speed considerably. Note that it’s disabled by default because it’s the most common problem when EEMD takes too long time to finish. if you set the flag to True, make also sure to set processes to some reasonable value.
separate_trends – Number of processes harness when executing in parallel mode. The value should be between 1 and max that depends on your hardware.
noise_kind – the specific type of noise the algorithm handles, choices: [“normal”, “uniform”]
processes – the number of multiple processes
max_imfs – the maximum number of imf functions to be decomposed -1 means to decompose as many imf functions as possible
max_iter – maximum number of decomposition iterations
random_seed – create a random seed for the random number generator
- __module__ = 'pysdkit._emd.eemd'#
- __weakref__#
list of weak references to the object (if defined)
- _run_emd(signal: ndarray, time: ndarray, max_imfs: int | None = -1) ndarray[source]#
Vanilla Empirical Mode Decomposition method
Perform the specified EMD algorithm to obtain the corresponding signal decomposition results
- _update_trial(trial) Tuple[ndarray, ndarray | None][source]#
A single trial evaluation, i.e., EMD(signal + noise).
Note: Although the trial argument isn’t used, it’s needed for the (multiprocessing) map method.
- property all_imfs: Dict#
A dictionary with all computed IMFs per given order.
- ensemble_count() List[int][source]#
Count of IMFs observed for a given order, e.g., the 1st proto-IMF, in the entire ensemble.
- ensemble_mean() ndarray[source]#
Integrate the results of the ensemble EMD algorithm to obtain the mean result.
- fit_transform(signal: ndarray, time: ndarray | None = None, max_imfs: int | None = None, progress: bool | None = False) ndarray[source]#
Perform Ensemble Empirical Mode Decomposition for the input signal
- Parameters:
signal – input ndarray signal to be decomposed
time – time array for the signal
max_imfs – The number of imf decomposed
progress – the number of multiple processes
- Returns:
Set of ensemble IMFs produced from input signal of ndarray
In general, these do not have to be, and most likely will not be, same as IMFs produced using EMD
- generate_noise(scale: float, size: int | Sequence[int]) ndarray[source]#
Generate noise with specified standard deviation and size.
The choice of noise is in [“normal”, “uniform”], where normal has a standard deviation equal to scale and uniform has a range of [-scale / 2, scale / 2].
- Parameters:
scale – The width for the noise distribution.
size – The size of the noise ndarray.
- Returns:
The generated white noise ndarray.
- get_imfs_and_residue() Tuple[ndarray, ndarray][source]#
Provides access to separated imfs and residue from recently analysed signal
- Returns:
obtained IMFs and residue through EMD
- 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:
obtained IMFs and main trend through EMD
emd.ceemdan#
Created on 2025/02/04 15:19:08 @author: Whenxuan Wang @email: wwhenxuan@gmail.com
- class pysdkit._emd.ceemdan.CEEMDAN(ext_EMD=None, max_imfs: int = -1, trials: int = 100, epsilon: float = 0.005, parallel: bool = False, noise_scale: float = 1.0, noise_kind: str | None = 'normal', range_thr: float | None = 0.01, total_power_thr: float | None = 0.05, beta_progress: bool | None = True, processes: int | None = None, max_iter: int | None = 1000, random_seed: int | None = 42)[source]#
Bases:
objectComplete Ensemble Empirical Mode Decomposition with Adaptive Noise
M. E. Torres, M. A. Colominas, G. Schlotthauer and P. Flandrin, “A complete ensemble empirical mode decomposition with adaptive noise,” 2011 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP),
M.A. Colominas, G. Schlotthauer, M.E. Torres, Improved complete ensemble EMD: A suitable tool for biomedical signal processing, In Biomed. Sig. Proc. and Control, V. 14, 2014, pp. 19–29 Prague, Czech Republic, 2011, pp. 4144-4147, doi: 10.1109/ICASSP.2011.5947265.
Python code: mariogrune/MEMD-Python-
MATLAB code: http://www.commsp.ee.ic.ac.uk/~mandic/research/emd.htm
Word “complete” presumably refers to decomposing completely everything, even added perturbation (noise).
- __call__(signal: ndarray, time: ndarray | None = None, max_imfs: int | None = None, progress: bool = False) ndarray[source]#
allow instances to be called like functions
- __init__(ext_EMD=None, max_imfs: int = -1, trials: int = 100, epsilon: float = 0.005, parallel: bool = False, noise_scale: float = 1.0, noise_kind: str | None = 'normal', range_thr: float | None = 0.01, total_power_thr: float | None = 0.05, beta_progress: bool | None = True, processes: int | None = None, max_iter: int | None = 1000, random_seed: int | None = 42) None[source]#
- Parameters:
ext_EMD – pre-defined EMD algorithms to be integrated
max_imfs – the maximum number of imf functions to be decomposed -1 means to decompose as many imf functions as possible
trials – number of trials or EMD performance with added noise
epsilon – scale for added noise
parallel – flag whether to use multiprocessing in EEMD execution. Since each EMD(s+noise) is independent this should improve execution speed considerably. Note that it’s disabled by default because it’s the most common problem when EEMD takes too long time to finish. if you set the flag to True, make also sure to set processes to some reasonable value.
noise_scale – scale (amplitude) of the added noise
noise_kind – the type of noise to add. Allowed are “normal” (default) and “uniform”
range_thr – Range threshold used as an IMF check. The value is in percentage compared to initial signal’s amplitude. If absolute amplitude (max - min) is below the range_thr then the decomposition is finished.
total_power_thr – signal’s power threshold. Finishes decomposition if sum(abs(r)) < thr.
beta_progress – flag whether to scale all noise IMFs by their 1st IMF’s standard deviation
processes – the number of multiple processes
max_iter – maximum number of decomposition iterations
random_seed – create a random seed for the random number generator
- __module__ = 'pysdkit._emd.ceemdan'#
- __weakref__#
list of weak references to the object (if defined)
- _generate_noise(scale: float, size: int | Sequence[int]) ndarray[source]#
Generate noise with specified standard deviation and size.
The choice of noise is in [“normal”, “uniform”], where normal has a standard deviation equal to scale and uniform has a range of [-scale / 2, scale / 2].
- Parameters:
scale – The width for the noise distribution.
size – The size of the noise ndarray.
- Returns:
The generated white noise ndarray.
- _run_eemd(signal: ndarray, time: ndarray | None = None, max_imfs: int | None = None, progress: bool | None = True) ndarray[source]#
Perform the specified EEMD algorithm to obtain the corresponding signal decomposition results.
- _run_emd(signal: ndarray, time: ndarray | None = None, max_imfs: int | None = None) ndarray[source]#
Vanilla Empirical Mode Decomposition method.
- Parameters:
signal – the input 1D ndarray signal.
time – the time array.
max_imfs – the maximum number of IMFs to be decomposed.
- Returns:
the decomposed IMFs of the input signal.
- end_condition(signal: ndarray, cIMFs: ndarray, max_imf: int) bool[source]#
Test for end condition for CEEMDAN method.
Procedure stops if: * number of components reaches provided max_imf, or * residue has insufficient extrema for further decomposition, or * residue amplitude range falls below range_thr, or * residue total power falls below total_power_thr.
- Parameters:
signal – the original input signal as a numpy ndarray
cIMFs – the signal decomposition results
max_imf – the maximum number of IMFs to extract (-1 means no limit)
- Returns:
a boolean stop flag indicating whether to stop the CEEMDAN method
- fit_transform(signal: ndarray, time: ndarray | None = None, max_imfs: int | None = None, progress: bool = False) ndarray[source]#
Perform the CEEMDAN method for signal decomposition.
- Parameters:
signal – the original signal on which CEEMDAN is to be performed
time – the time array of the original input signal
max_imfs – the maximum number of components to extract (-1 for no limit)
progress – whether to print out ‘.’ every 1s to indicate progress
- Returns:
the intrinsic mode functions (IMFs) after signal decomposition
- get_imfs_and_residue() Tuple[ndarray, ndarray][source]#
Provides access to separated imfs and residue from recently analysed signal
- Returns:
obtained IMFs and residue through EMD
- 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:
obtained IMFs and main trend through EMD
emd.remd#
Created on 2025/02/05 13:15:49 @author: Whenxuan Wang @email: wwhenxuan@gmail.com
- class pysdkit._emd.remd.REMD(max_imfs: int = 3, max_iter: int | None = 32, nbsym: int = 2, ssc: str | None = 'liu', extrema_detection: str | None = 'simple', spline_kind: str | None = 'cubic', ext_ratio: float | None = 0.2)[source]#
Bases:
objectRobust Empirical Mode Decomposition
A useful adaptive signal processing tool for multi-component signal separation, non-stationary signal processing.
The REMD is an improved empirical mode decomposition powered by soft sifting stopping criterion (SSSC). The SSSC is an adaptive sifting stop criterion to stop the sifting process automatically for the EMD. It extracts a set of mono-component signals (called intrinsic mode functions) from a temporal mixed signal. It can be used together with Hilbert transform (or other demodulation techniques) for advanced time-frequency analysis.
Dandan Peng, Zhiliang Liu, Yaqiang Jin, Yong Qin. Improved EMD with a Soft Sifting Stopping Criterion and Its Application to Fault Diagnosis of Rotating Machinery. Journal of Mechanical Engineering. Accepted on Jan. 01, 2019.
Zhiliang Liu*, Dandan Peng, Ming J. Zuo, Jiansuo Xia, and Yong Qin. Improved Hilbert-Huang transform with soft sifting stopping criterion and its application to fault diagnosis of wheelset bearings. ISA Transactions. 125: 426-444, 2022.
MATLAB code: https://www.mathworks.com/matlabcentral/fileexchange/70032-robust-empirical-mode-decomposition-remd
- __init__(max_imfs: int = 3, max_iter: int | None = 32, nbsym: int = 2, ssc: str | None = 'liu', extrema_detection: str | None = 'simple', spline_kind: str | None = 'cubic', ext_ratio: float | None = 0.2) None[source]#
Initialize REMD parameters. A useful adaptive signal processing tool for multi-component signal separation, non-stationary signal processing.
- Parameters:
max_imfs – max number of imf to be decomposed
max_iter – max iteration number in a IMF sifting process
nbsym
ssc – sifting stopping criterion
extrema_detection – method used to finding extrema, choices: [‘parabol’, ‘simple’]
spline_kind – The specific interpolation algorithm used to construct the upper and lower envelope spectra, optional: [akima, cubic, pchip, cubic_hermite, slinear, quadratic, linear]
ext_ratio
- __module__ = 'pysdkit._emd.remd'#
- __weakref__#
list of weak references to the object (if defined)
- _emd_mean(time: ndarray, signal: ndarray) Tuple[ndarray, int][source]#
Get the mean of the upper and lower envelope spectra and the number of all extreme points
- extend(signal: ndarray, indmin: ndarray, indmax: ndarray) Tuple[ndarray, ndarray, ndarray, ndarray][source]#
Extend original data to refrain end effect Modified on _emd by G.Rilling and P.Flandrin https://perso.ens-lyon.fr/patrick.flandrin/emd.html
- Parameters:
signal – Input signal to be processed
indmin – The position array of the maximum points of the input signal
indmax – An array of positions of the minimum points of the input signal
- extr(time: ndarray, signal: ndarray) Tuple[ndarray, ndarray, ndarray, ndarray, ndarray][source]#
Extracts the indices of extrema for the input signal Copied from _emd toolbox by G.Rilling and P.Flandrin https://perso.ens-lyon.fr/patrick.flandrin/emd.html
- fit_transform(signal: ndarray) ndarray[source]#
Start executing the REMD algorithm according to the input parameters :param signal: The input 1D signal of ndarray to be decomposed :return: the Intrinsic Mode Function of the input signal
- init_imfs(seq_len: int) Tuple[ndarray, ndarray, ndarray][source]#
The IMFs obtained from the initial decomposition and the variables recording the decomposition process
- is_sifting_process_stop(time, m, s, j, fv_i) Tuple[bool, ndarray][source]#
sifting stopping criterion
- prepare_points(time: ndarray, signal: ndarray, max_pos: ndarray, max_val: ndarray, min_pos: ndarray, min_val: ndarray) Tuple[ndarray, ndarray][source]#
Further processing of the maximum and minimum points of the input signal makes the upper and lower envelope spectra smoother. :param time: position or time array of numpy :param signal: input signal of numpy ndarray :param max_pos: numpy array, Position of local maxima. :param max_val: numpy array, Values of local maxima :param min_pos: numpy array, Position of local minima :param min_val: numpy array, Values of local minima :return: max_extrema and min_extrema for input signal in numpy ndarray
- spline_points(time: ndarray, extrema: ndarray) Tuple[ndarray, ndarray][source]#
Constructs spline over given points. Generates spline curves using different interpolation methods (depending on the spline_kind parameter) for given extreme points. These curves are used as the upper and lower envelopes of the signal.
- Parameters:
time – position or time array of numpy
extrema – the max_extrema and min_extrema for input signal in numpy ndarray
- Returns:
spline_points array of numpy ndarray
emd.memed#
Created on 2025/02/04 13:10:33 @author: Whenxuan Wang @email: wwhenxuan@gmail.com We refactored from mariogrune/MEMD-Python-
- class pysdkit._emd.memd.MEMD(stop_crit: str | None = 'stop', max_iter: int | None = 128, n_dir: int | None = 64, stop_vec: ndarray | None = array([0.075, 0.75, 0.075]), stop_cnt: int | None = 2)[source]#
Bases:
objectMultivariate Empirical Mode Decomposition
Rehman, Naveed, and Danilo P. Mandic. “Multivariate empirical mode decomposition.” Proceedings of the Royal Society A: Mathematical, Physical and Engineering Sciences 466.2117 (2010): 1291-1302.
G. Rilling, P. Flandrin and P. Goncalves, “On Empirical Mode Decomposition and its Algorithms”, Proc of the IEEE-EURASIP Workshop on Nonlinear Signal and Image Processing, NSIP-03, Grado (I), June 2003
N. E. Huang et al., “A confidence limit for the Empirical Mode Decomposition and Hilbert spectral analysis”, Proceedings of the Royal Society A, Vol. 459, pp. 2317-2345, 2003
Python code: mariogrune/MEMD-Python-
MATLAB code: http://www.commsp.ee.ic.ac.uk/~mandic/research/emd.htm
R code: https://rdrr.io/github/PierreMasselot/Library–emdr/man/memd.html
- __init__(stop_crit: str | None = 'stop', max_iter: int | None = 128, n_dir: int | None = 64, stop_vec: ndarray | None = array([0.075, 0.75, 0.075]), stop_cnt: int | None = 2) None[source]#
Initialize the Multivariate Empirical Mode Decomposition algorithm
Note that this algorithm requires the dimension of the input signal to be greater than or equal to 3
- Parameters:
stop_crit – The criterion for stopping the algorithm iteration, you can choose [‘stop’, ‘fix_h’]
max_iter – The maximum number of iterations
n_dir – The number of projections of the direction vector, generally this parameter does not need to be specified, After the input signal, this parameter will be set to twice the number of input signal channels
stop_vec – The stop parameter setting used when stop_crit is ‘stop’
stop_cnt – The stop parameter setting used when stop_crit is ‘fix_h’
- __module__ = 'pysdkit._emd.memd'#
- __weakref__#
list of weak references to the object (if defined)
- fit_transform(signal: ndarray) ndarray[source]#
Preform the Multivariate Empirical Mode Decomposition method.
Please note that this method only works for signals with input dimension greater than or equal to 3
(following the original MEMD MATLAB code) :param signal: the multivariate signal of numpy ndarray :return: the decomposed signal results
- fix(signal: ndarray, time: ndarray, seq: ndarray, seq_len: int, N_dim: int, counter: int) Tuple[bool, ndarray, int][source]#
emd.tvf_emd#
Created on 2025/02/01 22:06:04 @author: Whenxuan Wang @email: wwhenxuan@gmail.com
- class pysdkit._emd.tvf_emd.TVF_EMD(max_imf: int | None = 2, thresh_bwr: float | None = 0.1, bsp_order: int | None = 26, min_extrema: int | None = 4, max_iter: int | None = 100)[source]#
Bases:
objectTime Varying Filter based Empirical Mode Decomposition
Li, Heng, Zhi Li, and Wei Mo. “A time varying filter approach for empirical mode decomposition.” Signal Processing 138 (2017): 146-158.
Python code: stfbnc/pytvfemd
- __init__(max_imf: int | None = 2, thresh_bwr: float | None = 0.1, bsp_order: int | None = 26, min_extrema: int | None = 4, max_iter: int | None = 100) None[source]#
- Parameters:
max_imf – maximum number of imfs to be decomposed
thresh_bwr – instantaneous bandwidth threshold
bsp_order – b-spline order
min_extrema – stop the algorithm iteration when the number of remaining signal extrema is too low
max_iter – maximum number of iterations in one decomposition round
- __module__ = 'pysdkit._emd.tvf_emd'#
- __weakref__#
list of weak references to the object (if defined)
- _anti_mode_mixing(y: ndarray, bis_freq: ndarray, ind_remove_pad: ndarray, num_padding: int) None | int | float | complex | ndarray | Iterable[source]#
Remove unstable parts or ‘noise’ from the signal based on the extrema points of the input signal and certain rules, and smooth the signal through interpolation