Medical AI lab · Heart rate from ECG ·
Heart rate from a noisy ECG: interactive demo
A heart-rate algorithm can report the right average while getting individual beats wrong. In this demo a classical QRS detector reads a synthetic ECG whose true rate is known: with the Heavy movement preset (1.40 mV of motion artifact) it estimates 75.0 bpm against a true 74.3 bpm, well inside a ±5 bpm tolerance, yet 3 of its detections are false and 4 true beats are missed in a ten-beat window. A validation that compares only average rates would pass this detector; beat-level sensitivity and positive predictive value would not.
In one line: In the demo’s heavy-movement window the heart-rate error is +0.7 bpm while 3 beats are false and 4 are missed, so a test on the average rate alone passes a detector that is wrong beat by beat.
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.
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 HzHeart 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
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.
Worked example
A heart-rate algorithm that passes on the average
Picture a team building a wearable heart-rate monitor. Their acceptance test compares the device’s average heart rate over a short window with a reference and passes when the two agree within ±5 bpm. On recordings taken at rest the algorithm passes easily, and the team concludes that the beat detector works.
The demo opens on that at-rest case. With the default 0.20 mV of motion artifact, the opening eight-second window on a wide screen holds 10 true beats and the detector finds all 10. True and estimated heart rate are both 74.3 bpm, the error reads ±0.0 bpm, false · missed reads 0 · 0 and the check says pass.
Now take the same window with the Heavy movement preset (1.40 mV). The estimated rate is 75.0 bpm against a true 74.3 bpm, an error of +0.7 bpm, well inside the ±5 bpm tolerance. But the detector reports 9 beats where there are 10, 3 of its detections are false and 4 true beats are missed. The false beats stand in for the missed ones almost one for one, so the average hardly moves, and the demo’s check reads “fail: beats”. A test on the mean rate alone would have passed this window.
A note on reproducing these figures: the trace scrolls, so the readouts change from moment to moment. The numbers above are for the opening window, which is the still frame the demo draws when your system asks for reduced motion. A narrow screen shows a six-second window, with slightly different figures and the same pattern.
The practical cost is that anything built on beat times, such as heart-rate variability or rhythm analysis, inherits the wrong beats even though the displayed rate looks fine. The correct practice is to validate at beat level: annotate reference beat times, match each detection to a reference beat within a stated tolerance (100 ms here), and report sensitivity and positive predictive value next to the rate error. Report them separately for rest, walking and heavy movement instead of pooling everything, and fix the pass criteria before looking at the results.
Checklist
What to check in your own project
- Is there a beat-level reference with annotated beat times, not only a reference heart rate?
- Are beat-level sensitivity and positive predictive value reported, with the matching tolerance stated?
- Are results broken down by activity or signal quality (rest, walking, heavy movement) instead of pooled?
- Do the pass criteria cover beat errors as well as rate error, and were they fixed before testing?
- Do the test recordings come from people and devices that were not used to tune the detector?
- What does the algorithm do when the signal is unusable: report a number anyway, or flag low quality?
Related: our clinical model validation service, the wiki page on medical AI validation, and the demos on patient-level data leakage and calibration and decision thresholds.
FAQ
Common questions
How do I validate a heart rate algorithm from ECG?
Compare it beat by beat with annotated reference beats, not only by average rate. Match each detection to a reference beat within a stated tolerance, such as 100 ms, and report sensitivity and positive predictive value next to the rate error, separately for rest, walking and heavy movement. In this demo the heavy-movement window passes a ±5 bpm rate test while 3 beats are false and 4 are missed.
Why does my heart rate monitor read correctly during movement when the beats are wrong?
False beats added by motion artifact and real beats the detector misses can cancel in the average. The displayed rate then stays close to the truth while the beat times underneath are wrong, which corrupts anything built on them, such as heart-rate variability. The demo shows a +0.7 bpm error next to 3 false and 4 missed beats.
What is an acceptable error for a wearable heart rate monitor?
There is no single number; it depends on the intended use and the standard you validate against. The demo uses an illustrative ±5 bpm rate tolerance plus a limit of one false or missed beat per window, and it is the beat criterion that fails under heavy movement. Fix your criteria before testing and report them per activity level.
How is heart rate calculated from an ECG?
Each heartbeat produces a sharp QRS complex in the ECG. A detector finds the time of each one, usually at the R peak, and the interval between consecutive beats gives the rate: 60 divided by the R-R interval in seconds is the heart rate in beats per minute. Over a window, the rate is the number of intervals divided by the time from the first beat to the last, multiplied by 60.
Why can a heart rate estimate be right when the beat detection is wrong?
An average rate depends on how many beats were counted in the window, not on which ones. A false detection and a missed beat cancel each other. In this demo’s opening window with heavy movement the rate error is only +0.7 bpm, although 3 detections are false and 4 true beats are missed.
How do you validate a QRS detector?
Compare its detections with reference beat annotations, beat by beat. A detection counts as correct if it falls within a tolerance of a reference beat; the demo uses 100 ms. Report sensitivity (the share of true beats found) and positive predictive value (the share of detections that are real beats), by noise level, on recordings from people who were not used to develop the detector.
What is motion artifact in an ECG?
Motion artifact is any change in the recorded signal caused by movement of the body, the electrodes or the cables: slow baseline wander, muscle noise and abrupt bursts. Its frequencies overlap those of the QRS complex, so filtering cannot remove it completely, and a burst can look like a beat or hide one.
Medical AI lab
More demos
All fourteen demos on one page: the medical AI labClinical model validation →