pyhht package

Submodules

pyhht.emd module

Empirical Mode Decomposition.

pyhht.emd.EMD

alias of EmpiricalModeDecomposition

class pyhht.emd.EmpiricalModeDecomposition(x, t=None, threshold_1=0.05, threshold_2=0.5, alpha=0.05, is_mode_complex=None, ndirs=4, fixe=0, maxiter=2000, fixe_h=0, n_imfs=0, nbsym=2)

Bases: object

The EMD class.

__init__(x, t=None, threshold_1=0.05, threshold_2=0.5, alpha=0.05, is_mode_complex=None, ndirs=4, fixe=0, maxiter=2000, fixe_h=0, n_imfs=0, nbsym=2)

Empirical mode decomposition.

Parameters:
  • x (array-like) – A vector on which to perform empirical mode decomposition.
  • t (array-like) – Sampling time instants.
  • threshold_1 (float) – Threshold for the stopping criterion, corresponding to :math:` heta_{1}` in [1] (Default: 0.05)
  • threshold_2 (float) – Threshold for the stopping criterion, corresponding to :math:` heta_{2}` in [1] (Default: 0.5)
  • alpha (float) – Tolerance for the stopping criterion, corresponding to \(lpha\) in [1] (Default: 0.05)
  • is_mode_complex (bool) – Whether the input signal is complex.
  • ndirs (int) – Number of directions in which envelopes are computed. (Default: 4)
  • fixe (int) – Number of sifting iterations to perform for each mode. The default value is None, in which case the default stopping criterion is used. If not None, each mode will be a result of exactly fixe sifting iterations.
  • maxiter (int) – Number of maximum sifting iterations for the computation of each mode. (Default: 2000)
  • fixe_h (int) –
  • n_imfs (int) – Number if IMFs to extract.
  • nbsym (int) – Number of points to mirror when calculating envelopes.
Returns:

Array of shape [n_imfs + 1, length(x)]

Return type:

numpy.ndarray

Example:
>>> from pyhht.visualization import plot_imfs
>>> import numpy as np
>>> t = np.linspace(0, 1, 1000)
>>> modes = np.sin(2 * pi * 5 * t) + np.sin(2 * pi * 10 * t)
>>> x = modes + t
>>> decomposer = EMD(x)
>>> imfs = decomposer.decompose()
>>> plot_imfs(x, imfs, t) 

(Source code, png, hires.png, pdf)

../_images/simple_emd.png
decompose()

Decompose the input signal into IMFs.

This function does all the heavy lifting required for sifting, and should ideally be the only public method of this class. :Example:

>>> from pyhht.visualization import plot_imfs
>>> import numpy as np
>>> t = np.linspace(0, 1, 1000)
>>> modes = np.sin(2 * pi * 5 * t) + np.sin(2 * pi * 10 * t)
>>> x = modes + t
>>> decomposer = EMD(x)
>>> imfs = decomposer.decompose()
io()

Compute the index of orthoginality, as defined by:

\[\sum_{i, j=1, i\]

eq j}^{N} rac{|C_{i}overline{C_{j}}|}{|x|^2}

Where \(C_{i}\) is the \(i\) th IMF.

return:Index of orthogonality.
rtype:float
Example:
>>> import numpy as np
>>> t = np.linspace(0, 1, 1000)
>>> modes = np.sin(2 * pi * 5 * t) + np.sin(2 * pi * 10 * t)
>>> x = modes + t
>>> decomposer = EMD(x)
>>> imfs = decomposer.decompose()
>>> print(decomposer.io())
0.0170853675933
keep_decomposing()

Check whether to continue the sifting operation.

mean_and_amplitude(m)

Computes the mean of the envelopes and the mode amplitudes.

stop_EMD()

Check if there are enough extrema (3) to continue sifting.

stop_sifting(m)

Evaluate the stopping criteria for the current mode.

Parameters:m (array-like) – The current mode

pyhht.utils module

Utility functions used to inspect EMD functionality.

pyhht.utils.boundary_conditions(signal, time_samples, z=None, nbsym=2)

Extend the signal beyond it’s bounds w.r.t mirror symmetry.

Parameters:
  • x (array-like) – Signal to be mirrored.
  • t (array-like) – Timestamps of the signal
  • z (array-like) – Signal on whose extrema the interpolation is evaluated. (By default this is just x)
  • nbsym (int) – Number of points added to each end of the signal.
Returns:

timestamps and values of extended extrema, ordered as (minima timestamps, maxima timestamps, minima values, maxima values.)

Return type:

tuple

Example:
>>> from __future__ import print_function
>>> import numpy as np
>>> signal = np.array([-1, 1, -1, 1, -1])
>>> print(boundary_conditions(signal, np.arange(5)))
(array([-2,  2,  6]), array([-3, -1,  1,  3,  5,  7]), array([-1, -1, -1]), array([1, 1, 1, 1, 1, 1]))
pyhht.utils.extr(x)

Extract the indices of the extrema and zero crossings.

Parameters:x (array-like) – input signal
Returns:indices of minima, maxima and zero crossings.
Return type:tuple
Example:
>>> from __future__ import print_function
>>> import numpy as np
>>> x = np.array([0, -2, 0, 1, 3, 0.5, 0, -1, -1])
>>> indmin, indmax, indzer = extr(x)
>>> print(indmin)
[1]
>>> print(indmax)
[4]
>>> print(indzer)
[0 2 6]
pyhht.utils.get_envelops(x, t=None)

Find the upper and lower envelopes of the array x. :Example: >>> import numpy as np >>> x = np.random.rand(100,) >>> upper, lower = get_envelops(x)

pyhht.utils.inst_freq(x, t=None, L=1)

Compute the instantaneous frequency of an analytic signal at specific time instants using the trapezoidal integration rule.

Parameters:
  • x (numpy.ndarray) – The input analytic signal
  • t (numpy.ndarray) – The time instants at which to calculate the instantaneous frequencies.
  • L (int) – Non default values are currently not supported. If L is 1, the normalized instantaneous frequency is computed. If L > 1, the maximum likelihood estimate of the instantaneous frequency of the deterministic part of the signal.
Returns:

instantaneous frequencies of the input signal.

Return type:

numpy.ndarray

Example:
>>> from tftb.generators import fmsin
>>> import matplotlib.pyplot as plt
>>> x = fmsin(70, 0.05, 0.35, 25)[0]
>>> instf, timestamps = inst_freq(x)
>>> plt.plot(timestamps, instf) 

(Source code, png, hires.png, pdf)

../_images/inst_freq.png

pyhht.visualization module

Visualization functions for PyHHT.

pyhht.visualization.plot_imfs(signal, imfs, time_samples=None, fignum=None)

Visualize decomposed signals.

Parameters:
  • signal (array-like) – Analyzed signal
  • imfs (array-like of shape (n_imfs, length_of_signal)) – intrinsic mode functions of the signal
  • time_samples (array-like) – time instants
  • fignum (int) – (optional) number of the figure to display
Returns:

None

Example:
>>> from pyhht.visualization import plot_imfs
>>> import numpy as np
>>> from pyhht import EMD
>>> t = np.linspace(0, 1, 1000)
>>> modes = np.sin(2 * np.pi * 5 * t) + np.sin(2 * np.pi * 10 * t)
>>> x = modes + t
>>> decomposer = EMD(x)
>>> imfs = decomposer.decompose()
>>> plot_imfs(x, imfs, t) 

(Source code, png, hires.png, pdf)

../_images/simple_emd.png

Module contents

pyhht.EMD

alias of EmpiricalModeDecomposition

class pyhht.EmpiricalModeDecomposition(x, t=None, threshold_1=0.05, threshold_2=0.5, alpha=0.05, is_mode_complex=None, ndirs=4, fixe=0, maxiter=2000, fixe_h=0, n_imfs=0, nbsym=2)

Bases: object

The EMD class.

__init__(x, t=None, threshold_1=0.05, threshold_2=0.5, alpha=0.05, is_mode_complex=None, ndirs=4, fixe=0, maxiter=2000, fixe_h=0, n_imfs=0, nbsym=2)

Empirical mode decomposition.

Parameters:
  • x (array-like) – A vector on which to perform empirical mode decomposition.
  • t (array-like) – Sampling time instants.
  • threshold_1 (float) – Threshold for the stopping criterion, corresponding to :math:` heta_{1}` in [1] (Default: 0.05)
  • threshold_2 (float) – Threshold for the stopping criterion, corresponding to :math:` heta_{2}` in [1] (Default: 0.5)
  • alpha (float) – Tolerance for the stopping criterion, corresponding to \(lpha\) in [1] (Default: 0.05)
  • is_mode_complex (bool) – Whether the input signal is complex.
  • ndirs (int) – Number of directions in which envelopes are computed. (Default: 4)
  • fixe (int) – Number of sifting iterations to perform for each mode. The default value is None, in which case the default stopping criterion is used. If not None, each mode will be a result of exactly fixe sifting iterations.
  • maxiter (int) – Number of maximum sifting iterations for the computation of each mode. (Default: 2000)
  • fixe_h (int) –
  • n_imfs (int) – Number if IMFs to extract.
  • nbsym (int) – Number of points to mirror when calculating envelopes.
Returns:

Array of shape [n_imfs + 1, length(x)]

Return type:

numpy.ndarray

Example:
>>> from pyhht.visualization import plot_imfs
>>> import numpy as np
>>> t = np.linspace(0, 1, 1000)
>>> modes = np.sin(2 * pi * 5 * t) + np.sin(2 * pi * 10 * t)
>>> x = modes + t
>>> decomposer = EMD(x)
>>> imfs = decomposer.decompose()
>>> plot_imfs(x, imfs, t) 

(Source code, png, hires.png, pdf)

../_images/simple_emd.png
decompose()

Decompose the input signal into IMFs.

This function does all the heavy lifting required for sifting, and should ideally be the only public method of this class. :Example:

>>> from pyhht.visualization import plot_imfs
>>> import numpy as np
>>> t = np.linspace(0, 1, 1000)
>>> modes = np.sin(2 * pi * 5 * t) + np.sin(2 * pi * 10 * t)
>>> x = modes + t
>>> decomposer = EMD(x)
>>> imfs = decomposer.decompose()
io()

Compute the index of orthoginality, as defined by:

\[\sum_{i, j=1, i\]

eq j}^{N} rac{|C_{i}overline{C_{j}}|}{|x|^2}

Where \(C_{i}\) is the \(i\) th IMF.

return:Index of orthogonality.
rtype:float
Example:
>>> import numpy as np
>>> t = np.linspace(0, 1, 1000)
>>> modes = np.sin(2 * pi * 5 * t) + np.sin(2 * pi * 10 * t)
>>> x = modes + t
>>> decomposer = EMD(x)
>>> imfs = decomposer.decompose()
>>> print(decomposer.io())
0.0170853675933
keep_decomposing()

Check whether to continue the sifting operation.

mean_and_amplitude(m)

Computes the mean of the envelopes and the mode amplitudes.

stop_EMD()

Check if there are enough extrema (3) to continue sifting.

stop_sifting(m)

Evaluate the stopping criteria for the current mode.

Parameters:m (array-like) – The current mode
pyhht.plot_imfs(signal, imfs, time_samples=None, fignum=None)

Visualize decomposed signals.

Parameters:
  • signal (array-like) – Analyzed signal
  • imfs (array-like of shape (n_imfs, length_of_signal)) – intrinsic mode functions of the signal
  • time_samples (array-like) – time instants
  • fignum (int) – (optional) number of the figure to display
Returns:

None

Example:
>>> from pyhht.visualization import plot_imfs
>>> import numpy as np
>>> from pyhht import EMD
>>> t = np.linspace(0, 1, 1000)
>>> modes = np.sin(2 * np.pi * 5 * t) + np.sin(2 * np.pi * 10 * t)
>>> x = modes + t
>>> decomposer = EMD(x)
>>> imfs = decomposer.decompose()
>>> plot_imfs(x, imfs, t) 

(Source code, png, hires.png, pdf)

../_images/simple_emd.png