Electrocardiography analysis module

electrocardiography.analyzeECG(rawECGSignal, samplerate, preprocessing=True, highpass=0.5, lowpass=25, min_dist=500, peakThresh=0.3, PeakTreshAbs=False, ibi=True, bpm=True, sdnn=True, sdsd=True, rmssd=True, pnn50=True, pnn20=True, pnn50pnn20=True, freqAnalysis=True, freqAnalysisFiltered=True)[source]

This is a simple entrypoint for ECG analysis.

You can use this function as model for your analysis or to extrapolate several features from an ECG signal.

You can specify which features to evaluate or to exclude, as well as cutoff for frequencies and filter.

Parameters:
  • data (list) – ECG signal
  • samplerate (int) – samplerate of the signal in Hz
  • preprocessing (boolean) – whether to perform a simple preprocessing of the signal automatically
  • highpass (boolean) – cutoff frequency for the high pass filter
  • lowpass (boolean) – cutoff frequency for the low pass filter
  • min_dist (int) – minimum distance between peaks in ms. Used for peak detection
  • peakThresh (float) – Normalized threshold. Only the peaks with amplitude higher than the threshold will be detected by the peak detection utils
  • PeakTreshAbs (boolean) – If True, the peakThresh value will be interpreted as an absolute value, instead of a normalized threshold.
  • ibi (boolean) – whether or not to perform the IBI analysis
  • bpm (boolean) – whether or not to perform the BPM analysis
  • sdnn (boolean) – whether or not to perform the sdnn analysis
  • sdsd (boolean) – whether or not to perform the sdsd analysis
  • rmssd (boolean) – whether or not to perform the rmssd analysis
  • pnn50 (boolean) – whether or not to perform the pNN50 analysis
  • pnn20 (boolean) – whether or not to perform the pNN20 analysis
  • pnn50pnn20 (boolean) – whether or not to perform the pNN50 on pNN20 ratio analysis
  • freqAnalysis (boolean) – whether or not to perform a frequency analysis analysis
  • freqAnalysisFiltered (boolean) – whether or not to perform a frequency analysis automatically filtering the signal
Returns:

a dictionary containing the results of the ECG analysis

Return type:

list

electrocardiography.butter_highpass(cutoff, fs, order=5)[source]

This functions generates a higpass butter filter

Parameters:
  • cutoff (float) – cutoff frequency
  • cutoff – cutoff frequency
  • fs (float) – samplerate of the signal
  • order (int) – order of the Butter Filter
Returns:

butter highpass filter

Return type:

list

electrocardiography.butter_highpass_filter(data, cutoff, fs, order)[source]

This functions apply a butter highpass filter to a signal

Parameters:
  • data (list) – ECG signal
  • cutoff (float) – cutoff frequency
  • cutoff – cutoff frequency
  • fs (float) – samplerate of the signal
  • order (int) – order of the Butter Filter
Returns:

highpass filtered ECG signal

Return type:

list

electrocardiography.butter_lowpass(cutoff, fs, order=5)[source]

This functions generates a lowpass butter filter

Parameters:
  • cutoff (float) – cutoff frequency
  • cutoff – cutoff frequency
  • fs (float) – samplerate of the signal
  • order (int) – order of the Butter Filter
Returns:

butter lowpass filter

Return type:

list

electrocardiography.butter_lowpass_filter(data, cutoff, fs, order)[source]

This functions apply a butter lowpass filter to a signal

Parameters:
  • data (list) – ECG signal
  • cutoff (float) – cutoff frequency
  • cutoff – cutoff frequency
  • fs (float) – samplerate of the signal
  • order (int) – order of the Butter Filter
Returns:

lowpass filtered ECG signal

Return type:

list

electrocardiography.getBPM(npeaks, nsample, samplerate)[source]

This function returns the BPM of a discrete heart signal.

Input: number of peaks of the ECG signal,number of samples, samplerate of the signal

Output: BPM

Parameters:
  • npeak (int) – number of peaks of the ECG signal
  • nsample (int) – number of samples of the ECG signal
  • samplerate (int) – samplerate of the signal in Hz
Returns:

BPM of the ECG signal

Return type:

float

electrocardiography.getFrequencies(rawECGSignal, samplerate, llc=0.04, ulc=0.15, lhc=0.15, uhc=0.4, lvlc=0.0033, hvlc=0.04)[source]

This functions returns the sum of the PSD of low Frequencies, high frequencies and very low frequencies.

Default Values have been adapted from: Blood, J. D., Wu, J., Chaplin, T. M., Hommer, R., Vazquez, L., Rutherford, H. J., … & Crowley, M. J. (2015). The variable heart: high frequency and very low frequency correlates of depressive symptoms in children and adolescents. Journal of affective disorders, 186, 119-126.

It returns a dictionary with the values for high, low and very low frequencies

Parameters:
  • rawECGSignal (list) – raw ECG signal
  • samplerate (int) – samplerate of the ECG signal
  • llc (float) – lower cutoff of low frequencies
  • ulc (float) – upper cutoff of low frequencies
  • lhc (float) – lower cutoff of high frequencies
  • uhc (float) – high cutoff of high frequencies
  • lvlc (float) – lower cutoff of very low frequencies
  • uvlc (float) – upper cutoff of very low frequencies
Returns:

a dictionary containing the results of the frequency analysis

Return type:

dictionary

electrocardiography.getIBI(peaks, samplerate)[source]

This function returns the IBI of a discrete heart signal.

Input: peaks and samplerate of the ECG signal

Output: IBI in ms

Parameters:
  • peaks (list) – list of peaks of the ECG signal
  • samplerate (int) – samplerate of the signal in Hz
Returns:

the mean IBI of the ECG signal

Return type:

IBI (in ms) as float value

electrocardiography.getPNN20(peaks, samplerate)[source]

This functions evaluate pNN20, the proportion of differences greater than 20ms.

Input: peaks of the ECG signal,samplerate of the signal

Output: proportion of number of pairs of successive peaks that diffear by more than 20ms

Parameters:
  • peaks (list) – list of peaks in the ECG signal
  • samplerate (int) – samplerate of the signal in Hz
Returns:

the pNN20 of the ECG signal

Return type:

float

electrocardiography.getPNN50(peaks, samplerate)[source]

This functions evaluate pNN50, the proportion of differences greater than 50ms.

Input: peaks of the ECG signal,samplerate of the signal

Output: proportion of number of pairs of successive peaks that diffear by more than 50ms

Parameters:
  • peaks (list) – list of peaks in the ECG signal
  • samplerate (int) – samplerate of the signal in Hz
Returns:

the pNN50 of the ECG signal

Return type:

float

electrocardiography.getRMSSD(peaks, samplerate)[source]

This functions evaluate the root mean square of successive differences between adjacent R-R intervals.

RMSSD = sqrt((1 / (N - 1)) * sum(i=1 –> N)(RRdiff i - mean(RRdiff))**2)

Input: peaks of the ECG signal,samplerate of the signal.

Output: the root mean square of successive differences between adjacent R-R intervals.

Parameters:
  • peaks (list) – list of peaks in the ECG signal
  • samplerate (int) – samplerate of the signal in Hz
Returns:

the RMSSD of the ECG signal

Return type:

float

electrocardiography.getSDNN(peaks, samplerate)[source]

This functions evaluate the standard deviation of intervals between heartbeats. It is often calculated over 24h period, or over short peridos of 5 mins.

SDNN reflects all the cyclic components responsible for variability in the period of recording, therefore it represents total variability

SDNN = sqrt((1/N-1) * sum(i=1 –> N)(rri - rrmean)^2)

Input: peaks of the ECG signal,samplerate of the signal

Output: standard deviations of Intervals between heartbeats.

Parameters:
  • peaks (list) – list of peaks in the ECG signal
  • samplerate (int) – samplerate of the signal in Hz
Returns:

the SDNN of the ECG signal

Return type:

float

electrocardiography.getSDSD(peaks, samplerate)[source]

This functions evaluate the the standard deviation of successive differences between adjacent R-R intervals.

SDSD: sqrt((1 / (N - 1)) * sum(i=1 –> N)(RR i - mean(RR))**2)

Input: peaks of the ECG signal,samplerate of the signal

Output: the standard deviation of successive differences between adjacent R-R intervals

Parameters:
  • peaks (list) – list of peaks in the ECG signal
  • samplerate (int) – samplerate of the signal in Hz
Returns:

the SDSD of the ECG signal

Return type:

float