The algorithm: a window-level AF detector for 30-second single-lead ECG
How the detector works, from the cardiac cycle to the strip decision: the signal, the beat measurements it reuses, the rhythm features it computes, the model, the safeguards, and what the data shows.
Abstract
We describe a detector of atrial fibrillation (AF) for 30-second single-lead ECG strips recorded by a wrist sensor. The detector reuses an existing beat detector and its per-beat measurements and replaces the per-beat decision of the previous design with a decision over windows of consecutive beats. Each window is described by ten statistics of the RR-interval sequence and, where available, twelve summaries of beat morphology and signal quality from the beat detector. A gradient-boosting classifier with monotonic constraints estimates the probability of AF per window; a physiological guard, a plausibility gate and a probability band turn window probabilities into a strip decision of AF, not AF, or inconclusive. On 755 strips from 47 sensor patients never used in training, the detector classified 68 % of strips and reached 98.7 % sensitivity and 98.6 % specificity on them; on the MIT-BIH Atrial Fibrillation Database, never used in training, it reached 96.5 % duration sensitivity and 92 % duration positive predictivity by the EC57 method and detected every AF episode of 30 seconds or longer.
1. Background: what AF looks like on a single lead

A normal heartbeat begins with the P wave, the electrical activation of the atria, followed after the PR interval by the QRS complex, the activation of the ventricles, and the T wave, their recovery. In sinus rhythm the sinus node fires regularly, so successive R peaks are almost equally spaced, and every QRS is preceded by a P wave.
In atrial fibrillation the atria no longer contract in an organised way. Two consequences are visible on a single lead: the P wave disappears, replaced by low-amplitude fibrillatory activity, and the ventricles are activated at irregular moments, so the RR intervals vary from beat to beat without pattern. Rhythm-based AF detection rests on the second sign, because it survives noise, electrode placement and low amplitude far better than the first; morphology-based detection uses the first to separate AF from other irregular rhythms. This detector uses both where the beat detector provides them.

Figure 2 shows three real 30-second strips from the held-out sensor patients, with the beats found by the beat detector marked, and the Poincaré plot of successive RR intervals. In sinus rhythm (A) the RR pairs collapse onto one point; in AF (B) they scatter widely and the coefficient of variation of RR is 0.27 against 0.01; in an artefact strip (C) a periodic disturbance makes the beat detector report 229 “beats” per minute, which no heart produces, and the strip is refused rather than classified.
2. Signal and beats
The sensor records one lead at 256 Hz for 30 seconds, in microvolts. The existing engine filters the signal, detects beats and measures each of them: R position, RR interval, R and S amplitudes, QRS onset and width, P-wave position and amplitude when a P wave is found, T-wave position, a deformation index, and a quality index. It also clusters beats by morphology and marks stretches where it considers the signal unusable. None of this is changed. The detector consumes the beat positions and these measurements.
For the public databases used in development the beat positions come from the PhysioNet reference annotations, or, for the MIT-BIH AF Database, from its supplied detections; morphology features are then absent and the model handles them as missing values.
3. Windows and features
Beats are grouped into windows of 16 consecutive beats, stepping 4 beats, for 30-second strips; 32 beats stepping 8 for long recordings. A window is discarded if any RR interval lies outside 0.2-3.0 s or its mean rate exceeds 200 beats per minute; such windows come from missed or spurious beats, not from a rhythm.
For each window, ten RR statistics are computed. With the intervals in seconds, , the mean and the median:
plus the Shannon entropy of the RR histogram (16 bins over 0.3-2.0 s), the sample entropy of the RR sequence (, ), and the turning point ratio. These are the descriptors used by RR-based AF detectors since the 2000s; they measure, in different ways, how unpredictable the interval sequence is.
Where the engine has run, twelve window summaries of its measurements are added: the fraction of beats with a detected P wave and the mean and CV of its amplitude; mean and standard deviation of QRS width, of the deformation index and of R-S amplitude; mean, standard deviation and minimum of the quality index; the fraction of beats the engine’s beat classifier calls ventricular; and the fraction of the window inside engine out-of-signal stretches.

Figure 3 shows three of the RR features on held-out sensor windows. The irregularity index alone separates most AF from most non-AF; the overlap is where ectopic beats and sinus arrhythmia make a non-AF rhythm irregular, and where morphology and the model’s combination of features do the remaining work.
4. Model
The classifier is a histogram gradient-boosting ensemble (scikit-learn HistGradientBoostingClassifier): depth 4, 300 iterations, learning rate 0.05, L2 regularisation 1. Two constraints are built in.
Monotonicity. The RR-irregularity features (irregularity index, CV, normalised RMSSD, pNN50, normalised MAD) are constrained so that a larger value can only increase the predicted AF probability. This matches physiology and prevents the model from learning spurious reversals from noisy labels.
Physiological guard. A window whose irregularity index is below 0.1 and whose RR CV is below 0.05 is a practically regular rhythm and is never called AF, whatever the other features say. This rule was introduced after a held-out patient with a regular rhythm at about 100 beats per minute and unusually small P waves was repeatedly misclassified.
The model file is about 0.5 MB. Missing morphology features are handled natively by the ensemble.
5. From windows to a decision

For a 30-second strip, the highest window probability is compared with two thresholds: at least 0.8 gives AF, at most 0.5 gives not AF, and anything between is reported as inconclusive. A strip that yields no valid window, because its beats are implausible, is inconclusive by construction; this is how artefacts such as strip C in Figure 2 are handled. For long recordings, windows are joined into episodes by a hysteresis rule, on at 0.6 and off at 0.3, with a minimum of one window. All thresholds were selected on a separate tuning set of 24 long-term records, never on a test set.
6. Training and evaluation data
| Set | Role | Content | Beats | Labels |
|---|---|---|---|---|
| Long-Term AF Database | training 60 records, tuning 24 | 84 records, ~24 h each | reference | interval, cardiologist-reviewed |
| MIT-BIH Arrhythmia Database | training | 48 records | engine | interval, PhysioNet |
| Clinical AF set | training | 218 segments, 52 patients | engine | whole segment, physician |
| Sensor strips, 97 patients | training | 6,156 windows | engine | whole strip |
| MIT-BIH AF Database | test, never used in training | 23 records, 10 h | PhysioNet detections | interval, cardiologist |
| Sensor strips, 47 patients | test, patients disjoint | 755 strips | engine | whole strip |
Sensor patients were assigned to training or test by a hash of the patient identifier, with zero overlap verified. A window is labelled AF when at least 80 % of its span lies inside an annotated AF interval, not AF at 20 % or less, and discarded in between. Segments flagged as artefact by the annotator were excluded from training; on the test side they were kept, so that the artefact handling is evaluated rather than assumed.
A label audit with out-of-fold predictions found and fixed a loader bug that had labelled an unannotated two-hour stretch as non-AF, and led to two rule-based cleaning steps: windows above 200 beats per minute and AF-labelled windows with regular RR are excluded from training. Model-based disagreements were deliberately not used for cleaning.
7. Results
Sensor strips, all 755 held-out strips, product rule: 31.8 % inconclusive (the annotator flagged 28 % of this set as artefact); on the 515 classified strips, sensitivity 98.7 %, specificity 98.6 %, PPV 96.9 %, NPV 99.4 %, 5 false positives and 2 misses.
MIT-BIH AF Database, RR features only: window sensitivity 95.6 % and specificity 96.7 %; by EC57, duration sensitivity 96.5 % and duration positive predictivity 92.0 %; every reference episode of 30 s or longer detected, 89-100 % of those between 10 and 30 s, and 50-61 % of those shorter than 10 s, below the resolution of a window. Episode positive predictivity over all lengths is 47-56 %, dominated by short false episodes in eight records with frequent ectopy; restricted to detected episodes of at least a minute it is 84 %. The detailed tables are on the results page.
8. Discussion
Three properties make this design suitable for a regulated product. It is small and explainable: twenty-two named features with physiological meaning, an ensemble of shallow trees, two hard rules, and fixed thresholds with a documented selection procedure. It is honest about uncertainty: it refuses strips it cannot read instead of guessing, and the refusal rate is reported as a metric. And it was evaluated the way a reviewer evaluates: patients and databases never seen in training, thresholds chosen elsewhere, standard EC57 scoring.
Its known limits are equally clear. On RR intervals alone, frequent premature beats and sinus arrhythmia are indistinguishable from AF; the P-wave and quality measurements of the beat detector are the intended remedy, and the test that quantifies their effect on the public benchmark is pending. Episodes shorter than a window cannot be resolved, which is acceptable for a 30-second strip claim and a limitation for continuous monitoring. And the sensor labels used so far are whole-strip annotations by one annotator; cardiologist re-annotation at interval level is the next step before any number enters a submission.
References
- ANSI/AAMI EC57, Testing and reporting performance results of cardiac rhythm and ST-segment measurement algorithms.
- Moody GB, Mark RG. A new method for detecting atrial fibrillation using R-R intervals. Computers in Cardiology 1983 (MIT-BIH Atrial Fibrillation Database).
- Petrutiu S, Sahakian AV, Swiryn S. Abrupt changes in fibrillatory wave characteristics at the termination of paroxysmal atrial fibrillation in humans. Europace 2007 (Long-Term AF Database).
- Dash S, Chon KH, Lu S, Raeder EA. Automatic real time detection of atrial fibrillation. Annals of Biomedical Engineering 2009.
- Lake DE, Moorman JR. Accurate estimation of entropy in very short physiological time series. American Journal of Physiology 2011.
- Ke G et al. LightGBM / histogram-based gradient boosting; scikit-learn HistGradientBoostingClassifier documentation.