resurfemg.preprocessing.filtering module

Copyright 2022 Netherlands eScience Center and University of Twente Licensed under the Apache License, version 2.0. See LICENSE for details.

This file contains functions to filter EMG arrays.

resurfemg.preprocessing.filtering.bad_end_cutter(data_emg, percent_to_cut=7, tolerance_percent=10)

This algorithm takes the end off of EMGs where the end is radically altered, or if not radically altered cuts the last 10 values but returns only the array, not an altered Poly5.

Parameters:
  • data_emg (Poly5Reader) – A Poly5

  • percent_to_cut (int) – Percentage to look at on the end

  • tolerance_percent (int) – Percent variation tolerance to allow without cutting

Returns:

The cut EMG sample data

Return type:

ndarray

resurfemg.preprocessing.filtering.bad_end_cutter_better(data_emg, percent_to_cut=7, tolerance_percent=10)

This algorithm takes the end off of EMGs where the end is radically altered, or if not radically altered cuts the last 10 values but returns only the array not an altered Poly5.

Parameters:
  • data_emg (Poly5Reader) – A Poly5

  • percent_to_cut (int) – Percentage to look at on the end

  • tolerance_percent (int) – Percentage variation to allow without cut

Returns:

The cut EMG sample data

Return type:

ndarray

resurfemg.preprocessing.filtering.bad_end_cutter_for_samples(data_emg, percent_to_cut=7, tolerance_percent=10)

This algorithm takes the end off of EMGs where the end is radically altered, or if not radically altered cuts the last 10 values but returns only the array.

Parameters:
  • data_emg (ndarray) – Array of samples

  • percent_to_cut (int) – Percentage to look at on the end

  • tolerance_percent (int) – Percent variation to allow without cutting

Returns:

The cut EMG sample data

Return type:

ndarray

resurfemg.preprocessing.filtering.compute_power_loss(original_signal, original_signal_sampling_frequency, processed_signal, processed_signal_sampling_frequency)

This function computes the percentage of power loss after the processing of a signal. Inputs include the original_signal (signal before the processing), original_signal_sampling_frequency (sampling frequency of the signal before processing), processed_signal (signal after processing), processed_signal_sampling_frequency (sampling frequency of the signal after processing).

Output is the percentage of power loss.

Parameters:
  • original_signal (ndarray) – Array.

  • original_signal_sampling_frequency (int) – Sampling freq. original signal

  • processed_signal (ndarray) – Array.

  • processed_signal_sampling_frequency (int) – Sampling frequency processed signal

Returns:

Power loss

Return type:

float

resurfemg.preprocessing.filtering.emg_bandpass_butter(data_emg, low_pass, high_pass)

The parameter taken in here is the Poly5 file. Output is the EMG after a bandpass as made here.

Parameters:
  • data_emg (Poly5Reader) – Poly5 file with the samples to work over

  • low_pass (int) – The number to cut off frequenciesabove

  • high_pass (int) – The number to cut off frequenceisbelow

Returns:

The bandpass filtered EMG sample data

Return type:

ndarray

resurfemg.preprocessing.filtering.emg_bandpass_butter_sample(data_emg_samp, low_pass, high_pass, sample_rate, output='sos')

Output is the EMG after a bandpass as made here.

Parameters:
  • data_emg_samp (ndarray) – The array in the sample

  • low_pass (int) – The number to cut off frequenciesabove

  • high_pass (str) – The number to cut off frequenceisbelow

  • sample_rate (int) – The number of samples per second i.e. Hertz

  • output – The type of sampling stabilizor

Returns:

The bandpass filtered EMG sample data

Return type:

ndarray

resurfemg.preprocessing.filtering.emg_highpass_butter(data_emg, cut_above, sample_rate)

The parameter taken in here is the Poly5 file’s samples or another array. Output is the EMG after a bandpass as made here.

Parameters:
  • data_emg (ndarray) – Samples from the EMG

  • cut_above (int) – The number to cut off frequenceisbelow

  • sample_rate (int) – The number of samples per second i.e. Hertz

Returns:

The bandpass filtered EMG sample data

Return type:

ndarray

resurfemg.preprocessing.filtering.emg_highpass_butter_sample(data_emg_samp, high_pass, sample_rate, order=3)

Output is the EMG after a bandpass as made here.

Parameters:
  • data_emg_samp (ndarray) – The array in the sample

  • high_pass (int) – The number to cut off frequenciesabove

  • order (int) – The filter order

Returns:

The bandpass filtered EMG sample data

Return type:

ndarray

resurfemg.preprocessing.filtering.emg_lowpass_butter(array, cutoff, fs, order=5)

This is a lowpass filter of butterworth design.

Parameters:
  • array (ndarray) – 1d signal array usually of EMG

  • cutoff (int) – frequency above which to filter out

  • fs (int) – frequency array sampled at in Hertz

  • order (int) – order of the filter

Returns:

signal_filtered

Return type:

ndarray

resurfemg.preprocessing.filtering.emg_lowpass_butter_sample(data_emg_samp, low_pass, sample_rate, order=3)

Output is the EMG after a lowpass as made here.

Parameters:
  • data_emg_samp (ndarray) – The array in the sample

  • low_pass (int) – The number to cut off frequenciesabove

  • low_pass – The number to cut off frequenciesabove

  • order (int) – The filter order

Returns:

The bandpass filtered EMG sample data

Return type:

ndarray

resurfemg.preprocessing.filtering.helper_lowpass(cutoff, fs, order=5)

This is a helper function inside the butter_lowpass_filter function.

resurfemg.preprocessing.filtering.notch_filter(sample, sample_frequ, freq_to_pull, quality_factor_q)

This is a filter designed to take out a specific frequency. In the EU in some data electrical cords can interfere at around 50 Hertz. In some other locations the interference is at 60 Hertz. The specificities of a local power grid may neccesitate notch filtering.

Parameters:
  • sample (int) – Percentage variation tolerance to allow without cutting

  • sample_frequ (int) – The frequency at which the sample was captured

  • freq_to_pull (int) – The frequency you desire to remove from the signal

  • quality_factor_q (int) – How high the quality of the removal is

Returns:

The filterered sample data

Return type:

ndarray