ArticleslgStudy

computer science

Pan–Tompkins algorithm

Pan–Tompkins algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Pan–Tompkins algorithm rather than just read about it. In short: 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).

Pan–Tompkins algorithm — main illustration
Pan–Tompkins algorithm — illustration

Key takeaways

  • Pan–Tompkins algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Pan–Tompkins algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Pan–Tompkins algorithm from memory before moving on to harder problems.

Reference excerpt

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) in an updated version of their article:

H(z)=(1−z−6)2(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)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−2z−1+2z1+z2)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: ThresholdI=NoiseLevelI+0.25(SignalLevelI−NoiseLevelI) where NoiseLevelI is the running estimate of the noise level in the integrated signal and SignalLevelI is the running estimate of the signal level in the integrated signal. The threshold is automatically updated after detecting a new peak, based on its classification as signal or noise peak: SignalLevelI=0.125PEAKI+0.875SignalLevelI(if PEAKI is a signal peak) NoiseLevelI=0.125PEAKI+0.875NoiseLevelI(if PEAKI is a noise peak) where PEAKI is the new peak found in the integrated signal. 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 a new PEAKI is under the ThresholdI, the noise level is updated. 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. In the filtered signal the peak corresponding to the one evaluated on the integrated signal is searched and compared with a threshold, calculated in a similar way to the previous step: ThresholdF=NoiseLevelF+0.25(SignalLevelF−NoiseLevelF) SignalLevelF=0.125PEAKF+0.875SignalLevelF(if PEAKF is a signal peak) NoiseLevelF=0.125PEAKF+0.875NoiseLevelF(if PEAKF is a noise peak) where the final F stands for filtered signal.

Search back for missed QRS complexes The algorithm takes into account the possibility of setting too high values of ThresholdII and ThresholdIF. A check is performed to continuously assess the RR intervals (namely the temporal interval between two consecutively QRS peaks) to overcome this issue. The average RR is computed in two ways to consider both regular and irregular heart rhythm. In the first method RRaverage1 is computed as the mean of the last RR intervals. In the second method RRaverage2 is computed as the mean of the last RR intervals that fell between the limits specified as: RRlow=92%RRaverage2 RRhigh=116%RRaverage2 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.

… excerpt ends here. Continue reading the full article.

Illustrations

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

Worked examples

Example 1 — a first encounter with Pan–Tompkins algorithm

Start with the simplest possible case. Write down what Pan–Tompkins algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Pan–Tompkins algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Pan–Tompkins algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Pan–Tompkins algorithm

In research
Pan–Tompkins algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Pan–Tompkins algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Pan–Tompkins algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Algorithms, Cardiac electrophysiology, so understanding it makes those chapters shorter.
In everyday life
Look for Pan–Tompkins algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Pan–Tompkins algorithm” →

How to study Pan–Tompkins algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Pan–Tompkins algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Pan–Tompkins algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Pan–Tompkins algorithm in simple terms?

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).

Why does Pan–Tompkins algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Pan–Tompkins algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Pan–Tompkins algorithm.

Tags

  • Algorithms
  • Cardiac electrophysiology

Keep exploring