flowchart LR A["Biosignal<br/>(ECG / PPG)"] --> B["Filtering"] B --> C["Beat detection<br/>(R wave / pulse-wave fiducial point)"] C --> D["Compute RR intervals"] D --> E["Detect and correct<br/>artifacts and<br/>ectopic beats"] E --> F["NN intervals"] F --> G1["Time-domain metrics"] F --> G2["Resampling<br/>→ detrending<br/>→ spectral estimation"] F --> G3["Nonlinear metrics"]
4 Measurement and Preprocessing: ECG and Pulse Wave
The accuracy of HRV analysis is determined almost entirely by how accurately the RR intervals can be extracted. An error of a few ms has a large effect on metrics that look at beat-to-beat differences, such as RMSSD.
4.1 Analysis workflow
4.2 Obtaining RR intervals from the ECG
4.2.1 Sampling frequency
The time resolution of the R wave is determined by the sampling period.
- 250 Hz → 4 ms steps, 1000 Hz → 1 ms steps
- Task Force 1996 recommends 250–500 Hz or higher. At lower sampling frequencies, timing accuracy is improved by, e.g., parabolic interpolation of the R-wave peak
- For a person whose resting RMSSD is about 20 ms, even a quantization error of a few ms is not negligible
4.2.2 R-wave detection
A representative method is the Pan–Tompkins algorithm (1985).
- A band-pass filter (about 5–15 Hz) removes baseline wander and high-frequency noise and emphasizes the QRS complex
- Differentiation emphasizes the steep parts (QRS)
- Squaring makes all values positive and further emphasizes large slopes
- Moving-window integration (about 150 ms) yields the QRS envelope
- An adaptive threshold detects the QRS, and the R-wave peak is located on the original signal
Today, methods using wavelet transforms or machine learning, and open-source libraries (such as NeuroKit2), are also widely used.
4.3 Obtaining them from the pulse wave (PPG): PRV ≠ HRV
Most smartwatches and ring-type devices obtain inter-beat intervals from photoplethysmography (PPG). Strictly speaking, this is pulse rate variability (PRV), which is not the same as HRV.
flowchart LR R["ECG R wave<br/>(electrical excitation)"] -->|"pre-ejection period (PEP)<br/>+ pulse transit time (PTT)"| P["Pulse wave arrives at the periphery"] P --> PRV["PPG inter-beat interval = PRV"] R --> HRV["RR interval = HRV"]
- The time it takes the pulse wave to reach the periphery (pulse transit time + pre-ejection period) itself fluctuates beat to beat with respiration and blood pressure
- Therefore PRV = HRV + fluctuation of transit time, and it tends to overestimate fast beat-to-beat fluctuations such as RMSSD and HF
- Under rest, supine, no-movement conditions the two agree well, but agreement declines with standing, exercise, movement, and cold (reduced peripheral blood flow) (Schäfer & Vagedes 2013)
For PPG, fiducial points such as the pulse wave’s onset (foot), point of maximum slope, or peak can be used. Because the peak is easily affected by waveform shape, the onset or the maximum-slope point is said to give better timing accuracy.
4.4 Artifacts and ectopic beats
4.4.1 What is the problem?
- Premature beats (ectopic beats): an early beat (short RR) is followed by a compensatory pause (long RR). They do not reflect autonomic regulation of the sinus node
- Detection errors: missed R waves (RR roughly doubled), false detection of noise or T waves (RR split)
- Noise from body movement or poor electrode contact
RMSSD and HF, which look at beat-to-beat differences, change greatly with just a single ectopic beat. You will see this for yourself in the hands-on in Chapter 8.
4.4.2 Detection and correction
- Detection: for example, regard as abnormal “an RR that deviates by 20% or more from the preceding RR or from the local median” (adjust the threshold for age, heart rate, and situation)
- Correction: abnormal RRs are
- deleted (note that this shifts the time axis, which matters for frequency analysis)
- interpolated from neighboring normal RRs (linear interpolation, spline interpolation)
- Reporting: always record the proportion of corrected beats. Segments with a high correction rate (e.g., 5% or more) are often excluded from analysis
In atrial fibrillation the sinus node is not generating the rhythm, so the irregularity of RR intervals does not reflect autonomic regulation. HRV analysis presupposes sinus rhythm.
4.5 Preprocessing for frequency analysis
A time series of RR intervals is unevenly spaced data obtained beat by beat (the spacing tightens when the heart beats fast). To use the fast Fourier transform (FFT), the data must be converted to evenly spaced samples.
- Resampling: plot NN intervals against time and interpolate to even spacing at, e.g., 4 Hz (cubic spline interpolation is commonly used)
- Detrending: remove the mean and slow trends (polynomials, the smoothness-priors method, etc.)
- Apply a window function and FFT: Welch’s method (splitting into segments and averaging) reduces variance
There is also the Lomb–Scargle periodogram, which can estimate the spectrum directly from unevenly spaced data. Parametric spectral estimation with autoregressive (AR) models is also used. Values change depending on the method, so describing the method is important when comparing studies.
4.6 Recording length
| Recording | Length | Main use |
|---|---|---|
| Ultra-short-term | under 1 min to a few min | Wearables, spot measurements. There are reports that RMSSD over about 1 min agrees relatively well with the 5-min value |
| Short-term | 5 min (standard recommended by the Task Force) | Resting assessment in the lab and clinic. Assessment of HF and LF |
| Long-term | 24 h (Holter ECG) | Prognosis (SDNN, etc.), circadian variation, assessment of VLF and ULF |
Metrics from different recording lengths cannot be compared directly. In particular, SDNN becomes larger the longer the recording (because slower fluctuations are included).
4.7 Analyzing real data in Python (for reference)
This material analyzes synthetic data in the browser (Chapter 8), but for real data you can use, for example, NeuroKit2 in Python.
import neurokit2 as nk
# ecg: ECG signal (1-D array), fs: sampling frequency [Hz]
signals, info = nk.ecg_process(ecg, sampling_rate=fs)
peaks = info["ECG_R_Peaks"]
# Compute time-domain, frequency-domain, and nonlinear metrics all at once
hrv = nk.hrv(peaks, sampling_rate=fs, show=True)
print(hrv[["HRV_MeanNN", "HRV_SDNN", "HRV_RMSSD", "HRV_LF", "HRV_HF", "HRV_SD1"]])Library defaults (method for correcting abnormal beats, resampling frequency, spectral estimation method, bands) differ between libraries and versions. When reporting in papers and elsewhere, state the settings you used.
4.8 Summary
- Sample the ECG at 250–500 Hz or higher and detect R waves accurately
- What PPG gives you is PRV. It agrees well with HRV at rest, but diverges with movement, standing, and reduced peripheral blood flow, and tends to overestimate fast beat-to-beat fluctuations
- Correction of ectopic beats and detection errors is essential. Report the correction rate
- For frequency analysis: resampling → detrending → spectral estimation. Values change with the method
- Metrics from different recording lengths cannot be compared