The Pan–Tompkins algorithm 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). This feature makes it particularly suitable for measuring heart rate, the first way to assess the heart health state. In the first derivation of Einthoven of a physiological heart, the QRS complex is composed by a downward deflection (Q wave), a high upward deflection (R wave) and a final downward deflection (S wave). The Pan–Tompkins algorithm applies a series of filters to highlight the frequency content of this rapid heart depolarization and removes the background noise. Then, it squares the signal to amplify the QRS contribution, which makes identifying the QRS complex more straightforward. 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. The performance of the method was tested on an annotated arrhythmia database (MIT/BIH) and evaluated also in presence of noise. Pan and Tompkins reported that the 99.3 percent of QRS complexes was correctly detected.
Pre-processing
Noise cancellation 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. 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 H ( z ) {\displaystyle H(z)} in an updated version of their article:
H ( z ) = ( 1 − z − 6 ) 2 ( 1 − z − 1 ) 2 {\displaystyle H(z)={(1-z^{-6})^{2} \over (1-z^{-1})^{2}}} for a second-order low-pass filter with a gain of 36 and a processing delay of 5 samples;
H ( z ) = ( − 1 / 32 + z − 16 − z − 17 + z − 32 / 32 ) ( 1 − z − 1 ) {\displaystyle H(z)={(-1/32+z^{-16}-z^{-17}+z^{-32}/32) \over (1-z^{-1})}} for a high-pass filter with a unity gain and a processing delay of 16 samples.
Derivative step 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:
H ( z ) = 0.1 ( − z − 2 − 2 z − 1 + 2 z 1 + z 2 ) {\displaystyle H(z)=0.1(-z^{-2}-2z^{-1}+2z^{1}+z^{2})} for a 5-point derivative filter with gain of 0.1 and a processing delay of 2 samples.
Squaring and integration The filtered signal is squared to enhance the dominant peaks (QRSs) and reduce the possibility of erroneously recognizing a T wave as an R peak. Then, a moving average filter is applied to provide information about the duration of the QRS complex. The number of samples to average is chosen in order to average on windows of 150 ms. The signal so obtained is called integrated signal.
Decision rules
Fiducial mark In order to detect a QRS complex, the local peaks of the integrated signal are found. A peak is defined as the point in which the signal changes direction (from an increasing direction to a decreasing direction). After each peak, no peak can be detected in the next 200 ms (i.e. the lockout time). This is a physiological constraint due to the refractory period during which ventricular depolarization cannot occur even in the presence of a stimulus.
Thresholds Each fiducial mark is considered as a potential QRS. 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:
… excerpt ends here. Continue reading the full article.



![Pan–Tompkins algorithm: Example of Pan–Tompkins processing.[5]](https://upload.wikimedia.org/wikipedia/commons/thumb/8/82/ECGrita.svg/1280px-ECGrita.svg.png?utm_source=en.wikipedia.org&utm_campaign=parser&utm_content=thumbnail)
