Irregular rhythm check
An atrial-fibrillation check on the strap's beat intervals: 150 small boosted trees over 64-beat windows, trained on five PhysioNet databases, with alerts tuned so healthy people with high HRV aren't flagged.
Built from algorithms/rhythm/README.md
These are the project's working notes, published as written. “You” and “your strap” mean the author and the author's own WHOOP strap; only summary numbers from it appear here, never the recordings.
Flags an irregularly irregular heart rhythm, the pattern of atrial fibrillation, from beat-to-beat (RR) intervals. It runs in Pulse on the WHOOP strap's beats today, and later on the Pulse Band itself. Not a diagnosis: it suggests taking an ECG and talking to a doctor.
uv run --with wfdb --with numpy python fetch.py # PhysioNet beat annotations → data/ (gitignored)
uv run --with numpy --with scikit-learn python train.py # evaluate, then write model + Swift + vectors
cd ../../ios/WhoopKit && swift test # Swift port must match the Python vectors
Method
- Window: 64 consecutive beats, half-overlapping. Gaps in the beat stream split runs (the strap only reports clean beats, so checks happen mostly at rest and asleep).
- 8 features (
rhythm.py): normalised RMSSD (and with the 2 largest jumps removed), pNN50, Shannon entropy of the RR histogram, turning-point ratio, sample entropy, coefficient of variation, lag-1 autocorrelation. Autocorrelation is what tells smooth breathing variation (high HRV, young people) apart from random AF. - Model: 150 gradient-boosted trees of depth 3, exported to
ios/WhoopKit/Sources/WhoopKit/RhythmModel.swiftas flat arrays (small enough for the band's nRF52840 too). - Alert: window probability ≥ 0.7 for 6 windows in a row (≈ 4 minutes).
Data (PhysioNet, open access)
MIT-BIH Atrial Fibrillation (25 records, 10 h), MIT-BIH Normal Sinus Rhythm (18), Normal Sinus RR Interval (54), Fantasia (20 young + 20 older healthy adults) and MIT-BIH Arrhythmia (48, heavy ectopy). 185 recordings, 146,131 windows.
Results (held out by recording, 5-fold)
| Window AUC | 0.994 |
| Windows at 0.7 | sensitivity 85.2 %, specificity 99.6 %, young healthy false positives 0.41 % |
| Alerts, AF recordings | 29 / 30 flagged (miss: afdb 07859, a known regular-looking AF record) |
| Alerts, healthy people | 6 false alerts in ≈ 784 h, in 2 of 112 people |
| Alerts, arrhythmia patients without AF | 1 / 41 (frequent extra beats can look irregular) |
| Your strap data, 29 Nov morning | 33 windows, median probability 0.016, no alerts |
History: a 7-feature logistic regression reached AUC 0.989 but flagged 4.8 % of young healthy windows and mistook high HRV for irregularity (median 0.34 on the user's own resting data); the trees fixed that.
Model files
Generated by this algorithm's train.py and copied from the repository at build time. More on the Our data page.
-
model.json 109 KBalgorithms/rhythm/model.json
150 gradient-boosted trees (depth 3), feature list, alert threshold and run length
sha256 959ea7c3c800d797…
-
vectors.json 4.8 KBalgorithms/rhythm/vectors.json
Test vectors: 5 RR windows from PhysioNet records → features → probability (checked by the Swift tests)
sha256 5944a144a2cb5184…
References
- Moody GB, Mark RG. A new method for detecting atrial fibrillation using R-R intervals. Computers in Cardiology 10:227–230 (1983)
- MIT-BIH Atrial Fibrillation Database (PhysioNet, ODC-BY 1.0)
- MIT-BIH Normal Sinus Rhythm Database (PhysioNet, ODC-BY 1.0)
- Normal Sinus Rhythm RR Interval Database (PhysioNet, ODC-BY 1.0)
- Iyengar N et al. Age-related alterations in the fractal scaling of cardiac interbeat interval dynamics. Am J Physiol 1996 (Fantasia Database)
- Fantasia Database (PhysioNet, ODC-BY 1.0)
- Moody GB, Mark RG. The impact of the MIT-BIH Arrhythmia Database. IEEE Eng Med Biol 20(3):45–50 (2001)
- MIT-BIH Arrhythmia Database (PhysioNet, ODC-BY 1.0)
- Goldberger AL et al. PhysioBank, PhysioToolkit, and PhysioNet. Circulation 101(23):e215–e220 (2000)