Heart Rate Variability¶
Compute time-domain HRV metrics from RR intervals |
|
Compute frequency-domain HRV metrics from RR intervals |
|
Compute Poincaré plot descriptors (SD1, SD2) |
Definitions follow the Task Force of the ESC and NASPE (1996), Heart rate variability: standards of measurement, physiological interpretation and clinical use, Circulation 93:1043–1065.
Input is a 1-D array of RR intervals in milliseconds. NaN, infinite or non-positive values raise
ValueError.The intervals are used as given. Ectopic beats and detection errors are not removed, so pass cleaned NN intervals when the result must follow the standard.
A metric that is undefined for the number of intervals is returned as
nan: SDNN and RMSSD need 2 intervals, SDSD needs 3, frequency-domain metrics need 4, SD1/SD2 need 3.
Metric |
Unit |
Definition |
|---|---|---|
|
ms |
Sample standard deviation of the intervals (ddof = 1) |
|
ms |
Root mean square of successive differences |
|
ms |
Sample standard deviation of successive differences |
|
count, % |
Successive differences strictly greater than 50 ms, as a percentage of all differences |
|
count, % |
Same with 20 ms |
|
bpm |
Mean and sample standard deviation of |
|
ms² |
Welch PSD of the RR series, cubic-interpolated at |
|
none |
|
|
ms |
|
Warning
Frequency-domain metrics need enough data: the Task Force recommends at least 1 min for HF, 2 min for LF and 5 min for short-term analysis. frequency_domain() issues a UserWarning below 2 min (LF unreliable) and below 1 min (LF and HF unreliable). The RR intervals of a standard 10-second ECG are not enough for spectral HRV. Do not interpret VLF from recordings shorter than 5 min.
- ecgdatakit.processing.time_domain(rr_ms)[source]¶
Compute time-domain HRV metrics from RR intervals.
- Parameters:
rr_ms (
NDArray[double]) – RR intervals in milliseconds (1-D, positive, finite).- Returns:
mean_rr(ms): mean interval;nanif empty.sdnn(ms): sample standard deviation (ddof=1); needs 2 intervals.rmssd(ms): root mean square of successive differences; needs 2.sdsd(ms): standard deviation (ddof=1) of successive differences; needs 3.nn50_count,nn20_count: successive differences strictly greater than 50 ms / 20 ms.pnn50,pnn20(%): counts divided by the number of successive differences; needs 2 intervals.hr_mean(bpm): mean of60000 / rr;nanif empty.hr_std(bpm): sample standard deviation of60000 / rr; needs 2.
- Return type:
- Raises:
ValueError – If rr_ms is not 1-D or contains NaN, infinite or non-positive values.
- ecgdatakit.processing.frequency_domain(rr_ms, method='welch', interp_fs=4.0)[source]¶
Compute frequency-domain HRV metrics from RR intervals.
RR intervals are placed at their beat times, interpolated (cubic) to a uniform series at interp_fs Hz, mean-removed, and the power spectral density is estimated with Welch’s method (segments of up to 256 samples, 64 s at 4 Hz). Band powers integrate the PSD over the Task Force bands: VLF 0–0.04 Hz, LF 0.04–0.15 Hz, HF 0.15–0.40 Hz, total 0–0.40 Hz.
The Task Force recommends at least 1 min of data for HF and 2 min for LF (5 min for short-term analysis). A
UserWarningis issued when the recording is shorter than 2 min (LF unreliable) or 1 min (LF and HF unreliable). VLF from recordings shorter than 5 min should not be interpreted.- Parameters:
- Returns:
vlf_power,lf_power,hf_power,total_powerin ms², andlf_hf_ratio(dimensionless). All values arenanwhen fewer than 4 intervals are given;lf_hf_ratioisnanwhen HF power is zero.- Return type:
- Raises:
ValueError – Unknown method, interp_fs not above 0.8 Hz or not finite, or invalid rr_ms.
- ecgdatakit.processing.poincare(rr_ms)[source]¶
Compute Poincaré plot descriptors (SD1, SD2).
SD1 = std(RR[n+1] - RR[n]) / sqrt(2)andSD2 = std(RR[n+1] + RR[n]) / sqrt(2)(sample standard deviations).- Parameters:
rr_ms (
NDArray[double]) – RR intervals in milliseconds (1-D, positive, finite).- Returns:
sd1andsd2in ms,sd1_sd2_ratio. Allnanwhen fewer than 3 intervals are given; the ratio isnanwhen SD2 is 0.- Return type:
- Raises:
ValueError – If rr_ms is not 1-D or contains NaN, infinite or non-positive values.