Skip to content
Pulse
Lab · Algorithms

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.

0.994window AUC, held out by recording

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.swift as 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 AUC0.994
Windows at 0.7sensitivity 85.2 %, specificity 99.6 %, young healthy false positives 0.41 %
Alerts, AF recordings29 / 30 flagged (miss: afdb 07859, a known regular-looking AF record)
Alerts, healthy people6 false alerts in ≈ 784 h, in 2 of 112 people
Alerts, arrhythmia patients without AF1 / 41 (frequent extra beats can look irregular)
Your strap data, 29 Nov morning33 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.

References

  1. Moody GB, Mark RG. A new method for detecting atrial fibrillation using R-R intervals. Computers in Cardiology 10:227–230 (1983)
  2. MIT-BIH Atrial Fibrillation Database (PhysioNet, ODC-BY 1.0)
  3. MIT-BIH Normal Sinus Rhythm Database (PhysioNet, ODC-BY 1.0)
  4. Normal Sinus Rhythm RR Interval Database (PhysioNet, ODC-BY 1.0)
  5. Iyengar N et al. Age-related alterations in the fractal scaling of cardiac interbeat interval dynamics. Am J Physiol 1996 (Fantasia Database)
  6. Fantasia Database (PhysioNet, ODC-BY 1.0)
  7. Moody GB, Mark RG. The impact of the MIT-BIH Arrhythmia Database. IEEE Eng Med Biol 20(3):45–50 (2001)
  8. MIT-BIH Arrhythmia Database (PhysioNet, ODC-BY 1.0)
  9. Goldberger AL et al. PhysioBank, PhysioToolkit, and PhysioNet. Circulation 101(23):e215–e220 (2000)