EMG Analysis - Time and Frequency Parameters
Difficulty Level:
Tags extract☁emg☁muscular-activations

Muscles perform an essential role on movement, postural control and in the vital cardiorespiratory functions. These three examples have something in common, which is, the origin of the muscular contraction is in the nervous impulse that reaches the muscle, triggering a sequence of physiological mechanisms that ultimately cause the muscle contraction.

In the last example (muscle in vital cardiorespiratory processes), myocardium (cardiac muscle) functions in an involuntary way, under the coordination of the autonomic nervous system.

The previously mentioned nervous impulse and the respective changes in electric potential can be monitored by ECG acquisition and analysis.

However, for movement and postural control, another type of muscle goes into action, the skeletal muscle. In contrast to cardiac muscle, the action of skeletal muscles is voluntary, causing drastic differences in EMG signal when comparing to ECG, namely the inexistence of natural periodicity.

In this Jupyter Notebook it will be explained how some parameters can be extracted from EMG, both from time and frequency domain.

List of EMG analysis parameters:

  • Number of Muscular Activations;
  • Maximum, Minimum and Average duration of muscular activations;
  • Minimum, Maximum, Average and Standard Deviation values of EMG samples;
  • Root Mean Square (RMS) and Area under curve;
  • Total Power, Maximum Frequency and Median Frequency;

1 - Importation of the needed packages

In [1]:
# biosignalsnotebooks python package
import biosignalsnotebooks as bsnb

# Scientific packages
from numpy import linspace, max, min, average, std, sum, sqrt, where, argmax
from scipy.integrate import cumtrapz
from scipy.signal import welch

2 - Load of acquired EMG data

In [2]:
# Load of data
data, header = bsnb.load_signal("emg_bursts", get_header=True)

3 - Identification of mac address of the device and the channel used during acquisition

In [3]:
channel = list(data.keys())[0]
device = header["device"]
resolution = int(header["resolution"][0])
In [4]:
from sty import fg, rs
print (fg(98,195,238) + "\033[1mDevice: \033[0m" + fg.rs + device + fg(98,195,238) + "\033[1m Channel: \033[0m" + fg.rs + str(channel) + fg(98,195,238) + "\033[1m Resolution: \033[0m" + fg.rs + str(resolution) + " bits")
Device: channeller Channel: CH3 Resolution: 16 bits

4 - Storage of sampling frequency and acquired data inside variables

In [5]:
# Sampling frequency and acquired data
fs = header["sampling rate"]

# Signal Samples
signal = bsnb.raw_to_phy("EMG", device, data[channel], resolution, option="mV") # Conversion to mV
time = linspace(0, len(signal) / fs, len(signal))

5 -EMG parameter extraction
5.1 -Detection and accounting of muscular activations

In [6]:
burst_begin, burst_end = bsnb.detect_emg_activations(signal, fs, smooth_level=20, threshold_level=10, 
                                                     time_units=True, plot_result=True)[:2]