CardioPy: An open-source heart rate variability toolkit for single-lead EKG
and Objective: Heart rate variability (HRV) is a promising clinical marker of health and disease. Although HRV methodology is relatively straightforward, accurate detection of R-peaks remains a significant methodological challenge; this is especially true for single-lead EKG signals, which are routinely collected alongside EEG monitoring and for which few software options exist. Most developed algorithms with favorable R-peak detection profiles require significant mathematical and computational
... proficiency for implementation, providing a significant barrier for clinical research. Our objective was to address these challenges by developing a simple, free, and open-source software package for HRV analysis of single-lead EKG signals. Methods: CardioPy was developed in python and optimized for short-term (5-minute) single-lead EKG recordings. CardioPy's R-peak detection trades full automation and algorithmic complexity for an adaptive thresholding mechanism, manual artifact removal and parameter adjustment. Standard time and frequency domain analyses are included, such that CardioPy may be used as a stand-alone HRV analysis package. An example use-case of HRV across wakefulness and sleep is presented and results validated against the widely used Kubios HRV software. Results: HRV analyses were conducted in 66 EKG segments collected from five healthy individuals. Parameter optimization was conducted or each segment, requiring ~1-3 minutes of manual inspection time. With optimization, CardioPy's R-peak detection algorithm achieved a mean sensitivity of 100.0% (SD 0.05%) and positive predictive value of 99.8% (SD 0.20%). HRV results closely matched those produced by Kubios HRV, both by eye and by quantitative comparison; CardioPy power spectra explained an average of 99.7% (SD 0.50%) of the variance present in Kubios spectra. HRV analyses showed significant group differences between brain states; SDNN, low frequency power, and low frequency-to-high frequency ratio were reduced in slow wave sleep compared to wakefulness. Conclusions: CardioPy provides an accessible and transparent tool for HRV analyses. Manual parameter optimization and artifact removal allow granular control over data quality and a highly reproducible analytic pipeline, despite additional time requirements. Future versions are slated to include automatic parameter optimization and a graphical user interface, further reducing analysis time and improving accessibility.