❤️⚡ CARDIO-RS ⚡❤️
A Rust library for Heart Rate Variability (HRV) analysis
📊 Compute HRV metrics in time-domain and frequency-domain from RR intervals with ease!
💓 Preprocess ECG & PPG raw data for accurate HRV analysis!
📟 Compatible with embedded systems using no_std!
✨ Key Features
- ✅ Time-domain HRV metrics: SDNN, RMSSD, PNN50, SDSD, CVSD, and more!
- ✅ Frequency-domain HRV metrics: LF, HF, VLF (using Welch’s method).
- ✅ Geometric HRV metrics: Triangular Index & TINN.
- ✅ ECG & PPG preprocessing: Filtering, denoising, peak detection.
- ✅
no_stdcompatibility for embedded systems. - ✅ Window-based analysis: Split data into windows for segment-based HRV calculations.
- ✅ Live HRV analysis: Real-time processing of RR intervals with customizable pipelines.
📏 Time-domain HRV Metrics
- 🔹 RMSSD – Short-term HRV measurement.
- 🔹 SDNN – Overall HRV measurement.
- 🔹 PNN50 – Percentage of successive RR intervals > 50ms.
- 🔹 SDSD – Standard deviation of successive RR intervals.
- 🔹 Mean HR – Average heart rate.
- 🔹 AVNN – Mean of all RR intervals.
- 🔹 CVSD – RMSSD divided by the mean RR interval.
📐 Geometric HRV Metrics
- 📊 Triangular Index – Measures RR interval distribution.
- 📊 TINN (Triangular Interpolation of NN Interval Histogram) – Estimates RR variability.
🎵 Frequency-domain HRV Metrics
Computed using Welch’s method for spectral density estimation:
- 🎼 LF (Low Frequency) – Sympathetic and parasympathetic balance (0.04 - 0.15 Hz).
- 🎼 HF (High Frequency) – Parasympathetic activity (0.15 - 0.40 Hz).
- 🎼 VLF (Very Low Frequency) – Long-term regulatory processes (0.003 - 0.04 Hz).
🏥 ECG & PPG Data Processing
- 📡 ECG Processing: R-wave peak detection, filtering, and RR extraction.
- 💡 PPG Processing: Pulse detection & signal cleaning for HRV computation.
🪟 Window Analysis
Cardio-rs supports window analysis, which allows you to split data into segments of a defined size. This is useful for performing HRV analysis on specific time periods or segments of data.
Example:
use ;
let data = vec!;
// Create the window analysis builder
let analysis = new
.with_window_size
.build;
// Get HRV metrics for each window
println!;
🔄 Live Analysis
The live analysis module allows for real-time HRV calculations by dynamically processing incoming RR intervals. You can define a custom analysis pipeline or use the default pipeline for standard HRV metrics.
Example:
use ;
use RR_INTERVALS;
let mut queue = new; // Set the time window (in milliseconds)
let rr_intervals = RR_INTERVALS.to_vec;
for interval in rr_intervals
let hrv = queue.get_hrv;
println!;
🦀 Example Usage
🚀 Compute HRV Metrics & Load ECG Data
use ;
let path = "tests/ecg.csv";
let signal = "ECG_Raw";
let rate = 1000.;
let hrv_metrics = standard_analysis!;
println!;
🔥 Start analyzing HRV today with cardio-rs! 🚀💓