.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "emd_tutorials/00_quick_start/emd_tutorial_00_start_01_quicksift.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_emd_tutorials_00_quick_start_emd_tutorial_00_start_01_quicksift.py: Quick-Start: Running a simple EMD ================================= This getting started tutorial shows how to use EMD to analyse a synthetic signal. .. GENERATED FROM PYTHON SOURCE LINES 9-12 Running an EMD and frequency transform ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ First of all, we import both the numpy and EMD modules: .. GENERATED FROM PYTHON SOURCE LINES 12-19 .. code-block:: Python # sphinx_gallery_thumbnail_number = 2 import matplotlib.pyplot as plt import numpy as np import emd .. GENERATED FROM PYTHON SOURCE LINES 20-21 We then define a simulated waveform containing a non-linear wave at 5Hz and a sinusoid at 1Hz: .. GENERATED FROM PYTHON SOURCE LINES 21-48 .. code-block:: Python 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 = 0.25 # Change left-right skew of deformation [-pi to pi] nonlinearity_phi = -np.pi/4 # Compute the signal # Create a non-linear oscillation x = emd.simulate.abreu2010(freq, nonlinearity_deg, nonlinearity_phi, sample_rate, seconds) x += np.cos(2 * np.pi * 1 * time_vect) # Add a simple 1Hz sinusoid x -= np.sin(2 * np.pi * 2.2e-1 * time_vect) # Add part of a very slow cycle as a trend # Visualise the time-series for analysis plt.figure(figsize=(12, 4)) plt.plot(x) .. image-sg:: /emd_tutorials/00_quick_start/images/sphx_glr_emd_tutorial_00_start_01_quicksift_001.png :alt: emd tutorial 00 start 01 quicksift :srcset: /emd_tutorials/00_quick_start/images/sphx_glr_emd_tutorial_00_start_01_quicksift_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 49-53 Try changing the values of ``nonlinearity_deg`` and ``nonlinearity_phi`` to create different non-sinusoidal waveform shapes. Next, we can then estimate the IMFs for the signal: .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python imf = emd.sift.sift(x) print(imf.shape) .. rst-class:: sphx-glr-script-out .. code-block:: none (10000, 4) .. GENERATED FROM PYTHON SOURCE LINES 58-60 and, from the IMFs, compute the instantaneous frequency, phase and amplitude using the Normalised Hilbert Transform Method: .. GENERATED FROM PYTHON SOURCE LINES 60-63 .. code-block:: Python IP, IF, IA = emd.spectra.frequency_transform(imf, sample_rate, 'hilbert') .. GENERATED FROM PYTHON SOURCE LINES 64-65 From the instantaneous frequency and amplitude, we can compute the Hilbert-Huang spectrum: .. GENERATED FROM PYTHON SOURCE LINES 65-70 .. code-block:: Python # Define frequency range (low_freq, high_freq, nsteps, spacing) freq_range = (0.1, 10, 80, 'log') f, hht = emd.spectra.hilberthuang(IF, IA, freq_range, sum_time=False) .. GENERATED FROM PYTHON SOURCE LINES 71-75 Visualising the results ^^^^^^^^^^^^^^^^^^^^^^^ we can now plot some summary information, first the IMFs: .. GENERATED FROM PYTHON SOURCE LINES 75-78 .. code-block:: Python emd.plotting.plot_imfs(imf) .. image-sg:: /emd_tutorials/00_quick_start/images/sphx_glr_emd_tutorial_00_start_01_quicksift_002.png :alt: emd tutorial 00 start 01 quicksift :srcset: /emd_tutorials/00_quick_start/images/sphx_glr_emd_tutorial_00_start_01_quicksift_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 79-80 and now the Hilbert-Huang transform of this decomposition .. GENERATED FROM PYTHON SOURCE LINES 81-86 .. code-block:: Python fig = plt.figure(figsize=(10, 6)) emd.plotting.plot_hilberthuang(hht, time_vect, f, time_lims=(2, 4), freq_lims=(0.1, 15), fig=fig, log_y=True) .. image-sg:: /emd_tutorials/00_quick_start/images/sphx_glr_emd_tutorial_00_start_01_quicksift_003.png :alt: Hilbert-Huang Transform :srcset: /emd_tutorials/00_quick_start/images/sphx_glr_emd_tutorial_00_start_01_quicksift_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.581 seconds) .. _sphx_glr_download_emd_tutorials_00_quick_start_emd_tutorial_00_start_01_quicksift.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: emd_tutorial_00_start_01_quicksift.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: emd_tutorial_00_start_01_quicksift.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_