A wearable ECG patch samples a single lead at ~200 Hz and must locate the QRS complex (the sharp R-wave spike) in real time, on-device, while the strap moves against skin. The classic solution is the Pan-Tompkins algorithm (1985), still the basis of most consumer beat-detectors today. Four scrolling strip-chart panels below show its cascade live:
1. Bandpass filter HP (fc≈1 Hz) then LP (fc≈20 Hz) —
removes baseline wander + EMG noise
2. Derivative y[n] = (1/8)(x[n] + 2x[n-1] − 2x[n-3] − x[n-4])
— the true 5-tap Pan-Tompkins slope kernel
3. Squaring y[n] = x[n]² — all-positive, boosts peaks
4. Moving-window
integration y[n] = mean of last 150 ms — one hump per beat
5. Adaptive threshold SPKI = 0.125·peak + 0.875·SPKI (signal estimate)
NPKI = 0.125·peak + 0.875·NPKI (noise estimate)
THR = NPKI + 0.25·(SPKI − NPKI)
A QRS is declared when the integrated waveform's local peak crosses THR after a 200 ms refractory period (the heart's own absolute refractory period makes two real beats that close together physiologically impossible). A 1.5 s learning phase calibrates the starting threshold from the signal's own amplitude before detection begins — skipping this step is what silently breaks detection on a perfectly clean, noise-free signal, a real failure mode of a fixed-constant threshold.
- Heart rate — sets the underlying sinus rate the beat generator targets, with natural beat-to-beat jitter.
- Motion-artifact noise — adds baseline wander (skin/strap movement) and high-frequency noise on top of the clean ECG, testing whether the bandpass + adaptive threshold still separate signal from noise.
- Ectopic (PVC) rate — a fraction of beats fire early from the ventricles instead of the sinus node: wider, taller QRS, no preceding P-wave, followed by a compensatory pause — the detector still finds the peak, but its short RR-interval relative to the running average flags it.
- Poincaré plot (bottom-right inset) — each detected RR interval plotted against the next one is the standard clinical 2D view of heart-rate variability: a tight cluster near the diagonal means a calm, regular rhythm; PVC beats and their compensatory pause throw two points far off the diagonal, one on each side.
- Beat classification is a real, simplified rule wearables use: an RR interval shorter than 80% of the recent running average is flagged premature/ectopic; the HRV readout is RMSSD, the root-mean-square of successive RR differences, the standard time-domain autonomic-tone metric.