7.3.1. Butterworth filter#

The Butterworth filter may be the most used filter in biomechanics. It removes ranges of frequencies from the signal’s frequency spectrum. Normally, we first identify the frequency range of our data, so that we can remove any signal frequencies outside this range.

Let’s start by loading some noisy data.

import kineticstoolkit.lab as ktk
import matplotlib.pyplot as plt

ts_noisy = ktk.load(ktk.doc.download("filters_noisy_signals.ktk.zip"))

ts_noisy.plot();
_images/05c4127db846421e550e521c9b81ea3dbf2c65c3b912d768f42c7bb7a925a5ee.png

7.3.1.1. Low-pass filter#

The default setting for ktk.filters.butter is to apply a low-pass, no-lag filter of order 2. To filter with a cut-off frequency of 20 Hz:

ts_filtered = ktk.filters.butter(ts_noisy, fc=20)
ts_filtered.plot()
_images/02a7462605076cb5a9ef3a856f13cc7fd5d83d607bf489bbcb8c9a2a9248deed.png

You are encouraged to experiment with different cut-off frequencies to observe its effect on the results. In the figure above, we observed that while 20 Hz was probably correct for the sine wave, it still filtered out the most dynamic components, most notably in the square and pulse signals.

7.3.1.2. High-pass filter#

The inverse operation is the high-pass filter. Let’s observe what we removed from the original signal in the figure above:

ts_filtered = ktk.filters.butter(ts_noisy, btype="highpass", fc=20)
ts_filtered.plot()
_images/0bf5d9767e5b67313102cef3c99e673d08c09d15a57b6b37a24b7ccf69fdde38.png

Only the transitions were kept; all the stable parts of the signal were removed.

7.3.1.3. Band-pass filter#

We can combine both low-pass and high-pass in a band-pass filter. This type of filter is commonly used in processing of electromyography, to filter both high-frequency noise and low-frequency movement artifact.

To remove frequencies between 10 and 80 Hz:

ts_filtered = ktk.filters.butter(ts_noisy, btype="bandpass", fc=[10, 80])
ts_filtered.plot()
_images/6c05c9246985e965d8672554573d38b2bfca5028a38ec1578eb0428c52248e24.png