A Python-based pipeline for heart rate detection from bed-embedded Ballistocardiogram (BCG) sensors. This system processes raw BCG signals, filters out noise and movement artifacts, detects peaks corresponding to heartbeats, and estimates heart rate over time. The results are compared against ECG-derived reference heart rates for evaluation.
data/
βββ BCG/
β βββ fixed_bcg2.csv # Raw BCG data file
βββ RR/
β βββ 03_20231105_RR.csv # Reference heart rate (ECG-based RR intervals)
results/
βββ wavelet_cycle.png # Visualization of wavelet-smoothed BCG signal
βββ hr_comparison.png # Reference vs Estimated HR
βββ bland_altman.png # Bland-Altman plot
βββ pearson_correlation.png # Correlation between estimated and reference HR
- Load BCG and Reference RR Data
- Synchronize BCG and RR Timeframes
- Resample BCG to 50 Hz
- Denoise and Remove Artifacts
- Band-pass filtering
- Non-linear trend removal
- Smoothing with Savitzky-Golay filter
- Wavelet Transform
- Multi-resolution analysis (MODWT)
- Peak Detection
- Detect peaks in smoothed BCG signal to derive heartbeats
- Heart Rate Estimation
- Calculate RR intervals and convert to HR in BPM
- Metrics Evaluation
- MAE, RMSE, MAPE, Pearson correlation
- Comparison against reference ECG-derived HR
- Visualization
Heart Rate Comparison Metrics
MAE: 16.08
RMSE: 22.65
MAPE: 19.14%
r value: ~0.00
Heart Rate Information
Min: 53 bpm
Max: 91 bpm
Mean: 72 bpmMake sure to install the following Python packages:
pip install numpy pandas scipy matplotlib scikit-learn- Data is resampled to 50 Hz using linear interpolation and
scipy.signal.resample. - Reference HR is used for validation only and is not interpolated.
- Ensure your CSV files are timestamped in milliseconds and aligned properly.