|
EMG Analysis - Time and Frequency Parameters |
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:
1 - Importation of the needed packages
# 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
# 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
channel = list(data.keys())[0]
device = header["device"]
resolution = int(header["resolution"][0])
4 - Storage of sampling frequency and acquired data inside variables
# 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
burst_begin, burst_end = bsnb.detect_emg_activations(signal, fs, smooth_level=20, threshold_level=10,
time_units=True, plot_result=True)[:2]
5.2 -Maximum, Minimum and Average duration of muscular activation periods
# Bursts Duration
bursts_time = burst_end - burst_begin
# Parameter extraction
max_time = max(bursts_time)
min_time = min(bursts_time)
avg_time = average(bursts_time)
std_time = std(bursts_time)
5.3 - Maximum, Minimum, Average and Standard Deviation of EMG sample values
# Maximum
max_sample_value = max(signal)
# Minimum
min_sample_value = min(signal)
# Average and Standard Deviation
avg_sample_value = average(signal)
std_sample_value = std(signal)
time_param_dict = {"Maximum EMG": max_sample_value, "Minimum EMG": min_sample_value,
"Average EMG": avg_sample_value, "Standard Deviation EMG": std_sample_value}
5.4 - Root Mean Square and Area under the curve (Signal Intensity Estimators)
# Root Mean Square
rms = sqrt(sum(signal * signal) / len(signal))
# Area under the curve
area = cumtrapz(signal)
5.5 - Total power and some reference points on the frequency domain
# Signal Power Spectrum
f, P = welch(signal, fs=fs, window='hanning', noverlap=0, nfft=int(256.))
# Total Power and Median Frequency (Frequency that divides the spectrum into two regions with equal power)
area_freq = cumtrapz(P, f, initial=0)
total_power = area_freq[-1]
median_freq = f[where(area_freq >= total_power / 2)[0][0]]
f_max = f[argmax(P)]
This procedure can be automatically done by emg_parameters function in extract module of biosignalsnotebooks package
bsnb.emg_parameters(signal, fs, raw_to_mv=False)
This set of parameters reveals interesting information about EMG signal, however you can extract much more features during your signal processing journey !
We hope that you have enjoyed this guide. biosignalsnotebooks is an environment in continuous expansion, so don"t stop your journey and learn more with the remaining Notebooks !