.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/04_simulate_surface_emg.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_auto_examples_04_simulate_surface_emg.py: Surface EMG Signals ============================= After having created the **MUAPs**, we can finally simulate the **surface EMG** by creating a **surface EMG model**. .. note:: The **surface EMG** signals are the **summation** of the **MUAPs** at the surface of the skin. In **Myogen**, we can simulate the **surface EMG** by convolving the **MUAPs** with the **spike trains** of the **motor units**. .. GENERATED FROM PYTHON SOURCE LINES 12-14 .. code-block:: Python import shutil .. GENERATED FROM PYTHON SOURCE LINES 15-17 Import Libraries ----------------- .. GENERATED FROM PYTHON SOURCE LINES 17-26 .. code-block:: Python from pathlib import Path import joblib import matplotlib import numpy as np import seaborn as sns from matplotlib import pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 27-30 Load Muscle Model ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 30-34 .. code-block:: Python save_path = Path("./results") muscle = joblib.load(save_path / "muscle_model.pkl") .. GENERATED FROM PYTHON SOURCE LINES 35-38 Load Motor Neuron Pool ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python motor_neuron_pool = joblib.load(save_path / "motor_neuron_pool.pkl") .. GENERATED FROM PYTHON SOURCE LINES 42-47 Load Surface EMG Model ---------------------------- .. note:: Because of computation time, we pre-computed the **surface EMG** model for 100 motor units. .. GENERATED FROM PYTHON SOURCE LINES 47-51 .. code-block:: Python surface_emg = joblib.load(save_path / "surface_emg_100.pkl") .. GENERATED FROM PYTHON SOURCE LINES 52-56 Generate Surface EMG ----------------------------------------------- To simulate the **surface EMG**, we need to run the ``simulate_surface_emg`` method of the **SurfaceEMG** object. .. GENERATED FROM PYTHON SOURCE LINES 56-71 .. code-block:: Python surface_emg_signals = surface_emg.simulate_surface_emg( motor_neuron_pool=motor_neuron_pool ) print(f"Surface EMG simulation completed!") print(f"Generated EMG shape: {surface_emg_signals.shape}") print(f" - {surface_emg_signals.shape[0]} pools") print(f" - {surface_emg_signals.shape[1]} electrode rows") print(f" - {surface_emg_signals.shape[2]} electrode columns") print(f" - {surface_emg_signals.shape[3]} time samples") # Save the surface EMG results joblib.dump(surface_emg_signals, save_path / "surface_emg_signals.pkl") .. rst-class:: sphx-glr-script-out .. code-block:: none Simulating surface EMG (CPU): 0%| | 0/2 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 04_simulate_surface_emg.py <04_simulate_surface_emg.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 04_simulate_surface_emg.zip <04_simulate_surface_emg.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_