Is atrial fibrillation under way, or about to start?
A small neural network reads a single-lead ECG ten seconds at a time and, for every ten-second window, estimates two things: whether atrial fibrillation (AF) is happening now, and whether it will start within the next ten minutes. It runs entirely on this device, compiled from Rust to WebAssembly; no signal leaves your browser.
A research demonstration, not a medical device. Read what the numbers mean before trusting any of them.
What the numbers mean
AF now is the model's probability that atrial fibrillation is under way in a ten-second window. AF within 10 min is its probability that an episode starts within the next ten minutes. Both are plotted after averaging the last three windows (30 seconds).
The dashed line is the alarm threshold. It was set, without looking at the recordings shown here, so that each model raises about one false alarm per hour (or one per five hours) on long ambulatory recordings of other people without AF nearby. A triangle marks an alarm; while the score stays above the line it repeats every five minutes. Shaded bands are where the dataset's annotators marked AF.
Three methods are shown on the same axes. The neural network (about 0.9 million parameters) reads the raw ECG. The boosted trees read 49 hand-made measurements of each window (beat timing, waveform shape, spectrum, signal quality) and their recent averages. The variability drop uses no training at all: it tracks how much the beat-to-beat intervals vary compared with this recording's own level from at least ten minutes earlier, because the rhythm tends to become unusually regular before AF. It is drawn as 1/(1 + e−z) of its z-score so it fits the same scale, and only answers the early-warning question.
VT / VF: ventricular tachycardia and fibrillation
These are the rhythms that stop the heart pumping and can kill within minutes, during surgery as elsewhere. The VT/VF view uses boosted trees on the same 49 measurements, trained on seven open databases of ventricular events. It answers two questions: is VT or VF under way, and will it start within the next two minutes. The alarm thresholds were fixed on other patients. No neural model beat the trees here.
Measurements from one lead
A larger network (an encoder of about 4.8 million parameters, pretrained by reconstructing hidden stretches of ECG and reading the signal strictly forward in time) turns each ten-second window into a summary from which simple linear read-outs estimate the wave intervals and the signal quality. Click the chart to measure any window.
- PR, QRS, QT: medians over the window's beats, fitted on LUDB, a database of resting ECGs with every wave marked by cardiologists. Monitoring and surgical ECGs are noisier; expect larger errors there.
- QTc: QT corrected for heart rate with Fridericia's formula (QT divided by the cube root of the beat interval).
- Heart rate comes from the beat detector, which measures beat intervals more accurately than the read-out.
- Signal quality: good (every analysis possible), fair (beats can be found) or poor (unusable), fitted on BUT QDB, long recordings from wearable devices with quality marked by experts. Fair and poor windows are marked under the ECG.
Limits
- Detection is the easy part; early warning is modest. Most onsets get no warning from any method, and an alarm before an onset is far more often a false alarm than a true warning.
- Trained on ambulatory recordings (Holter monitors and patches from public research databases). Surgery, intensive care, exercise and wearables can look different; the operating-room example shows the model on data unlike its training.
- The examples were picked by rule, not by result: for each database, the first AF onset with 40 clean minutes before it, from patients the models did not train on (the two-lead network did train on the surgical database).
- Your file is resampled to 250 Hz and assumed to be in millivolts unless you say otherwise. Poor electrode contact, movement and other leads than those in training all change the output.
- This is not a medical device and must not be used to make decisions about anyone's care.
How it runs
The model was trained in PyTorch and ported to a small Rust runtime: weights load from one file, every ten-second window goes through the Transformer encoder and one step of the recurrent head, and the state carries over to the next window. Its outputs agree with the Python reference to within 10−5 on every window tested. Here it runs as WebAssembly (with SIMD where the browser supports it) in a background thread, so the page stays responsive.
Data and licences
Example recordings are excerpts, converted to 250 Hz and rounded to half precision. Every source allows redistribution with attribution under the licence named.