Exercise: Filtering EMG data

7.3.1.4. Exercise: Filtering EMG data#

Using this dataset with one surface EMG electrode on the biceps brachii:

import kineticstoolkit.lab as ktk
import numpy as np

filename = ktk.doc.download("emg_biceps_brachii.ktk.zip")
emg = ktk.load(filename)
emg.plot()
_images/e51ca73149317228479abe3f704b992b965d5c98d882f2edcc8736d65f058a9e.png

Write a code that generates a new data named “Envelope” in the TimeSeries, that corresponds to the envelope of this signal. Follow these three steps:

  1. Filter the TimeSeries with a band-pass butterworth filter from 20 Hz to 500 Hz to reject high frequency noise and body movement artifacts.

Hide code cell content
filtered_emg = ktk.filters.butter(emg, btype="bandpass", fc=[20, 500])
filtered_emg.plot()
_images/1a567ebd099327b300a93fa6ac03d069404aee027a55351b48096e1d0f6686e0.png
  1. Rectify the filtered TimeSeries, by replacing every data by its absolute value. You may use np.abs.

Hide code cell content
filtered_emg.data["BicepsBrachiiR"] = np.abs(filtered_emg.data["BicepsBrachiiR"])
filtered_emg.plot()
_images/7f01a048c66f5868fe2da29ea53052283c7b7eb10a5dee877c0fff25745db48a.png
  1. Filter the rectified TimeSeries with a low-pass butterworth filter with a cut-off frequency of 10 Hz.

Hide code cell content
filtered_emg = ktk.filters.butter(filtered_emg, fc=10)

# Add the filtered signal as Envelope in the original TimeSeries
# There are many ways to do this, here is a robust one:
filtered_emg = filtered_emg.rename_data("BicepsBrachiiR", "Envelope")
emg = emg.merge(filtered_emg)

# Plot the result
emg.plot()
_images/907b7a7085e674c3b6116f780dce575e753729fac4d2c745de76eb13503dbcb5.png