A wearable ECG patch samples a single lead at ~200–250 Hz and must locate the QRS complex (the sharp R-wave spike) in real time, on a battery-powered chip, while the strap moves against skin. The classic solution is the Pan-Tompkins algorithm (1985), still the basis of most consumer beat-detectors today. It cascades five stages:
1. Bandpass filter removes baseline wander and EMG/motion noise,
keeping the ~5–15 Hz band where QRS energy lives
2. Derivative y[n] ≈ (x[n] − x[n-2]) / 2 — emphasises steep slope
3. Squaring y[n] = x[n]² — all-positive, boosts peaks
4. Moving-window
integration y[n] = (1/N) Σ x[n-k] — 150 ms window, smooths
into one hump per beat
5. Adaptive threshold SPKI = 0.125·peak + 0.875·SPKI (signal-peak estimate)
NPKI = 0.125·peak + 0.875·NPKI (noise-peak estimate)
THR = NPKI + 0.25·(SPKI − NPKI)
A QRS is declared when the integrated waveform crosses THR after a 200 ms refractory period (the heart's own absolute refractory period, which makes two real beats that close together physiologically impossible). The four processing stages are drawn as stacked ribbons scrolling toward you; the bottom one carries the adaptive threshold as a translucent plane.
- 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.
- 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.