Introduction to Heart Rate Variability (HRV) Analysis

Benjamin Gallois PhD
5 min readSep 29, 2023

--

https://unsplash.com/photos/rCOWMC8qf8A

Introduction

Heart rate variability (HRV) encompasses all the analyses conducted on the time intervals between individual heartbeats. These time intervals exhibit subtle fluctuations and can be associated with various physiological states such as health conditions, fatigue, and mental health, among others.

HRV measurements are now integrated into smartwatches and bracelets, and they can be monitored through photoplethysmography (PPG) heart rate recording using a smartphone camera. However, the multitude of metrics generated by these apps and devices can often be bewildering. In this post, we will delve into how these metrics are calculated using Python and the SciPy ecosystem, providing a clearer understanding of HRV analysis (notebook included).

Data

Description

To illustrate the process of conducting HRV analysis, we will utilize freely available ECG recordings. The ERG recordings can be read using the https://wfdb.readthedocs.io/en/latest/ library, which supports the most common ERG standard formats. Additionally, an ECG dataset is accessible within the SciPy dataset repository.

An ECG recording typically consists of a repetitive pattern: a P wave, a QRS complex lasting between 80 and 100 milliseconds, and a T wave. These components correspond to specific electrical events in the heart: the P wave signifies atrial depolarization, the QRS complex represents ventricular depolarization, and the T wave indicates ventricular repolarization. When examining an ECG, it is evident that the most prominent peak is the R wave within the QRS complex. Consequently, the subsequent analysis will focus on detecting this R wave peak.

https://en.wikipedia.org/wiki/QRS_complex#/media/File:SinusRhythmLabels.svg

Pre-processing

Once we’ve loaded the ECG data, our initial step involves applying a Wiener filter to eliminate any noise within the signal effectively. Following noise reduction, we proceed to detect the peaks corresponding to the R wave within the QRS complex. From these detected peaks, we can derive a series of RR-intervals, which represent the time intervals between two consecutive R wave peaks.

R peaks detection.

Next, we normalize these RR-intervals, a process that eliminates physiological and sensor-related artifacts. This normalization retains only the RR-intervals that do not deviate by more than 2 standard deviations from the mean of all RR-intervals. These filtered intervals are called NN-intervals and serve as the fundamental data for all subsequent analyses.

Time analysis

The initial phase of our analysis focuses on time-domain parameters, providing valuable insights into heart rate variability (HRV).

  1. Standard Deviation of NN-Intervals (SDNN): SDNN serves as our first metric, calculated as the sample standard deviation of the NN-intervals. SDNN quantifies overall HRV and measures the heart’s variability in beat-to-beat intervals.
  2. Percentage of Successive NN-intervals that Differ by More than 50 ms (pNN50): Our second parameter, pNN50, is computed by determining the percentage of NN-intervals with a duration exceeding 50 milliseconds.
  3. Root Mean Square of Successive NN Interval Differences (RMSSD): RMSSD represents the third key parameter. It is calculated as the square root of the mean of the squared differences between successive NN-intervals.

In many applications, such as health monitoring devices, units are often not explicitly specified, but these parameters are typically presented in milliseconds.

Additionally, we can compute the instantaneous heart rate, which reflects the number of depolarizations within a 6-second interval multiplied by 10 to express it as beats per minute (bpm). In practical terms, you can calculate it using the formula: 60000 divided by the NN-intervals in ms. This provides a more immediate measure of heart rate, making it useful for monitoring rapid changes in heart rhythm.

Instantaneous heart rate.

Frequency analysis

In the second analysis phase, we delve into the frequency domain analysis of the NN-intervals. Given that the NN-intervals constitute an irregular time series, we employ interpolation techniques to transform it into a regular time series with equally spaced data points. This transformation enables us to utilize frequency analysis tools such as the Fourier Transform.

NN-intervals time series resampling.

To compute the Power Spectral Density (PSD), we employ Welch’s method, a technique that divides the data into overlapping segments, computes a periodogram for each segment, and then averages all these periodograms. The PSD represents the squared signal unit divided by frequency, so to achieve this, we convert the NN-intervals into seconds, ensuring that the PSD is expressed in seconds cubed (s³).

FFT-based Welch’s Periodogram.

Two key parameters that we can derive from the PSD are:

  1. Power of the Low-Frequency Band (0.04–0.15 Hz) — LF: This parameter is computed by integrating the PSD within the specified low-frequency range.
  2. Power of the High-Frequency Band (0.15–0.4 Hz) — HF: Similar to LF, HF is calculated by integrating the PSD within the designated high-frequency range.

Commonly, applications do not explicitly state the units for LF and HF, yet these units are derived by performing an integral on the PSD with respect to frequency. Given that the PSD is expressed in seconds cubed (s³) and the frequency in hertz (s-¹), LF and HF are subsequently expressed in seconds squared (s²). It is customary to represent them in milliseconds squared (ms²) for practical ease and clarity.

Conclusion

HRV analysis is frequently performed opaquely by various apps and smart devices, resulting in outputs that lack clear units of measurement. In this discussion, we have demonstrated a straightforward method for computing these HRV parameters using both time and frequency analysis. It’s important to emphasize the significance of the units employed when describing NN-intervals to ensure the accuracy and meaningful interpretation of these values. By understanding the units and employing consistent conventions, we can obtain HRV results that are both reliable and comprehensible.

Code

--

--

Benjamin Gallois PhD

🔬PhD in physics 🌐Open-source dev 🚀FastTrack creator 💼Freelance in computer vision & blockchain 🚴‍♂️Competitive cyclist 🏆Sports science enthusiast