resurfemg.preprocessing.ecg_removal 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 eliminate ECG artifacts from
with various EMG arrays.
- resurfemg.preprocessing.ecg_removal.compute_ICA_n_comp(emg_samples, use_all_leads=True, desired_leads=(0, 2))¶
A function that performs an independant component analysis (ICA) meant for EMG data that includes stacked arrays, there should be at least two arrays but there can be more. This differs from helper_functions.compute_ICA_two_comp_multi because you can get n leads back instead of only two.
- resurfemg.preprocessing.ecg_removal.compute_ICA_n_comp_selective_zeroing(emg_samples, ecg_lead_to_remove, use_all_leads=True, desired_leads=(0, 2))¶
A function that performs an independant component analysis (ICA) meant for EMG data that includes stacked arrays, there should be at least two arrays but there can be more. In this ICA one lead is put to zero before reconstruction. This should probably be the ECG lead.
- Parameters:
- Returns:
Arrays of independent components (ECG-like and EMG)
- Return type:
- resurfemg.preprocessing.ecg_removal.compute_ICA_two_comp_selective(emg_samples, use_all_leads=True, desired_leads=(0, 2))¶
A function that performs an independant component analysis (ICA) meant for EMG data that includes stacked arrays, there should be at least two arrays but there can be more.
- Parameters:
- Returns:
Two arrays of independent components (ECG-like and EMG)
- Return type:
- resurfemg.preprocessing.ecg_removal.compute_ica_two_comp(emg_samples)¶
A function that performs an independent component analysis (ICA) meant for EMG data that includes three stacked arrays.
- resurfemg.preprocessing.ecg_removal.compute_ica_two_comp_multi(emg_samples)¶
A function that performs an independant component analysis (ICA) meant for EMG data that includes stacked arrays, there should be at least two arrays but there can be more.
- resurfemg.preprocessing.ecg_removal.find_peaks_in_ecg_signal(ecg_signal, lower_border_percent=50)¶
This function assumes you have isolated an ecg-like signal with QRS peaks “higher” (or lower) than ST waves. In this case it can be applied to return an array of ECG peak locations. NB: This function assumes that the ECG signal has already been through a bandpass or low-pass filter or has little baseline drift.
- resurfemg.preprocessing.ecg_removal.gating(src_signal, gate_peaks, gate_width=205, method=1)¶
Eliminate peaks (e.g. QRS) from src_signal using gates of width gate_width. The gate either filled by zeros or interpolation. The filling method for the gate is encoded as follows: 0: Filled with zeros 1: Interpolation samples before and after 2: Fill with average of prior segment if exists otherwise fill with post segment 3: Fill with running average of RMS (default)
- resurfemg.preprocessing.ecg_removal.pick_highest_correlation_array(components_tuple, ecg_lead)¶
Here we have a function that takes a tuple with the two parts of ICA and the array containing the ECG recording, and finds the ICA component with the highest similarity to the ECG. Data should not have been finally filtered to envelope level
- Parameters:
components_tuple (Tuple[ndarray, ndarray]) – tuple of two arrays representing different signals
ecg_lead (numpy.ndarray) – array containing the ECG recording
- Returns:
Array with the highest correlation coefficient to the ECG lead (should usually be the ECG)
- Return type:
- resurfemg.preprocessing.ecg_removal.pick_highest_correlation_array_multi(components, ecg_lead)¶
Here we have a function that takes a tuple with n parts of ICA and the array defined by the user as the ECG recording, and finds the ICA component with the highest similarity to the ECG. Data should not have been finally filtered to envelope level
- Parameters:
components (ndarray) – n-dimensional array representing different components. Each row is a component.
ecg_lead (numpy.ndarray) – array containing the ECG recording
- Returns:
Index of the array with the highest correlation coefficient to the ECG lead (should usually be the ECG)
- Return type:
- resurfemg.preprocessing.ecg_removal.pick_lowest_correlation_array(components_tuple, ecg_lead)¶
Here we have a function that takes a tuple with the two parts of ICA and the array containing the ECG recording, and finds the ICA component with the lowest similarity to the ECG. Data should not have been finally filtered to envelope level
- Parameters:
components_tuple (Tuple[ndarray, ndarray]) – tuple of two arrays representing different signals
ecg_lead (numpy.ndarray) – array containing the ECG recording
- Returns:
Array with the lowest correlation coefficient to the ECG lead (should usually be the EMG as opposed to ECG)
- Return type:
- resurfemg.preprocessing.ecg_removal.pick_more_peaks_array(components_tuple)¶
Here we have a function that takes a tuple with the two parts of ICA, and finds the one with more peaks and anti-peaks. The EMG if without a final envelope will have more peaks
Note
Data should not have been finally filtered to envelope level