Template Matching for PPG Beat Detection
Template matching detects PPG systolic beats by sliding a reference pulse waveform template across the signal and identifying locations of maximum cross-correlation. This approach simultaneously provides beat detection and signal quality assessment through the correlation coefficient.
Template matching begins with template construction from a clean segment of the PPG recording. The template is computed as the ensemble average of 10–30 high-quality beats identified by preliminary peak detection. For each sample position in the continuous PPG, the normalized cross-correlation with the template is computed: NCC(τ) = Σ(x(n+τ)·t(n)) / (||x||·||t||). Peaks in NCC exceeding a threshold (typically 0.85) indicate detected beats.
The template is adaptively updated during processing to track slow waveform changes from posture, vasoconstriction, and circadian effects. Update rate (exponential moving average with α = 0.01–0.05) balances template adaptation against corruption by artifacts. Separate templates may be maintained for different activity states detected by the accelerometer.
Template matching outperforms simple peak detection during moderate motion artifacts because the correlation computation inherently favors physiologically plausible pulse shapes over artifact-induced peaks. On the MIMIC-III benchmark, template matching achieves F1 = 0.97 for beat detection vs. F1 = 0.93 for derivative-based peak detection, with the largest improvement during noisy segments.
Frequently Asked Questions
How is the initial template created?
The initial template is extracted from the first clean segment identified by simple amplitude and periodicity checks. 10–30 consecutive beats are ensemble-averaged. If no clean segment is found in the first 30 seconds, a generic waveform shape is used as a starting template.
Does template matching work for abnormal rhythms?
Template matching works for AF and ectopic beats with reduced correlation. The correlation coefficient naturally drops for morphologically abnormal beats, providing simultaneous beat detection and abnormality flagging.
What is the computational cost?
Sliding cross-correlation has O(N·M) complexity where N is signal length and M is template length. For 25 Hz PPG with 25-sample template (1 second), this is 625 multiply-accumulate operations per second — negligible on modern MCUs.