HRV

This is a Python module/tutorial for performing heart rate variability (HRV) analysis on electrocardiogram (ECG) time series.

Dependencies

Licence

This code is licensed under the MIT License - see the LICENSE.md file for details.

R-Peak Detection

Pan-Tompkins

Implements the popular QRS complex detection algorithm introduced in Pan, et al (1985). The algorithm uses filtering, adaptive thresholding, and criteria based on human cardiac physiology to detect QRS complexes in the face of noise and quickly changing and diverse ECG morphologies. This function implements the Pan-Tompkins algorithm as it was originally published, along with two modifications which include additional filtering and eliminating potential QRS detections that occur within the refractory period. Since this algorithm is often used to find R-peak locations (and not just general QRS detection) for applications such as Heart Rate Variability (HRV) analysis, this function also performs a neighborhood search around the final QRS detection locations to find exact R-peak locations.

Code Example

    R_peak_locs = panTompkins(ECG, fs, plot = 1)

HRV Features

Time Domain

Time domain features are perhaps the simplist method computationally for performning HRV analysis. Following R-peak detection (see PanTompkins), ectopic beats are removed to produce a normal-to-normal (NN) interval series. Various statistical measures can then be extracted from the time series that provide insights into heart rate linear dynamics.

Code Example

timeDomainFeats = timDomain(RR_interval_series)
Label         Description                                                      
ANN Average NN interval
SDNN Standard deviation of NN intervals
SDSD Standard deviation of successive NN intervals
NN50 Number of successive NN intervals differing by more than 50 ms
pNN50 Proportion of successive NN intervals differing by more than 50 ms
rMMSD Root mean square of successive NN intervals
MedianNN Median of NN intervals

Frequency Domain

Spectral analysis is a standard in HRV analysis. Features are extracted from the power spectral density (PSD) of the NN interval time series. The PSD within various frequency bands is estimated using Welch's method. The most common frequency bands under investigation are the very low frequency (VLF) band, the low frequency (LF) band, and the high frequency (HF) band. The spectral power distributions across these bands has been shown to provide insight into modulations in autnomic nervous system (ANS) activity.

Code Example

freqDomainFeats = frequencyDomain(RR_interval_series)
Label Description
VLF Power Log of normalized spectral power between 0.003 Hz and 0.04 Hz
LF Power Log of normalized spectral power between 0.04 Hz and 0.15 Hz
HF Power Log of normalized spectral power between 0.15 Hz and 0.4 Hz
LF/HF Ratio Ratio between LF and HF spectral power

The frequencyDomain function also has the capability to compute the frequency domain features listed in the table above using the spectral boundary adaptation method described in X. Long, et al (2014). The idea behind using adapted spectral bands is to account for the time varying behavior of these bands (e.g. whilst sleeping) and to potentially reduce the within – and between – subject frequency domain feature variabilities. This method works by adapting the bands according to the peak frequencies found within the traditional spectral bands and setting their lower and upper bounds to values based off specified bandwidths.

           

Poincare

Poincare plots are an important visualization technique for quantifying the non-linear characteristics of the RR interval time series. The geometrical descriptors that can be extracted from the poincare plot with this package have been shown to provide insights into short and long term HRV trends. This includes parameters derived from the ellipse fitting method described in Brennan, et al (2001) and the heart rate asymmetry (HRA) method that quantifies accelerations/decelerations in heart rate introduced in Guzik, Przemyslaw, et al (2006).

Multifractal Detrended Fluctuation Analysis (MF-DFA)

Multi-fractal detrended fluctuation analysis (MF-DFA) introduced in Kantelhardt, et al. MF-DFA is based on the standard detrended fluctuation analysis (DFA) introduced by Peng, et al (1995).

Code Example

from DFA import scalingExponent
scaleExp = scalingExponent(timeSeries, lowerScaleLimit = 10, upperScaleLimit = 40, scaleDensity = 30, m = 1, q = 2, plot = 1)

The algorithm involves dividing the integrated RR interval time series into non-overlapping segments of equal length, s.

A polynomial is then fitted to each non-overlapping segment. Linear, quadratic, cubic, and/or other higher polynomials may be used in the fitting procedure. These DFA orders differ in their ability to eliminate various types of trends from the time series. Thus, an estimation of the type of time series trend can be captured via comparison of the different DFA orders, as seen below.

Following the polynomial fit, the average of all the segments are obtained via:
where *q* is the order of the fluctuation coefficient. When *q* = 2, the MF-DFA procedure simplifies to standard DFA. It may be of the user’s interests to explore how the *q*-dependent fluctuation coefficients *Fq(s)* depend on scale *s* for various values of *q*. The above procedure is repeated over various scales to provide a relationship between the qth order fluctuation coefficient and scale. The final step of the MF-DFA procedure is determining the scaling behavior of the various fluctuation coefficients by generating a log-log plot of *Fq(s)* versus *s*. In general, *Fq(s)* increases with increases in scale, with a linear relationship on the double log plot indicating the presence of scaling. This behavior can be characterized by a scaling exponent α, which is the slope of the line of best fit describing the relationship between *Fq(s)* and scale.
### Multiscale Entropy (MSE) Implements the multiscale entropy (MSE) algorithm introduced in [Costa, *et al* (2002)](http://dbiom.org/files/publications/Peng_MultiscaleEntropyAnalysisComplexPhysiologicTimeSeries.pdf). MSE can be used as a tool for measuring the complexity of the RR tachogram. The MSE algorithm works by computing sample entropy at multiple scales (for various "coarse-grained" series), making it advantageious for analyzing features related to structure on scales other than the shortest one. Details on computing sample entropy are detailed in [Pincas, *et al* (1991)](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC51218/pdf/pnas01056-0271.pdf). #### Code Example ``` import multiScaleEntropy as MSE entropyMeasure = MSE.multiScaleEntropy(RR_interval_series, mseScales = np.arange(1,11), r = 0.2 * np.std(RRints), m = 2) ``` As seen below, applying the MSE algorithm to (uncorrelated) white noise results in a monotonically decreasing entropy measure, while its application to pink noise (or 1/f noise) reveals structure across multiple scales.