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(n_freq=60)
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.

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 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!')

pecg.Example

pecg.Example.load_example(ecg_type: str) -> (<class 'numpy.ndarray'>, <class 'int'>)[source]

The load_example function loads an ECG signal from the PhysioNet open source datasets. There are three types of ECG that might be downloded: longe single lead ECG, ‘12-lead’ and a Holter with two channels.

Parameters

ecg_type – The type of the signal that you would like download: ‘single-lead’, ‘12-lead’ and ‘Holter’.

Returns

  • signal: the ECG signal as a ndarray, with shape (L, N) when L is the number of channels or leads and N is the number of samples.

  • fs: The sampling frequency of the signal [Hz].

import pecg
from pecg.Example import load_example
signal, fs = load_example(ecg_type='12-lead')

Module contents