A Real-Time QRS Detection Algorithm
A Real-Time QRS Detection Algorithm
3, MARCH 1985
Abstract-We have developed a real-time algorithm for detection of a derivative, and a moving window integrator. The nonlinear
the QRS complexes of ECG signals. It reliably recognizes QRS com- transformation that we use is signal amplitude squaring.
plexes based upon digital analyses of slope, amplitude, and width. A Adaptive thresholds and T-wave discrimination techniques pro-
special digital bandpass filter reduces false detections caused by the var-
ious types of interference present in ECG signals. This filtering permits vide part of the decision rule algorithm.
use of low thresholds, thereby increasing detection sensitivity. The algo- The slope of the R wave is a popular signal feature used to
rithm automatically adjusts thresholds and parameters periodically to locate the QRS complex in many QRS detectors [5]. An
adapt to such ECG changes as QRS morphology and heart rate. For analog circuit or a real-time derivative algorithm that provides
the standard 24 h MIT/BIH arrhythmia database, this algorithm cor- slope information is straightforward to implement. However,
rectly detects 99.3 percent of the QRS complexes.
by its very nature, a derivative amplifies the undesirable higher
frequency noise components. Also, many abnormal QRS com-
INTRODUCTION plexes with large amplitudes and long durations are missed in
THERE are many uses for a reliable QRS recognition algo- a purely derivative approach because of their relatively low R-
rithm. Computer interpretation of the 12-lead ECG is a wave slopes. Thus, R-wave slope alone is insufficient for proper
popular technique. Coronary care units now use arrhythmia QRS detection. To achieve reliable performance, we must ex-
monitors extensively. Widely used Holter tape recording re- tract other parameters from the signal such as amplitude, width,
quires a Holter scanning device that includes a QRS detector and QRS energy [6], [7].
to analyze the tapes much faster than real time. Currently It is very important to evaluate a QRS detector algorithm
under development are arrhythmia monitors for ambulatory using a standard arrhythmia database. There are now two such
patients which analyze the ECG in real time [1] -[31. When databases available: MIT/BIH [8] and AHA (American Heart
an arrhythmia appears, such a monitor can be programmed to Association) [9] . The performance of an algorithm on a data-
immediately store an interval of the abnormal ECG for sub- base is not the ultimate answer as to its utility in a clinical en-
sequent transmission to a central station where a physician can vironment, but it provides a standardized means of comparing
interpret it. Such a device requires a very accurate QRS recog- the basic performance of one algorithm to another.
nition capability. False detection results in unnecessary trans- ALGORITHM OVERVIEW
mission of data to the central station or requires an excessively We implemented the QRS detection algorithm in assembly
large memory to store any ECG segments that are unnecessarily language. It operates on either a Z80 (Zilog) or an NSC800
captured. Thus, an accurate QRS detector is an important part (National Semiconductor) microprocessor. All the processing
of many ECG instruments. is done with integer arithmetic so that the algorithm can op-
QRS detection is difficult, not only because of the physio- erate in real time without requiring excessive computing power.
logical variability of the QRS complexes, but also because of The database provides two simultaneous ECG channels. We
the various types of noise that can be present in the ECG signal. attempted two-channel analysis, but abandoned this approach.
Noise sources include muscle noise, artifacts due to electrode Due to the way that the electrode positions are orthogonally
motion, power-line interference, baseline wander, and T waves placed in Holter recording, a high-quality signal on one channel
with high-frequency characteristics similar to QRS complexes. normally implies a low-amplitude ECG with a poor signal-to-
In our approach, digital filters reduce the influence of these
noise ratio on the second channel. The only way that two-
noise sources, and thereby improve the signal-to-noise ratio. Of channel algorithms will yield improved performance for most
the many QRS detectors proposed in the literature, few give
serious enough attention to noise reduction.
patients is by adopting a new way of electrode placement that
will provide usable signals in both channels.
Software QRS detectors typically include one or more of Fig. 1 shows signals at various steps in digital signal processing.
three different types of processing steps: linear digital filtering, First, in order to attenuate noise, the signal passes through a
nonlinear transformation, and decision rule algorithms [4]. We digital bandpass filter composed of cascaded high-pass and low-
use all three types. Linear processes include a bandpass filter, pass filters. Fig. l(b) shows the output of this filter. The next
Manuscript received July 27, 1984; revised October 24, 1984. This
process after filtering is differentiation [see Fig. 1 (c)] , followed
work was supported in part by the National Institutes of Health under by squaring [see Fig. 1 (d)], and then moving window integra-
Grant HL00765. tion [see Fig. 1 (e)]. Information about the slope of the QRS
J. Pan is with the Department of Biophysics, Shanghai Second Medical is obtained in the derivative stage. The squaring process in-
College, Shanghai, People's Republic of China.
W. J. Tompkins is with the Department of Electrical and Computer tensifies the slope of the frequency response curve of the deriv-
Engineering, University of Wisconsin, Madison, WI 53706. ative and helps restrict false positives caused by T waves with
(a)
(a)
(b)
(b)
(c)
(c)
(d)
(d)
(e)
(f) (e)
occurs following the end of the refractory period but within Frequency (Hz)
360 ms of the previous complex, we must determine if it is a
valid QRS complex or a T wave. In this case, we judge the
waveform with the largest slope to be the QRS complex.
To be reliable, a QRS detection algorithm must adapt each
of its parameters with time so as to be able to operate properly .L;
for ECG's of different patients as well as for ECG morphology (r)
changes in a single patient. In our algorithm, each threshold
automatically adapts periodically based upon peak values of L
the second one. The algorithm adapts rapidly to a changing H(Z) z 1)2
(1)
signal. It can even adapt rapidly when switching from one The amplitude response is
patient's ECG to another without requiring special learning
phases. sin2 (3oT)
METHODS
HwT =sin2 (wTI2) (2)
An analog filter bandlimits the ECG signal at 50 Hz. An ana- where T is the sampling period. The difference equation of
log-to-digital converter (ADC) samples the ECG at a rate of 200 the filter is
samples/s. The resulting digital signal passes successively y(nT) = 2y(nT - T) - y(nT - 2 T) + x(nT)
through a sequence of processing steps that includes three
linear digital filters implemented in software. First is an integer- - 2x(nT- 6T)+x(nT- 12T) (3)
coefficient bandpass filter composed of cascaded low-pass and where the cutoff frequency is about 11 Hz and the gain is 36.
high-pass filters. Its function is noise rejection. Next is a filter The filter processing delay is six samples.
that approximates a derivative. After an amplitude squaring
process, the signal passes through a moving-window integrator. High-Pass Filter
Adaptive thresholds then discriminate the locations of the QRS The design of the high-pass filter is based on subtracting the
complexes. output of a first-order low-pass filter from an all-pass filter (i.e.,
Bandpass Filter the samples in the original signal). The transfer function for
such a high-pass filter is
The bandpass filter reduces the influence of muscle noise,
60 Hz interference, baseline wander, and T-wave interference. (1+z1)) (4)
The desirable passband to maximize the QRS energy is approx- H(z)
=
imately 5-15 Hz [10], (111. Our filter is a fast, real-time re- The
cursive filter in which poles are located to cancel zeros on the amplitude response is
unit circle of the z plane [12] . This approach results in a filter
design with integer coefficients. Since only integer arithmetic |H(wT)I = [256 +cossin2(wT/2)
(16cT)] 1/2 (5)
is necessary, a real-time filter can be implemented with a simple
microprocessor and still have available computing power left The difference equation is
to do the QRS recognition task. y(nT) = 32x(nT - 16 T) - [y(nT - T)
This class of filters having poles and zeros only on the unit
circle permits limited passband design flexibility. For our + x(nT) - x(nT - 32 T)] . (6)
chosen sample rate, we could not design a bandpass filter di- The low cutoff frequency of this filter is about 5 Hz, the gain
rectly for the desired passband of 5-15 Hz using this specialized is 32, and the delay is 16 samples.
design technique. Therefore, we cascaded the low-pass and
high-pass filters described below to achieve a 3 dB passband Derivative
from about 5-12 Hz, reasonably close to the design goal. Fig. 3 After filtering, the signal is differentiated to provide the QRS-
shows the overall frequency response. complex slope information. We use a five-point derivative with
PAN AND TOMPKINS: REA L-TIME QRS DETECTION ALGORITHM 233
that is not related to the QRS (e.g., the Twave). The thresh- RR AVERAGE2 = 0.125 (RR'_7 + RR'?6 + * * + RR') -
olds are based upon running estimates of SPKI and NPKI. That (25)
is, new values of these variables are computed in part from their
prior values. When a new peak is detected, it must first be where RR' is the most recent RR interval that fell between
classified as a noise peak or a signal peak. To be a signal peak, the acceptable low and high RR -interval limits. The RR -inter-
the peak must exceed THRESHOLD I1 as the signal is first val limits are
analyzed or THRESHOLD 12 if searchback is required to find RR LOW LIMIT = 92% RR AVERAGE2 (26)
the QRS. When the QRS complex is found using the second
threshold-, RR HIGH LIMIT = 116% RR AVERAGE2. (27)
SPKI = 0.25 PEAKI + 0.75 SPKI. (16) RR MISSED LIMIT = 166% RR AVERAGE2 (28)
The set of thresholds applied to the filtered ECG is determined If a QRS complex is not found during the interval specified
from by the RR MISSED LIMIT, the maximal peak reserved between
the -two established thresholds is considered to be a QRS
SPKF = 0.125 PEAKF + 0.875 SPKF candidate.
(if PEAKF is the signal peak) (17) If each of the eight most-recent sequential RR intervals that
are calculated from RR AVERAGE1 is between the RR LOW
NPKF = 0.125 PEAKF + 0.875 NPKF LIMIT and the RR HIGH LIMIT, we interpret the heart rate
(if PEAKF is the noise peak) (18) to be regular for these eight heart beats and
THRESHOLD F1 = NPKF + 0.25 (SPKF - NPKF) (19) RR AVERAGE2>-RR AVERAGE1. (29)
THRESHOLD F2 = 0.5 THRESHOLD Fl (20) This is the case for normal sinus rhythm.
where all the variables refer to the filtered ECG: T-Wave Identification
PEAKF is the overall peak, When an RI interval is less than 360 ms (it must be greater
SPKF is the running estimate of the signal peak, than the 200 ms latency), a judgment is made to determine
NPKF is the running estimate of the noise peak, whether the current QRS complex has been correctly identified
THRESHOLD Fl is the first threshold applied, and or whether it is really a T wave. If the maximal slope that
THRESHOLD F2 is the second threshold applied. occurs during this waveform is less than half that of the QRS
waveform that preceded it, it is identified to be a Twave; other-
When the QRS complex is found using the second threshold,
wise, it is called a QRS complex.
SPKF = 0.25 PEAKF + 0.75 SPKF. (21)
EVALUATION
For irregular heart rates, the first threshold of each set is re- We used the MIT/BIH arrhythmia database to evaluate the
duced by half so as to increase the detection sensitivity and to QRS detection algorithm [8]. The database consists of 48
avoid missing beats: half-hour recordings for a total of 24 h of ECG data. The data-
THRESHOLDII v- 0.5 THRESHOLD II (22) base is on four-channel FM magnetic tape. Channels I and 2
are the two-channel ECG signals. Channel 3 is an annotation
THRESHOLD Fl 0.5 THRESHOLD Fl. (23)
channel recorded in a standard binary format, and channel 4
To be identified as a QRS complex, a peak must be recognized is a binary-recorded timing track.
as such a complex in both the integration and bandpass-filtered Fig. 6 shows the experimental setup for evaluation of the
waveforms. QRS algorithm. It includes two four-channel FM tape re-
Adjusting the Average RR Interval and Rate Limits corders, two Z80-based laboratory microcomputer systems, a
dc amplifier, and a nonfade oscilloscope.
Two RR-interval averages are maintained. One is the average Using the QRS detection algorithm, one of the microcom-
of the eight most-recent beats. The other is the average of the puter systems samples and analyzes the database ECG played
eight most-recent beats having RR intervals that fall within cer- back from one of the FM recorders. If it detects a QRS com-
tain limits. The reason for maintaining these two separate aver- plex, it generates a pulse. Simultaneously, the second micro-
ages is to be able to adapt to quickly changing or irregular heart computer monitors the encoded beat annotation channel of
rates. The first average is the mean of the eight most-recent the recorder and generates a pulse coincident with the fiducial
sequential RR intervals regardless of their values. mark annotated in the database.
RR AVERAGE1 = 0.125 (RRIn-I7 +RRIn-6 + -+RRn) A second four-channel FM tape recorder records the original
ECG waveform being analyzed on one channel and the pulses
(24) from each of the microcomputer systems on two other chan-
where RR n is the most-recent RR interval. nels. All of these signals appear on a nonfade display oscillo-
The second average is based on selected beats. scope or a chart recorder for further visual evaluation.
PAN AND TOMPKINS: REAL-TIME QRS DETECTION ALGORITHM 23 5
[8] "MIT/BIH arrhythmia database-Tape directory and format spec- and the second year was at the University of Wisconsin, Madison, where
ification," Document BMEC TR00, Mass. Inst. Technol., Cam- he completed the work reported here.
bridge, 1980. Database is available from Bioengineering Divi-
sion KB-26, Beth-Israel Hospital, 330 Brookline Avenue, Boston,
MA 02215.
[9] "AHA database." Database is available from Emergency Care Re-
search Institute, 5200 Butler Pike, Plymouth Meeting, PA 19462.
[10] H. G. Goovaerts, H. H. Ros, T. J. vanden Akker, and H. Schneider,
"A digital QRS detector based on the principle of contour lim- f Willis J. Tompkins (S'61-M'66-SM'77) received
iting,"IEEE Trans. Biomed. Eng., vol. BME-23, p. 154, 1976. _ the B.S. and M.S. degrees in electrical engi-
[11] N. V. Thakor, J. G. Webster, and W. J. Tompkins, "Optimal QRS
detector," Med. BioL Eng. Comput., vol. 21, pp. 343-350, 1983.
>
| lmW
neermg from the University of Maine, Orono,
in 1963 and 1965, respectively, and the Ph.D.
[12] P. A. Lynn, "Online digital filter for biological signals: Some fast degree in biomedical electronic engineering from
designs for a small computer," Med. Biol. Eng. Comput., vol. 15, *; £0i the University of Pennsylvania, Philadelphia, in
pp. 534-540, 1977. 1973.
From 1965 to 1968 he was an Electrical Engi-
neer at Sanders Associates, Inc., Nashua, NH,
where he worked on research and development
of data storage systems. He was employed from
1973 to 1974 at the Hospital of the University of Pennsylvania as a Bio-
medical Engineer. Since 1974 he has been on the Faculty of the Uni-
Jiapu Pan received the M.D. degree in 1962 with versity of Wisconsin, Madison, where his teaching specialty is on the
a specialty in biophysics in medicine from the topic of computers in medicine, an area in which he has developed two
Shanghai Second Medical College, Shanghai, new courses. His research interests include on-line biomedical computing
People's Republic of China. applications. He is co-editor, with J. G. Webster, of the textbookDesign
Since that time, he has been on the Faculty of Microcomputer-Based Medical Instrumentation (Englewood Cliffs,
of the Department of Biophysics of the Shanghai NJ: Prentice-Hall, 1981) and co-editor, with J. G. Webster, A. M. Cook,
Second Medical College. His background in- and G. C. Vanderheiden, of the textbook Electronic Devices for Re-
cludes research in medical applications of lasers, habilitation (New York: Wiley, 1984).
flow cytometry for single cell analysis and Dr. Tompkins is a member of the IEEE Engineering in Medicine and
sorting, artificial arm control using electromyo- Biology Society (currently Region IV Administrative Committee Rep-
graphic signals, body surface mapping in electro- resentative and Vice President for Technical Activities), the IEEE Com-
cardiography, and microcomputer-based medical instrumentation. Re- puter Society, the Association for the Advancement of Medical Instru-
cently he spent two years in the United States as a visiting scholar. The mentation, and the Biomedical Engineering Society. He is a Registered
first of these was at Case Western Reserve University, Cleveland, OH, Professional Engineer in the State of Wisconsin.