Skip to the heart rate from ecg demo

Medical AI lab · Heart rate from ECG

Heart rate from a noisy ECG: interactive demo

Estimating heart rate from an ECG means detecting each heartbeat (the QRS complex) and turning the intervals between beats into beats per minute. This demo runs a classical QRS detector on a synthetic ECG with a known true heart rate while you add motion artifact. It compares the estimate with the truth, counts missed and false beats and applies a simple pass/fail check, so you can see when the average rate still looks right although individual beats are wrong.

SYNTHETIC DATA

These demos are illustrative. Every signal, image, patient and note is synthetic and fictional, generated and scored in your browser, and every number shown is computed from that synthetic data. They show general principles, not the performance of any real model, product or project, and none of them is a medical device.

Nothing is uploaded. No patient data is used.

01

Biosignals / clinical model validation

Right on average. Wrong beat by beat.

What this shows: as motion artifact grows, a beat detector misses real beats and adds false ones, and the two errors can cancel so the average heart rate still looks right.

Add motion artifact

You can also drag across the trace, or focus it and use the arrow keys.

The check passes when the estimated rate is within ±5 bpm of the true rate and at most one beat is false or missed. Watch for “fail: beats” with a small rate error.

Synthetic ECG and detected beats

sliding window · 250 Hz

Heart rate in the visible window

true HR · bpm
72.0
estimated HR · bpm
72.0
error
±0.0 bpm
detected / actual
9 / 9
false · missed
0 · 0
validation check
pass

Amber: ECG with motion artifactBlue: detected beats, detector energyWhite: true beats, threshold

Synthetic data · illustrative · not a medical device

Where this matters

Wearables, patient monitors and any algorithm that reports a rate or count from a biosignal. A validation that compares only averages can pass a detector whose individual beats are wrong.

What this experiment models

A synthetic ECG built from Gaussian P, QRS and T waves at a known, slowly drifting heart rate, plus motion artifact made of baseline wander, muscle noise and movement bursts. The detector is a classical QRS detector: zero-phase 5–15 Hz band-pass, derivative, squaring, a 150 ms moving window, an adaptive threshold and a 250 ms refractory period. Detected beats are matched to true beats within 100 ms. It is the same code as the live demo on the Medical AI page.

The principle

How it works

The synthetic ECG is built from smooth P, QRS and T waves at a heart rate that drifts slowly between about 64 and 80 bpm, so every true beat time is known exactly. Motion artifact adds baseline wander, muscle noise and short movement bursts whose frequencies overlap the QRS band, which is why filtering alone cannot remove them.

The detector follows a classic design: a 5–15 Hz band-pass filter, a derivative, squaring, a 150 ms moving window and an adaptive threshold with a 250 ms refractory period. A detection within 100 ms of a true beat counts as correct; any other detection is a false beat, and a true beat without a detection is a missed beat.

Heart rate is computed from the beats in the visible window. With heavy artifact the detector can add one false beat and miss another, and the two errors cancel in the average. That is why the check here fails on beat errors as well as on rate error, and why validating a biosignal algorithm means reporting beat-level sensitivity and positive predictive value, not only a mean rate. See clinical model validation.

MLAIA DATA SCIENCE

Tell us what
you’re working on.

Share the problem, the data you have and what success would look like. We’ll discuss a practical next step.

Please don’t include confidential datasets, credentials or patient information.

yochai@mlaia.com
WhatsApp: +972 52 484 6282

Your inquiry is handled under our Privacy Policy.