pecg package

pecg.Example

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

The load_example function loads ECG signal from some of the PhysioNet open source datasets. There are three types of ECG examples: long single lead ECG, 12-lead and a Holter with two channels.

param ecg_type:

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

return:
  • 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')

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 [Hz].

import pecg
from pecg.Example import load_example
from pecg import Preprocessing as Pre

signal, fs = load_example(ecg_type='single-lead')
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.

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.

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 work of Li et al. [1] and Behar [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 float between 0 and 1.

bsqi_score = pre.bsqi()

pecg.ecg

Module contents