pecg package

pecg.Preprocessing

class pecg.Preprocessing.Preprocessing(signal: 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. :param 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. :param fs: The sampling frequency of the signal [Hz].

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. :param n_freq: The expected center frequency of the power line interference. Typically, 50Hz (e.g. Europe) or 60Hz (e.g. US) :return: 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.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. :return: 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: array = array([], dtype=float64), test_peaks: 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].

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 jqrs 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.

bsqi_score = pre.bsqi()
if bsqi_score < 0.8:
    print('It's a bad quality ECG recording!')

Module contents