Pan–Tompkins algorithm

The Pan–Tompkins algorithm[1] is commonly used to detect QRS complexes in electrocardiographic signals (ECG).

The QRS complex represents the ventricular depolarization and the main spike visible in an ECG signal (see figure).

The Pan–Tompkins algorithm applies a series of filters to highlight the frequency content of this rapid heart depolarization and removes the background noise.

Finally, it applies adaptive thresholds to detect the peaks of the filtered signal.

The algorithm was proposed by Jiapu Pan and Willis J. Tompkins in 1985, in the journal IEEE Transactions on Biomedical Engineering.

[1] The performance of the method was tested on an annotated arrhythmia database (MIT/BIH[2][3]) and evaluated also in presence of noise.

Pan and Tompkins reported that the 99.3 percent of QRS complexes was correctly detected.

[1] As a first step, a band-pass filter is applied to increase the signal-to-noise ratio.

A filter bandwidth of 5-15 Hz is suggested to maximize the QRS contribute and reduce muscle noise, baseline wander, powerline interference and the P wave/T wave frequency content.

[1] In the original algorithm proposed in 1985, the band-pass filter was obtained with a low-pass filter and a high-pass filter in cascade to reduce the computational cost and allow a real-time detection, while ensuring a 3 dB passband in the 5–12 Hz frequency range, reasonably close to the design goal.

For a signal sampled at a frequency of 200 Hz, Pan and Tompkins suggested the filters with the following transfer functions

in an updated version of their article:[4] As a third step, a derivative filter is applied to provide information about the slope of the QRS.

For a signal sampled at 200 Hz, Pan and Tompkins suggested the following transfer function:[4]

for a 5-point derivative filter with gain of 0.1 and a processing delay of 2 samples.

Then, a moving average filter is applied to provide information about the duration of the QRS complex.

In order to detect a QRS complex, the local peaks of the integrated signal are found.

This is a physiological constraint due to the refractory period during which ventricular depolarization cannot occur even in the presence of a stimulus.

To reduce the possibility of wrongly selecting a noise peak as a QRS, each peak amplitude is compared to a threshold (ThresholdI) that takes into account the available information about already detected QRS and the noise level:

At the beginning of the QRS detection, a 2 seconds learning phase is needed to initialize SignalLevelI and NoiseLevelI as a percentage of the maximum and average amplitude of the integrated signal, respectively.

If PEAKI is above the ThresholdI, the algorithm implements a further check before confirming the peak as a true QRS, taking into consideration the information provided by the bandpass filtered signal.

(if PEAKF is a noise peak) where the final F stands for filtered signal.

The algorithm takes into account the possibility of setting too high values of ThresholdII and ThresholdIF.

The average RR is computed in two ways to consider both regular and irregular heart rhythm.

In the second method RRaverage2 is computed as the mean of the last RR intervals that fell between the limits specified as:

If no QRS is detected in a window of 166% of the average RR (RRaverage1 or RRaverage2, if the heart rhythm is regular or irregular, respectively), the algorithm adds the maximal peak in the window as a potential QRS and classify it considering half the values of the thresholds (both ThresholdII and ThresholdIF).

This check is implemented because the temporal distance between two consecutive beats cannot physiologically change more quickly than this.

The algorithm takes particularly into consideration the possibility of a false detection of T waves.

If a potential QRS falls up to a 160 ms window after the refractory period from the last correctly detected QRS complex, the algorithm evaluates if it could be a T wave with particular high amplitude.

In this case, its slope is compared to that of the precedent QRS complex.

HRV is often used in the clinical field[6] to diagnose and monitor pathological conditions and their treatment, but also in the affective computing research to study new methods to assess the emotional state of people.

ECG beat
Block diagram of the pre-processing phase of the Pan–Tompkins algorithm.
Example of Pan–Tompkins processing. [ 5 ]