Heart Rate Variability

Initialize NeuroAnalyzer
using NeuroAnalyzer
using CairoMakie
CairoMakie.activate!(type = "png")
eeg = load("files/eeg.hdf")

Heart Rate Variability (HRV) is the physiological phenomenon of variation in the time interval between heartbeats. It reflects the autonomic nervous system’s (ANS) regulation of heart activity and is influenced by physiological and psychological factors. HRV is widely used in clinical, research, and wellness applications to assess autonomic balance, stress, cardiovascular health, and emotional regulation.

HRV measures the fluctuations in the time intervals between consecutive heartbeats (R-R intervals in ECG).

It is not the same as heart rate (which measures the average number of beats per minute). Instead, HRV reflects the complex interplay between the sympathetic (fight-or-flight) and parasympathetic (rest-and-digest) branches of the autonomic nervous system.

HRV provides insights into:

  • Autonomic nervous system (ANS) function: Balance between sympathetic and parasympathetic activity.
  • Cardiovascular health: Predicts risk of heart disease, hypertension, and arrhythmias.
  • Stress and emotional regulation: Lower HRV is associated with chronic stress, anxiety, and depression.
  • Physical fitness: Athletes often exhibit higher HRV, indicating better recovery and performance.
  • Sleep quality: HRV patterns can indicate sleep stages and quality.
  • Aging: HRV tends to decrease with age.

In NeuroAnalyzer, HRV analysis is performed using ECG data, where the R-peaks of the ECG signal are detected to compute NN intervals (the time between two successive normal heartbeats). Below is a detailed explanation of HRV, its measurement, and the time-domain parameters used for analysis.

  1. Mean NN Interval (MENN)
  • Definition: The mean of all NN intervals.
  • Formula: \(\text{MENN} = \frac{1}{N} \sum_{i=1}^N \text{NN}_i\) where:
    • \(N\): Total number of NN intervals.
    • \(\text{NN}_i\): \(i\)-th NN interval.
  • Interpretation:
    • Represents the average heart rate (in milliseconds).
    • Higher values indicate slower heart rate (bradycardia).
    • Lower values indicate faster heart rate (tachycardia).
  1. Median NN Interval (MDNN)
  • Definition: The median of all NN intervals.
  • Formula:
    • Sort the NN intervals and select the middle value.
  • Interpretation:
    • Less sensitive to outliers than the mean.
    • Provides a robust estimate of central tendency.
  1. Variance of NN Intervals (VNN)
  • Definition: The variance of NN intervals.
  • Formula: \(\text{VNN} = \frac{1}{N-1} \sum_{i=1}^N (\text{NN}_i - \text{MENN})^2\)
  • Interpretation:
    • Reflects overall HRV.
    • Higher variance indicates greater HRV.
  1. Standard Deviation of NN Intervals (SDNN)
  • Definition: The standard deviation of NN intervals.
  • Formula: \(\text{SDNN} = \sqrt{\text{VNN}}\)
  • Interpretation:
    • Most widely used time-domain HRV metric.
    • Reflects overall HRV and autonomic balance.
    • Higher SDNN: Better autonomic regulation, lower stress.
    • Lower SDNN: Poor autonomic regulation, chronic stress, or cardiovascular disease.
  1. Root Mean Square of Successive Differences (RMSSD)
  • Definition: The square root of the mean of the squares of successive NN interval differences.
  • Formula: \(\text{RMSSD} = \sqrt{\frac{1}{N-1} \sum_{i=1}^{N-1} (\text{NN}_{i+1} - \text{NN}_i)^2}\)
  • Interpretation:
    • Reflects short-term HRV and parasympathetic (vagal) activity.
    • Higher RMSSD: Stronger vagal tone, better stress resilience.
    • Lower RMSSD: Weakened vagal tone, stress, or health issues.
  1. Standard Deviation of Successive Differences (SDSD)
  • Definition: The standard deviation of successive NN interval differences.
  • Formula: \(\text{SDSD} = \sqrt{\frac{1}{N-1} \sum_{i=1}^{N-1} (\text{NN}_{i+1} - \text{NN}_i - \text{mean})^2}\)
  • Interpretation:
    • Similar to RMSSD but less commonly used.
    • Reflects variability in short-term HRV.
  1. NN50
  • Definition: The number of pairs of successive NN intervals that differ by more than 50 ms.
  • Formula: \(\text{NN50} = \text{Count}(\text{NN}_{i+1} - \text{NN}_i > 50 \text{ ms})\)
  • Interpretation:
    • Reflects short-term HRV.
    • Higher NN50: Better vagal tone.
  1. Proportion of NN50 (pNN50)
  • Definition: The proportion of NN50 divided by the total number of NN intervals
  • Formula: \(\text{pNN50} = \frac{\text{NN50}}{N} \times 100\%\)
  • Interpretation:
    • Normalized version of NN50
    • Higher pNN50 Stronger parasympathetic activity.
  1. NN20
  • Definition: The number of pairs of successive NN intervals that differ by more than 20 ms.
  • Formula: \(\text{NN20} = \text{Count}(\text{NN}_{i+1} - \text{NN}_i > 20 \text{ ms})\)
  • Interpretation:
    • Similar to NN50 but more sensitive to smaller changes.
  1. Proportion of NN20 (pNN20)
  • Definition: The proportion of NN20 divided by the total number of NN intervals.
  • Formula: \(\text{pNN20} = \frac{\text{NN20}}{N} \times 100\%\)
  • Interpretation:
    • Normalized version of NN20.
    • Higher pNN20: Better short-term HRV.

Reference Values

Parameter Typical Range (Healthy Adults)
SDNN 50–150 ms
RMSSD 20–100 ms
pNN50 10–50%

For a comprehensive HRV analysis, time-domain metrics are often combined with:

Frequency-Domain Metrics:

  • LF (Low Frequency): 0.04–0.15 Hz (sympathetic + parasympathetic activity).
  • HF (High Frequency): 0.15–0.40 Hz (parasympathetic activity).
  • LF/HF Ratio: Reflects sympatho-vagal balance.

Non-Linear Metrics:

  • Poincaré Plot: Visualizes short-term and long-term HRV.
  • Sample Entropy (SampEn): Measures complexity of HRV.
  • Detrended Fluctuation Analysis (DFA): Assesses fractal properties of HRV.

HRV Analysis in NeuroAnalyzer

Detecting NN intervals:

nn_seg, r_idx = hrv_detect(eeg)

Visualize peaks to check if were detected correctly:

ch = get_channel(eeg; ch = "ecg")
ecg = eeg.data[ch, 1:(10 * sr(eeg)), 1][:] # 10 seconds
t = eeg.time_pts[1:(10 * sr(eeg))]         # 10 seconds

fig, ax = lines(t, ecg)
vlines!(ax,
        t[r_idx[1:10]],
        linestyle=:dot,
        color=:red)
fig

Analyzing peaks properties:

hrv = hrv_analyze(nn_seg)
println(" MENN: $(hrv.menn)")
println(" MDNN: $(hrv.mdnn)")
println("  VNN: $(hrv.vnn)")
println(" SDNN: $(hrv.sdnn)")
println("RMSSD: $(hrv.rmssd)")
println(" SDSD: $(hrv.sdsd)")
println(" NN50: $(hrv.nn50)")
println("PNN50: $(hrv.pnn50)")
println(" NN20: $(hrv.nn20)")
println("PNN20: $(hrv.pnn20)")
 MENN: 941.233
 MDNN: 941.406
  VNN: 15653.256
 SDNN: 125.113
RMSSD: 175.458
 SDSD: 175.541
 NN50: 114
PNN50: 0.107
 NN20: 136
PNN20: 0.128