pecg package¶
pecg.Preprocessing¶
- class pecg.Preprocessing.Preprocessing(signal: numpy.array, fs: int)[source]¶
Bases:
object
The Preprocessing class provides some routines for pre-filtering
the ECG signal as well as estimating the signal quality.
- Parameters
signal – the ECG signal as a ndarray, with shape (L, N) when L is the number of channels or leads and N i the number of samples.
fs – The sampling frequency of the signal.
import pecg from pecg import Preprocessing as Pre pre = Pre.Preprocessing(signal, fs)
- notch(n_freq: int)[source]¶
The notch function applies a notch filter in order to remove the power line artefacts.
- Parameters
n_freq – The expected center frequency of the power line interference. Typically, 50Hz (e.g. Europe) or 60Hz (e.g. US)
- Returns
The filtered ECG signal, with shape (L, N) when L is the number of channels or leads and N is the number of samples.
f_notch = 60 filtered_ecg_rec = pre.notch(f_notch)
- bpfilt()[source]¶
The bpfilt function applies a bandpass filter between [0.67, 100] Hz,
this function uses a zero-phase Butterworth filter with 75 coefficients.
- Returns
The filtered ECG signal, with shape (L, N) when L is the number of channels or leads and N is the number of samples.
filtered_ecg_rec = pre.bpfilt()
- bsqi(peaks: numpy.array = array([], dtype=float64), test_peaks: numpy.array = array([], dtype=float64))[source]¶
bSQI is an automated algorithm to detect poor-quality electrocardiograms.
This function is based on the following paper:1.
The implementation itself is based on: 2.
- 1
Li, Qiao, Roger G. Mark, and Gari D. Clifford.
“Robust heart rate estimation from multiple asynchronous noisy sources
using signal quality indices and a Kalman filter.”
Physiological measurement 29.1 (2007): 15.
- 2
Behar, J., Oster, J., Li, Q., & Clifford, G. D. (2013).
ECG signal quality during arrhythmia and its application to false alarm reduction.
IEEE transactions on biomedical engineering, 60(6), 1660-1666.
- Parameters
peaks – Optional input- Annotation of the reference peak detector (Indices of the peaks), as an ndarray of shape (L,N), when L is the number of channels or leads and N is the number of peaks. If peaks are not given, the peaks are calculated with epltd detector.
test_peaks – Optional input - Annotation of the anther reference peak detector (Indices of the peaks), as an ndarray of shape (L,N), when N is the number of peaks. If test peaks are not given, the test peaks are calculated with xqrs detector.
- Returns
The ‘bsqi’ score, a flout between 0 and 1.
epltd_peaks = fp.epltd() xqrs_peaks = fp.xqrs() bsqi_score = pre.bsqi(epltd_peaks, xqrs_peaks) if bsqi_score < 0.8: print('It's a bad quality ECG recording!')