PyEMD Documentation

repository·master·Indexed 19 days ago

https://github.com/laszukdawid/pyemd

A Python implementation of the Empirical Mode Decomposition (EMD) algorithm and its variations, including EEMD and CEEMDAN, for signal processing. Distributed as the EMD-signal package, it provides tools for decomposing signals into Intrinsic Mode Functions (IMFs), visualizing results, and performing statistical white noise checks. It includes experimental support for 2D EMD (EMD2D/BEMD) for images and a JIT-compiled version (JitEMD) for large signals.

Tokens
5.4K
Snippets
31
Records
40
Agent score
76%

What's inside PyEMD

  1. What is PyEMD?

    master

    PyEMD is a Python implementation of Empirical Mode Decomposition (EMD) and its variations, such as Ensemble Empirical Mode Decomposition (EEMD).

    Core Concept: Intrinsic Mode Functions (IMF) Methods in this package decompose a signal into a set of components called Intrinsic Mode Functions (IMF). These IMFs represent specific oscillations within the analyzed signal, characterized by their own frequency and amplitude, which may change over time.

  2. Experimental EMD2D for image decomposition

    master

    The EMD2D module is an experimental feature for performing EMD on images. This version uses 2D splines for envelopes, which are spanned on extrema defined through a maximum filter.

    Warning: This is an experimental module. Results are not guaranteed to be reasonable or computationally optimal.

  3. Configure stopping conditions for EMD

    master

    You can control the number of sifting iterations by adjusting the stopping condition parameters FIXE and FIXE_H on the EMD instance.

    • FIXE: Setting this to any positive value forces exactly that many iterations for every IMF.
    • FIXE_H: Relates to the number of iterations required when the proto-IMF signal fulfills IMF conditions (extrema and zero-crossings differ by at most one, and the mean is near zero). This ensures at least FIXE_H iterations per IMF.
    • Default Behavior: When both FIXE and FIXE_H are set to 0, the algorithm uses other convergence criteria, such as checking for convergence between consecutive iterations or checking if the output amplitude is below an acceptable range.
    # Example: Fix iterations to exactly 10
    from PyEMD import EMD
    emd = EMD()
    emd.FIXE = 10
    imfs = emd(s)
    
    # Example: Ensure at least 5 iterations if IMF conditions are met
    from PyEMD import EMD
    emd = EMD()
    emd.FIXE_H = 5
    imfs = emd(s)
  4. How CEEMDAN works and its parallel execution

    master

    Complete Ensemble EMD with Adaptive Noise (CEEMDAN) is an extension of EEMD where information about the noise is shared among all workers.

    Parallelization: By default, CEEMDAN enables parallel execution, automatically utilizing all available CPU cores to speed up computation. You can control this behavior via the parallel parameter during initialization.

  5. Experimental BEMD for bidimensional data

    master

    The BEMD (Bidimensional Empirical Mode Decomposition) module is an experimental feature for performing EMD on 2D data, such as images. It uses morphological operators to detect regional maxima, which are then used to span a surface envelope using a radial basis function.

    Warning: This is an experimental module. Results are not guaranteed to be reasonable or computationally optimal.

  6. How Ensemble Empirical Mode Decomposition (EEMD) works

    master

    Ensemble Empirical Mode Decomposition (EEMD) decomposes an input signal by creating an ensemble of workers. Each worker performs a standard Empirical Mode Decomposition (EMD) on a copy of the input signal that has been augmented with added noise. Once all workers complete their tasks, the final result is calculated as the mean across all workers.

    Note on Reproducibility: Because EEMD relies on random noise, every decomposition will produce a different set of components by default. To achieve reproducible results, you must both set a seed using the noise_seed method and disable parallel execution by setting parallel=False.

    eemd = EEMD(parallel=False)
    eemd.noise_seed(12345)
    imfs = eemd(signal)
  7. Limit the number of output IMFs

    master

    By default, EMD methods decompose the signal until all components are returned. If your use case only requires a specific number of components (e.g., only the first component), you can limit the output by setting the max_imfs parameter.

    from PyEMD import EEMD
    
    # Limit the decomposition to return only 2 IMFs
    eemd = EEMD(max_imfs=2)
  8. Optimize EEMD and CEEMDAN by adjusting the number of trials

    master

    In EEMD and CEEMDAN, the trials parameter determines how many times the EMD is performed with noise-perturbed signals. While more trials increase convergence certainty, they also increase computation time. You can decrease the trials value to speed up the process if the default is too high for your specific signal.

    from PyEMD import CEEMDAN
    
    # Reduce the number of iterations to speed up computation
    ceemdan = CEEMDAN(trials=20)
  9. Install PyEMD from source (GitHub)

    master

    To install the latest version directly from the GitHub repository, you can either clone the repository and install it locally, or install it directly using a git URL with pip.

    # Option 1: Clone and install locally
    $ git clone https://github.com/laszukdawid/PyEMD
    $ python -m pip install .
    
    # Option 2: Install directly via git URL
    $ python -m pip install git+https://github.com/laszukdawid/PyEMD.git
  10. Perform Ensemble Empirical Mode Decomposition (EEMD) with the EEMD class

    master

    To perform Ensemble Empirical Mode Decomposition, import the EEMD class and use its eemd method. You can also configure the underlying EMD settings, such as the extrema detection method, by accessing the eemd.EMD attribute.

    from PyEMD import EEMD
    import numpy as np
    
    t = np.linspace(0, 1, 200)
    S = np.sin(2*np.pi*t) # Example signal
    
    eemd = EEMD()
    
    # Configure underlying EMD settings (e.g., extrema detection)
    eemd.EMD.extrema_detection = "parabol"
    
    eIMFs = eemd.eemd(S, t)