ECG early warning
Loading runtime…

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.

1:00:00

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).

Window by window. Each completed ten-second window gets one probability, and the network carries a memory of earlier windows into the next. Illustration with a made-up signal, not model output.

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.

The alarm rule. Dots are single windows, the line their 30-second average. A lone spike does not alarm; a sustained rise does, and the alarm repeats every five minutes while the score stays up. Illustration.

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.

What early warning delivers. Of every 100 AF onsets in testing on ambulatory recordings, how many got an alarm at least ten minutes ahead, at one false alarm per hour. Chance is the same count at randomly placed onsets.

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.

Limits

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.

Your recording

CSV or text: one sample per row; extra columns allowed (a time column is detected). Binary: 32-bit floats, little-endian, one lead. The signal is resampled to 250 Hz on this device.