pecg.ecg package

pecg.ecg.FiducialPoints

class pecg.ecg.FiducialPoints.FiducialPoints(signal: numpy.array, fs: int, n_pools: int = 1)[source]

Bases: object

The purpose of the FiducialPoints class is to calculate the fiducial points.

Parameters
  • 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]

  • n_pools – The number of cores to use when calculating the XQRS peaks,the default is 1.

from pecg.ecg import FiducialPoints as Fp

fp = Fp.FiducialPoints(f_ecg_rec, fs)
wavedet(matlab_pat: str, peaks: numpy.array = array([], dtype=float64))[source]

The wavedat function uses the matlab algorithm wavedet, compiled for python.

The algorithm is described in the following paper: 1. The function is calculating

the fiducial points of the ECG recording using wavelet transform.

1

Martinze at el (2004),

A wavelet-based ECG delineator: evaluation on standard databases.

IEEE Transactions on Biomedical Engineering, 51(4), 570-581.

Parameters
  • matlab_pat – path to matlab runtime 2021a directory

  • 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 the epltd detector.

Returns

fiducials: Dictionary that includes indexes for each fiducial point.

matlab_pat = '/usr/local/MATLAB/R2021a'

peaks = fp.epltd()

fiducials = fp.wavedet(matlab_pat, peaks)
epltd()[source]

This function calculates the indexes of the R-peaks with epltd peak detector algorithm.

This algorithm were introduced by 2.

2(1,2)

Pan, Jiapu, and Willis J. Tompkins. “A real-time QRS detection algorithm.”

IEEE Trans. Biomed. Eng 32.3 (1985): 230-236.

Returns

indexes of the R-peaks in the ECG signal, as an ndarray of shape (L,N), when L is the number of channels or leads and N is the number of peaks.

peaks = fp.epltd()
xqrs()[source]

This function wraps the XQRS function of the WFDB package.

Returns

indexes of the R-peaks in the ECG signal, as an ndarray of shape (L,N), when L is the number of channels or leads and N is the number of peaks.

peaks = fp.xqrs()
jqrs(thr: float = 0.8, rp: float = 0.25)[source]

The function is an Implementation of an energy based qrs detector 3. The algorithm is an

adaptation of the popular Pan & Tompkins algorithm 2. The function assumes

the input ecg is already pre-filtered i.e. bandpass filtered and that the

power-line interference was removed. Of note, NaN should be represented by the

value -32768 in the ecg (WFDB standard).

3

Behar, Joachim, Alistair Johnson, Gari D. Clifford, and Julien Oster.

“A comparison of single channel fetal ECG extraction methods.” Annals of

biomedical engineering 42, no. 6 (2014): 1340-1353.

Parameters
  • thr – threshold, default value is 0.8.

  • rp – refractory period (sec), default value is 0.25.

Returns

indexes of the R-peaks in the ECG signal, as an ndarray of shape (L,N), when L is the number of

channels or leads and N is the number of peaks.

peaks = fp.jqrs()

pecg.ecg.Biomarkers

class pecg.ecg.Biomarkers.Biomarkers(signal: numpy.array, fs: int, fiducials: dict)[source]

Bases: object

Parameters
  • signal – The ECG signal as a ndarray.

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

  • fiducials – Dictionary that includes indexes for each fiducial point. this dictionary can be calculated using the FiducialPoints module.

from pecg.ecg import Biomarkers as Obm

obm = Obm.Biomarkers(f_ecg_rec, fs, fiducials)

ints, stat_i = obm.intervals()

waves, stat_w = obm.waves()
intervals()[source]
Returns

intervals_b: Dictionary that includes all the row data, for the **Interval duration and segments* biomarkers.

intervals_statistics: Dictionary that includes the mean, median, min, max, iqr and std, for every **Interval duration and segments* biomarker.

waves()[source]
Returns

waves_b: Dictionary that includes all the row data, for every **Waves characteristic* biomarker.

waves_statistics: Dictionary that includes the mean, median, min, max, iqr and std, for every **Waves characteristic* biomarker.

Module contents