Note
Click here to download the full example code
Running a simple EMD¶
This getting started tutorial shows how to use EMD to analyse a synthetic signal.
Running an EMD and frequency transform¶
First of all, we import both the numpy and EMD modules:
# sphinx_gallery_thumbnail_number = 2
import matplotlib.pyplot as plt
import numpy as np
import emd
We then define a simulated waveform containing a non-linear wave at 5Hz and a sinusoid at 1Hz:
sample_rate = 1000
seconds = 10
num_samples = sample_rate*seconds
time_vect = np.linspace(0, seconds, num_samples)
freq = 5
# Change extent of deformation from sinusoidal shape [-1 to 1]
nonlinearity_deg = .25
# Change left-right skew of deformation [-pi to pi]
nonlinearity_phi = -np.pi/4
# Compute the signal
x = emd.utils.abreu2010(freq, nonlinearity_deg, nonlinearity_phi, sample_rate, seconds)
x += np.cos(2 * np.pi * 1 * time_vect)
# Visualise the time-series for analysis
plt.figure(figsize=(12, 4))
plt.plot(x)
Out:
[<matplotlib.lines.Line2D object at 0x7f98b3e29490>]
We can then estimate the IMFs for the signal:
imf = emd.sift.sift(x)
print(imf.shape)
Out:
(10000, 5)
and, from the IMFs, compute the instantaneous frequency, phase and amplitude using the Normalised Hilbert Transform Method:
IP, IF, IA = emd.spectra.frequency_stats(imf, sample_rate, 'nht')
From the instantaneous frequency and amplitude, we can compute the Hilbert-Huang spectrum:
freq_edges, freq_bins = emd.spectra.define_hist_bins(0, 10, 100)
hht = emd.spectra.hilberthuang(IF, IA, freq_edges)
Visualising the results¶
we can now plot some summary information, first the IMFs:
emd.plotting.plot_imfs(imf, scale_y=True, cmap=True)
and now the Hilbert-Huang transform of this decomposition
plt.figure(figsize=(10, 6))
plt.subplot(1, 1, 1)
plt.pcolormesh(time_vect[:5000], freq_bins, hht[:, :5000], cmap='ocean_r')
plt.ylabel('Frequency (Hz)')
plt.xlabel('Time (secs)')
plt.grid(True)
Out:
/home/docs/checkouts/readthedocs.org/user_builds/emd/checkouts/v0.3.0/doc/source/tutorials/plot_tutorial1.py:77: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later.
plt.pcolormesh(time_vect[:5000], freq_bins, hht[:, :5000], cmap='ocean_r')
Total running time of the script: ( 0 minutes 1.412 seconds)