scientific-skills/neurokit2/references/hrv.md
Heart Rate Variability (HRV) reflects the variation in time intervals between consecutive heartbeats, providing insights into autonomic nervous system regulation, cardiovascular health, and psychological state. NeuroKit2 provides comprehensive HRV analysis across time, frequency, and nonlinear domains.
Compute all available HRV indices at once across all domains.
hrv_indices = nk.hrv(peaks, sampling_rate=1000, show=False)
Input:
peaks: Dictionary with 'ECG_R_Peaks' key or array of R-peak indicessampling_rate: Signal sampling rate in HzReturns:
This is a convenience wrapper that combines:
hrv_time()hrv_frequency()hrv_nonlinear()Compute time-domain HRV metrics based on inter-beat intervals (IBIs).
hrv_time = nk.hrv_time(peaks, sampling_rate=1000)
Basic interval statistics:
HRV_MeanNN: Mean of NN intervals (ms)HRV_SDNN: Standard deviation of NN intervals (ms)
HRV_RMSSD: Root mean square of successive differences (ms)
Successive difference measures:
HRV_SDSD: Standard deviation of successive differences (ms)
HRV_pNN50: Percentage of successive NN intervals differing >50ms
HRV_pNN20: Percentage of successive NN intervals differing >20ms
Range measures:
HRV_MinNN, HRV_MaxNN: Minimum and maximum NN intervals (ms)HRV_CVNN: Coefficient of variation (SDNN/MeanNN)
HRV_CVSD: Coefficient of variation of successive differences (RMSSD/MeanNN)Median-based statistics:
HRV_MedianNN: Median NN interval (ms)
HRV_MadNN: Median absolute deviation of NN intervals
HRV_MCVNN: Median-based coefficient of variationAdvanced time-domain:
HRV_IQRNN: Interquartile range of NN intervalsHRV_pNN10, HRV_pNN25, HRV_pNN40: Additional percentile thresholdsHRV_TINN: Triangular interpolation of NN interval histogramHRV_HTI: HRV triangular index (total NN intervals / histogram height)Analyze HRV power across frequency bands using spectral analysis.
hrv_freq = nk.hrv_frequency(peaks, sampling_rate=1000, ulf=(0, 0.0033), vlf=(0.0033, 0.04),
lf=(0.04, 0.15), hf=(0.15, 0.4), vhf=(0.4, 0.5),
psd_method='welch', normalize=True)
Ultra-Low Frequency (ULF): 0-0.0033 Hz
Very-Low Frequency (VLF): 0.0033-0.04 Hz
Low Frequency (LF): 0.04-0.15 Hz
High Frequency (HF): 0.15-0.4 Hz
Very-High Frequency (VHF): 0.4-0.5 Hz
Absolute power (ms²):
HRV_ULF, HRV_VLF, HRV_LF, HRV_HF, HRV_VHF: Power in each bandHRV_TP: Total power (variance of NN intervals)HRV_LFHF: LF/HF ratio (sympathovagal balance)Normalized power:
HRV_LFn: LF power / (LF + HF) - normalized LFHRV_HFn: HF power / (LF + HF) - normalized HFHRV_LnHF: Natural logarithm of HF (log-normal distribution)Peak frequencies:
HRV_LFpeak, HRV_HFpeak: Frequency of maximum power in each bandWelch's method (default):
hrv_freq = nk.hrv_frequency(peaks, sampling_rate=1000, psd_method='welch')
Lomb-Scargle periodogram:
hrv_freq = nk.hrv_frequency(peaks, sampling_rate=1000, psd_method='lomb')
Multitaper method:
hrv_freq = nk.hrv_frequency(peaks, sampling_rate=1000, psd_method='multitapers')
Burg autoregressive:
hrv_freq = nk.hrv_frequency(peaks, sampling_rate=1000, psd_method='burg', order=16)
LF/HF Ratio:
HF Power:
Recording Requirements:
Compute complexity, entropy, and fractal measures reflecting autonomic dynamics.
hrv_nonlinear = nk.hrv_nonlinear(peaks, sampling_rate=1000)
Poincaré plot: NN(i+1) vs NN(i) scatter plot geometry
HRV_SD1: Standard deviation perpendicular to line of identity (ms)
HRV_SD2: Standard deviation along line of identity (ms)
HRV_SD1SD2: Ratio SD1/SD2
HRV_SD2SD1: Ratio SD2/SD1
HRV_S: Area of ellipse (π × SD1 × SD2)
HRV_CSI: Cardiac Sympathetic Index (SD2/SD1)
HRV_CVI: Cardiac Vagal Index (log10(SD1 × SD2))
HRV_CSI_Modified: Modified CSI (SD2²/(SD1 × SD2))
Analyzes whether heart rate accelerations and decelerations contribute differently to HRV.
HRV_GI: Guzik's Index - asymmetry of short-term variabilityHRV_SI: Slope Index - asymmetry of long-term variabilityHRV_AI: Area Index - overall asymmetryHRV_PI: Porta's Index - percentage of decelerationsHRV_C1d, HRV_C2d: Deceleration contributionsHRV_C1a, HRV_C2a: Acceleration contributionsHRV_SD1d, HRV_SD1a: Poincaré SD1 for decelerations/accelerationsHRV_SD2d, HRV_SD2a: Poincaré SD2 for decelerations/accelerationsInterpretation:
Approximate Entropy (ApEn):
HRV_ApEn: Regularity measure, lower = more regular/predictableSample Entropy (SampEn):
HRV_SampEn: Improved ApEn, less dependent on data lengthMultiscale Entropy (MSE):
HRV_MSE: Complexity across multiple time scalesFuzzy Entropy:
HRV_FuzzyEn: Fuzzy membership functions for pattern matchingShannon Entropy:
HRV_ShanEn: Information-theoretic randomness measureDetrended Fluctuation Analysis (DFA):
HRV_DFA_alpha1: Short-term fractal scaling exponent (4-11 beats)
HRV_DFA_alpha2: Long-term fractal scaling exponent (>11 beats)
HRV_DFA_alpha1alpha2: Ratio α1/α2
Correlation Dimension:
HRV_CorDim: Dimensionality of attractor in phase spaceHiguchi Fractal Dimension:
HRV_HFD: Complexity and self-similarityPetrosian Fractal Dimension:
HRV_PFD: Alternative complexity measureKatz Fractal Dimension:
HRV_KFD: Waveform complexityQuantifies abnormal short-term fluctuations reflecting autonomic dysregulation.
HRV_PIP: Percentage of inflection points
HRV_IALS: Inverse average length of acceleration/deceleration segmentsHRV_PSS: Percentage of short segments (<3 beats)HRV_PAS: Percentage of NN intervals in alternation segmentsClinical relevance:
HRV_Hurst: Hurst exponent (long-range dependence)HRV_LZC: Lempel-Ziv complexity (algorithmic complexity)HRV_MFDFA: Multifractal DFA indicesRespiratory Sinus Arrhythmia - heart rate modulation by breathing.
rsa = nk.hrv_rsa(peaks, rsp_signal, sampling_rate=1000, method='porges1980')
Methods:
'porges1980': Porges-Bohrer method (band-pass filtered HR around breathing frequency)'harrison2021': Peak-to-trough RSA (max-min HR per breath cycle)Requirements:
Returns:
RSA: RSA magnitude (beats/min or similar units depending on method)Recurrence Quantification Analysis - nonlinear dynamics from phase space reconstruction.
rqa = nk.hrv_rqa(peaks, sampling_rate=1000)
Metrics:
RQA_RR: Recurrence rate - system predictabilityRQA_DET: Determinism - percentage of recurrent points forming linesRQA_LMean, RQA_LMax: Average and maximum diagonal line lengthRQA_ENTR: Shannon entropy of line lengths - complexityRQA_LAM: Laminarity - system trapped in specific statesRQA_TT: Trapping time - duration in laminar statesUse case:
Preprocess RR-intervals before HRV analysis.
processed_intervals = nk.intervals_process(rr_intervals, interpolate=False,
interpolate_sampling_rate=1000)
Operations:
Use case:
Convert interval data (RR, NN) to peak indices for HRV analysis.
peaks_dict = nk.intervals_to_peaks(rr_intervals, sampling_rate=1000)
Use case:
| Analysis | Minimum Duration | Optimal Duration |
|---|---|---|
| RMSSD, pNN50 | 30 sec | 5 min |
| SDNN | 5 min | 5 min (short), 24 hr (long) |
| LF, HF power | 2 min | 5 min |
| VLF power | 5 min | 10+ min |
| ULF power | 24 hr | 24 hr |
| Nonlinear (ApEn, SampEn) | 100-300 beats | 500+ beats |
| DFA | 300 beats | 1000+ beats |
Preprocessing:
# Detect R-peaks with artifact correction
peaks, info = nk.ecg_peaks(cleaned_ecg, sampling_rate=1000, correct_artifacts=True)
# Or manually process intervals
processed = nk.intervals_process(rr_intervals, interpolate=False)
Quality checks:
Task Force Standards (1996):
Normalization:
Inter-individual variability:
Cardiovascular health:
Psychological state:
Athletic performance:
Neuroscience:
Aging: