Heart Rate Calculation Using the Pan-Tompkins Algorithm

Resource Overview

Implementation of heart rate calculation through the Pan-Tompkins QRS detection algorithm with signal processing workflow explanation

Detailed Documentation

The Pan-Tompkins algorithm is a classical real-time QRS complex detection method for electrocardiogram (ECG) signals, widely used in heart rate calculation applications. Its core principle involves accurately locating R-peak positions in heartbeats through a series of signal processing stages, enabling subsequent instantaneous heart rate derivation.

The algorithm's processing pipeline consists of five critical phases: Bandpass filtering: First combines low-pass and high-pass filters (typically 0.5-10Hz range) to remove baseline wander and high-frequency electromyographic noise from ECG signals. In code implementation, this can be achieved using Butterworth or Chebyshev filters with carefully selected cutoff frequencies. Differentiation: Applies first-order differentiation to enhance the slope characteristics of QRS complexes. This stage typically uses a 5-point derivative filter to emphasize rapid signal changes. Squaring operation: Performs nonlinear transformation through squaring to further accentuate the steep changes of R-peaks. This step converts all values to positive and amplifies higher-frequency components. Moving window integration: Employs a sliding time window (approximately 150ms) to smooth the signal and generate waveform envelopes. Implementation requires careful selection of window width matching typical QRS durations. Adaptive thresholding: Dynamically adjusts detection thresholds to accommodate signal amplitude variations, ultimately determining R-peak positions. This involves setting initial thresholds based on signal peaks and updating them recursively during processing.

After obtaining consecutive R-R intervals, heart rate is calculated using the formula: 60/(R-R interval time). The algorithm demonstrates excellent real-time performance and noise immunity, though attention should be paid to potential motion artifact interference affecting detection accuracy. Modern enhanced versions often incorporate machine learning techniques to improve robustness against signal quality variations.