Continuously Tested and Used QRS Detection Algorithm: Free Access To The MATLAB Code
Continuously Tested and Used QRS Detection Algorithm: Free Access To The MATLAB Code
Continuously Tested and Used QRS Detection Algorithm: Free Access To The MATLAB Code
61-70
Abstract: Each ECG analysis begins with the detection of the QRS complex, which is the most
distinguishable wave for initial investigation. Long ago we published an algorithm for
ventricular beats (VB) detection in single ECG lead. The classification of normal QRS
complexes is based on the slope, the amplitude and the width of the ECG waves.
Other criteria recognize ventricular ectopic beats (EB) by presence of biphasic beats and
separate premature EB from the already detected QRS complexes. The aim of this paper is to
place the MATLAB program of our algorithm at disposal to the readers (supplementary
MATLAB codes) looking forward to more successful ECG investigations.
Introduction
Each automated as well as manual ECG analysis comprises the next main stages: onset and
offset detection of the waveforms; measurement of their amplitudes, widths, intervals and
interrelationships; comparison between the extracted values and statistically created datasets of
criteria to classify the found ECG morphology as normal or pathological heart activity. To be
successful, the ECG analysis begins with the detection of the QRS complex, which is the most
distinguishable wave for initial investigation.
One of the first software algorithms for QRS detection has been published by Caceres and
Dreifus in the early 1970 [9]. The differentiated ECG signal was divided into short intervals
where the absolute maximums higher than a dynamic threshold were assumed to belong to QRS
complexes. Nowadays the number of the elaborated, tested and reported QRS algorithms is
enormous that proves implicitly the impossibility to build an ideal QRS detector covering all
the variety of shapes encountered in practice.
Generally, each QRS detection algorithm includes two parts: preprocessing and decision rule.
The preprocessing is aimed to suppress the disturbances accompanying the ECG signals
acquisition, such as power line interference (PLI), drift, tremor and artefacts due to bad
electrode-to-skin contact (Nenova and Iliev [20], Bhoi et al. [8], Razavi and Mohammadi [22]).
Here the processing parameters are selected rather to enhance the difference between the QRS
complex and the other waveforms than to keep the informative ECG features.
The decision rules are highly varied. The commonly used algorithms interpret features extracted
from first or second derivative of the ECG signal (Köhler et al. [17], Arzeno et al. [5]).
As an example, Hamilton and Tompkins [14] reported a first derivative based squaring function
61
INT. J. BIOAUTOMATION, 2019, 23(1), 61-70 doi: 10.7546/ijba.2019.23.1.61-70
for QRS detection. The last two decades have been proposed algorithms designed by filter
banks (Alfonso et al. [2]), wavelet transforms (Sumathi and Sanavullah [25], Sasikala and
Wahidabanu [24], Benali et al. [6]); artificial networks (Abibullaev and Seo [1]); Hilbert
transform (Benitez et al. [7]; Sahoo [23]); feature extraction (Paoletti and Marchesi [21],
Harikumar and Shivappriya [15]).
Kohler et al. [17] investigate the QRS complexes counting the number of high amplitude zero
crossings per segment in ECG signals, which are preliminary subjected to linear phase band
pass filtration to suppress the P- and T-waves together with the noise oscillations around the
zero line.
Kim and Shin [16] developed algorithm based on some spatiotemporal characteristic.
The power spectrum components of the ECG signal are currently assessed and the maximum
energy level within the 5÷25 Hz frequency band during a short time interval is accepted to
belong to QRS complex.
The Christov’s QRS detector [10] takes in consideration signals from one or more
simultaneously recorded channels. The signals are differentiated and their absolute values are
summed and compare to threshold with three components: adaptive slew-rate, correction
depending on the presence of high-frequency noise and criterion supporting the detection of
low amplitude QRS complexes. In another study [11] Christov reports new modifications of
the combined threshold method. The test carried out with the AHA database recordings
impresses with the obtained very high statistical indices.
Actually, the QRS detection represents a special case of ventricular beat (VB) recognition
(Christov [10]), which is followed by discrimination between normal sinus beats (NB) and
ectopic beats (EB) (Millet et al. [18], Dotsinsky and Stoyanov [13], Tanev [27]). This process
is the first step of both morphological and rhythm analysis. Epochs of sinus QRS complexes
are investigated for assessment of the heart rate variation (HRV). The EB are divided in
different types according to their shape and/or time of occurrence that is used further for rhythm
disorders discovery.
Tanev [27] describes very fast off-line procedure for accurate QRS detection in long term ECG
Holter recordings, followed by classification of the complexes in normal and ectopic beats. The
analysis of a 24 hour epoch needs no more than 7-8 min.
The efficiency of VB detection algorithms is usually tested with ECG signals taken from
internationally recognized databases, e.g., the AHA database, the MIT-BIH arrhythmia
database, the diagnostic PhysioNet database, etc. Generally, the performance of the algorithms
is assessed by calculating the true positive (TP), the true negative (TN), the false positive (FP)
and the false negative (FN) detections within the examined recording.
Then some indices are evaluated, for example the sensitivity Se = TP/(TP+FN) and the
specificity Sp = TN/(TN+FP), (Altman and Bland [4]); the positive and negative predictive
values PPV = TP/(TP+FP) and NPV = TN/(TN+FN), thus giving objective rating of the
algorithms accuracy.
As a rule, the TP, TN, FP and FN values are obtained by counting the coincidences between
the recognized and the annotated beats inside the used database. Because of the enormous data
array they have to be checked automatically.
62
INT. J. BIOAUTOMATION, 2019, 23(1), 61-70 doi: 10.7546/ijba.2019.23.1.61-70
The annotations have varying positions towards the complexes, e.g., in the AHA database they
are mostly near to the onset of the R wave. Suppappola and Sun [26] advised the users to define
themselves the interval that includes the ventricular beats or to set default borders at
10 ms before and 140 ms after the annotated locations. Dotsinsky and Stoyanov [13], as well
as Christov [10] use specially designed software, which inserts windows surrounding the
marked complexes by 60 ms. The algorithm published by Tanev [27] allows deviation of
±30 ms between the classified beats and the corresponding annotations.
Most of the published methods for QRS detection demonstrate very high performance values
typically more than 95%.
There are numerous papers with extremely scientific contributions. Usually the theoretical
approaches are perfectly carried out, the details are correctly revealed, and the results obtained
are convincingly illustrated by tables and figures. However, a few of the reported studies may
be easily implemented in similar investigations since usually no programs or extracted parts of
them are available to the readers.
Long ago we published an algorithm for VB detection in single ECG lead (Dotsinsky and
Stoyanov [13]). The normal QRS classification is based on the slope, the amplitude and the
width of the ECG waves. Other criteria recognize ventricular EB by presence of biphasic beats
and separate premature EB from already detected QRS complexes. Finally, sinus beats (NB)
and all ectopic beats (EB) are discriminated in two categories. The algorithm was tested in
MATLAB environment by the entire AHA [3] and MIT-BIH [19] databases demonstrating
99.04% sensitivity and 99.62% specificity, but more important is that it was shared with closed
friends thus proving high efficiency in practice.
QRS detection
The algorithm for ventricular beat detection (Dotsinsky and Stoyanov [13]) improves
previously developed method for QRS detection (Dotsinsky [12]). Two identical in sign
differences between the ongoing sample Si and the adjacent samples Sin and Si+n are currently
calculated, where n is usually equal to the number of samples within the interference period.
The positions of the ongoing samples Si either coincide with or are very near to peaks of the
investigated ECG signal. The absolute SUM of the differences
is compared to appropriate adaptive threshold AT. QRS candidates are marked each time when
SUM > AT. Fig. 1 shows three QT intervals with difficult for detection QRS complexes.
63
INT. J. BIOAUTOMATION, 2019, 23(1), 61-70 doi: 10.7546/ijba.2019.23.1.61-70
Fig. 1 Discrimination between different in shape QRS complexes and their T-waves
Nevertheless, the different SUM values ensure efficient discrimination between QRS and
T-waves. For better illustration of the principle based on high amplitude, steep edges and sharp
peak evaluation, the wave peaks are assumed to coincide with samples. Another sample
distribution over the QRS complex can be seen in Fig. 2a.
The initial value of AT is set to 0.2 mV (Dotsinsky and Stoyanov [13]). Except for occurrence
of very low peak amplitude, the threshold after each QRS detection becomes equal to 0.7 SUM.
It does not change for 200 ms to skip high-amplitude T-waves, decreasing further linearly in
accordance with different laws until and after the end of the first second.
A true beat candidate is expected to appear after a delay called DIST that is related to the
expected QT interval duration of the ongoing RR interval. Each beat candidate located to the
latest detected QRS complex nearer than DIST is ignored if its SUM is less than that of the latest
complex. Otherwise, the latest complex is discarded assuming it is a lower amplitude
component of the new candidate.
Further, the maximum value Vmax inside the interval of 120 ms around the candidate is found.
Its position is entered in buffer normal beats if Vmax > 80 µV and the number of zero crossings
N < 8. The first requirement allows the detection of low amplitude QRS complexes; the second
one is aimed to suppress electromyographic artifacts and other high frequency disturbances.
If the criteria are not met, W1 is discarded, while W2 and W3 are marked as W1 and W2.
They form the next two waves together with a new crossing W3. This cycle is repeated until EB
is detected. Its position is saved in buffer ectopic beats. Besides, it is entered in buffer
suspicious beats for additional analysis. The reason is that two consecutive VBs may occur at
distance shorter than DIST in case of long RR intervals, which include burst of EBs or EB
followed by compensatory pause.
Analogously, deviations of the QRS width and/or its maximum peak-to-peak amplitude may
erroneously classify normal QRS complex as ectopic beat. That is why other algorithm branch
compares the parameters of the currently detected QRS complexes with the corresponding
parameters of a template QRSe created during the first 12 detected beats to distribute the
64
INT. J. BIOAUTOMATION, 2019, 23(1), 61-70 doi: 10.7546/ijba.2019.23.1.61-70
suspicious or erroneous beats in the true buffers. Among the used parameters are the maximum
positive and negative amplitudes, their peak-to-peak amplitudes and the number of zero
crossings.
Fig. 2a. Discovery of typical QRS complex Fig. 2b. Investigation of ectopic beats
MATLAB codes
Two MATLAB codes for VB detection are available in compressed format at
http://www.biomed.bas.bg/bioautomation/2019/vol_23.1/files/23.1_06.zip
together with associated ECG signals.
They are structured in two directories: version1 and version2. You can download every one of
them and run the corresponding VB1.m or VB2.m code from archive 23.1_06.zip:
Free access to QRS detection code/version1/VB1.m
Free access to QRS detection code/version2/VB2.m
Our original MATLAB program discussed in the publication (Dotsinsky and Stoyanov [13])
was adapted to work with all ECG recordings from AHA and MIT-BIH databases, representing
a lot of files of many Mbytes that have to be open in a complicated manner, specifically for the
MIT-BIH database.
Therefore we compiled the file VB1.m to operate with several selected recordings, which are
quite enough to discover the algorithm potential. The file execution starts with question about
the database to be used. A click on the button AHA gives access to 8 recordings.
Four recordings are available if the reader chooses the button MIT-BIH but not before selecting
one of the two channels replying to a second question. The code entitled %epoch length
(enclosed inside 174th and 186th lines) defines either the entire ECG file or its selected part to
be opened, analyzed and displayed. The results are shown in sequence of figures, which include
two curves, the non-used lead and the original processed and analyzed lead together with the
marked normal and ectopic beats. In a lot of cases the correct recognition may be visually
confirmed by the accompanying lead.
Below are presented results of ventricular beat detection obtained with VB1.m. Figs. 3 and 4
show the recognized normal QRS complexes and ectopic beats in epochs taken from the
recordings AHA A7006D1 and MITBIH 212D2. Please, pay attention to the signal displayed
in Fig. 4, where all QRS complexes are correctly detected regardless of the abrupt waveform
change after the 251th s.
65
INT. J. BIOAUTOMATION, 2019, 23(1), 61-70 doi: 10.7546/ijba.2019.23.1.61-70
AHA A7006D1.DAT
[mV]
2
-2
60 61 62 63 64 65 66 67 68 69 70
upper trace (green) - the accompanying lead, lower trace (black) - the analyzed lead
4
[mV]
-2
70 71 72 73 74 75 76 77 78 79 80
4
[mV]
-2
80 81 82 83 84 85 86 87 88 89 90
[s]
Fig. 3
MIT-BIH 212D2.DAT
4
[mV]
240 241 242 243 244 245 246 247 248 249 250
upper trace (green) - the accompanying lead, lower trace (black) - the analyzed lead
4
[mV]
250 251 252 253 254 255 256 257 258 259 260
4
[mV]
260 261 262 263 264 265 266 267 268 269 270
[s]
Fig. 4
The second file VB2.m simplifies the algorithm implementation working with the
AHA/AHA6003d1 and MITBIH/203d1 recordings, which are preliminary opened and
secondary saved in a format suitable for analysis of reader’s files. Here the %epoch length
definition is inside 98th and 110th lines. The results of the investigated signals are demonstrated
in Figs. 5 and 6.
66
INT. J. BIOAUTOMATION, 2019, 23(1), 61-70 doi: 10.7546/ijba.2019.23.1.61-70
AHA/A6003d1
[mV]
0
-2
90 91 92 93 94 95 96 97 98 99 100
2
[mV]
-2
100 101 102 103 104 105 106 107 108 109 110
2
[mV]
-2
110 111 112 113 114 115 116 117 118 119 120
[s]
Fig. 5
MIT-BIH/203d1
1
[mV]
-1
-2
150 151 152 153 154 155 156 157 158 159 160
1
[mV]
-1
-2
160 161 162 163 164 165 166 167 168 169 170
1
[mV]
-1
-2
170 171 172 173 174 175 176 177 178 179 180
[s]
Fig. 6
More detail can be found in the attached MATLAB codes provided with comments.
67
INT. J. BIOAUTOMATION, 2019, 23(1), 61-70 doi: 10.7546/ijba.2019.23.1.61-70
Conclusion
We hope this paper may support the investigators in developing of complex ECG signal
analyses. The shared algorithm was tested with the entire AHA and MIT-BIH databases
demonstrating 99.04% sensitivity and 99.62% specificity.
The number of the attached to the first VB1.m version recordings is limited to save the space.
Still, we think they demonstrate quite enough the algorithm power, although the discrimination
between normal and ectopic beats can be improved. The reader can easily add other recordings
from the mentioned databases if necessary. The presence of the accompanying leads may
confirm the detection and classification considerations.
The two recorders attached to the second VB2.m version simplify the opening of files saved in
a wide accepted mode.
References
1. Abibullaev B., H. D. Seo (2011). A New QRS Detection Method Using Wavelets and
Artificial Neural Networks, J Med Syst, 35(4), 683-691.
2. Afonso V. X., W. J. Tompkins, T. Q. Nguyen, L. Shen (1999). ECG Beat Detection Using
Filter Banks, IEEE Trans Biomed Eng, 46, 192-202.
3. AHA (http://www.ecri.org/)
4. Altman D. G., J. M. Bland (1994). Diagnostic Tests 1: Sensitivity and Specificity, British
Medical Journal, 308(6943), p. 1552
5. Arzeno N. M., Z. D. Deng, C. S. Poon (2008). Analysis of First-derivative Based QRS
Detection Algorithms, IEEE Trans Biomed Eng, 55(2), 478-484.
6. Benali R., F. B. Reguig, Z. H. Slimane (2012). Automatic Classification of Heartbeats
Using Wavelet Neural Network, J Med Syst, 36(2), 883-892.
7. Benitez D., P. A. Gaydecki, A. Zaidi, A. P. Fitzpatrick (2001). The Use of the Hilbert
Transform in ECG Signal Analysis, Comput Biol Med, 31(5), 399-406.
8. Bhoi A. K., K. S. Sherpa, B. Khandelwal (2015). Classification Probability Analysis for
Arrhythmia and Ischemia Using Frequency Domain Features of QRS Complex,
International Journal Bioautomation, 19(4), 531-542.
9. Caceres C. A., L. S. Dreifus (1970). Clinical Electrocardiography and Computers,
Academic Press, New York, London.
10. Christov I. I. (2004). Real Time Electrocardiogram QRS Detection Using Combined
Adaptive Threshold, BioMed Eng OnLine, 3:28.
11. Christov I. I. (2007). Assessment of the Performance of the Adaptive Thresholding
Algorithm for QRS Detection with the Use of AHA Database, International Journal
Bioautomation, 6, 27-37.
12. Dotsinksy I. A. (1991). Software Real Time QRS Detection, Med Biol Eng Comput,
29(Suppl), 337.
13. Dotsinsky I. A., T. V. Stoyanov (2004). Ventricular Beat Detection in Single Channel
Electrocardiogram, BioMed Eng OnLine, 3:3.
14. Hamilton P. S., W. J. Tompkins (1996). Quantitative Investigation of QRS Detection Rules
Using the MIT/BIH Arrhythmia Database, IEEE Trans Biomed Eng, 12, 1157-1165.
15. Harikumar R., S. N. Shivappriya (2011). Analysis of QRS Detection Algorithm for Cardiac
Abnormalities – A Review, Int J Soft Comput Eng, 1(5), 80-88.
16. Kim J., H. Shin (2016). Simple and Robust Realtime QRS Detection Algorithm Based on
Spatiotemporal Characteristic of the QRS Complex, PLoS One, 11(3).
17. Köhler B.-U., C. Hennig, R. Orglmeister (2003). QRS Detection Using Zero Crossing
Counts, Progress in Biomed Res, 8(3), 138-145.
68
INT. J. BIOAUTOMATION, 2019, 23(1), 61-70 doi: 10.7546/ijba.2019.23.1.61-70
18. Millet J., M. Perez, G. Joseph, A. Mocholi, J. Chorro (1997). Previous Identification of
QRS Onset and Offset Is not Essential for Classifying QRS Complex in a Single Lead,
Computers in Cardiology, 24, 299-302.
19. MIT-BIH (http://www.physionet.org)
20. Nenova B., I. Iliev (2010). Automated Algorithm for Fast Pulse Wave Detection,
International Journal Bioautomation, 14(3), 203-216.
21. Paoletti M., C. Marchesi (2006). Discovering Dangerous Patterns in Long-term
Ambulatory ECG Recordings Using a Fast QRS Detection Algorithm and Explorative Data
Analysis, Comp Methods Progs Biomed, 82, 20-30.
22. Razavi S. R., M. H. D. Mohammadi (2017). R-peak Detection in Electrocardiogram Signals
Using Continuous Wavelet Transform, International Journal Bioautomation, 21(2),
165-178.
23. Sahoo S., P. Biswal, T. Das, S. Sabu (2016). De-noising of ECG Signal and QRS Detection
Using Hilbert Transform and Adaptive Thresholding, Procedia Technology, 25, 68-75.
24. Sasikala P., R. S. D. Wahidabanu (2010). Robust R Peak and QRS Detection in
Electrocardiogram Using Wavelet Transform, Int J Advanced Computer Science
Applications, 1(6), 48-53.
25. Sumathi S., M. Y. Sanavullah (2009). Comparative Study of QRS Complex Detection in
ECG Based on Discrete Wavelet Transform, Int J Recent Trends Eng, 2(5), 273-277.
26. Suppappola S., Y. Sun (1994). Nonlinear Transforms of ECG Signals for Digital QRS
Detection: A Quantitative Analysis, IEEE Trans Biomed Eng, 41, 397-400.
27. Tanev S. (2012). Ventricular Beat Detection in Long Term ECG Recordings, International
Journal Bioautomation, 16(4), 273-290.
69
INT. J. BIOAUTOMATION, 2019, 23(1), 61-70 doi: 10.7546/ijba.2019.23.1.61-70
70