Dipjyoti onset and offset points of P, QRS

Dipjyoti Bisharad1, Debakshi Dey1, Brinda Bhowmick1


1 National Institute of Technology Silchar,
Silchar – 788010, Assam, India

{dipjyotibisharad.nit, deydebakshi16,

Abstract. Electrocardiography (ECG or
EKG) is a widely employed non invasive technique to determine the condition of
human heart and detect any abnormal cardiac behavior. Computer systems for ECG
analysis can aid physicians in prompt detection of dangerous events such as
ventricular fibrillation in patients with high cardiac risks. The first and
crucial part of automatic analysis of ECG signals is to accurately identify and
measure characteristic features of ECG signal, which is to locate exact
position of the onset and offset points of P, QRS and T-waves. In this paper,
we propose a fast technique that can accurately identify these key reference
points using local windows around R peaks. The proposed method has been tested
on standard QT database and a very high accuracy of above 99% is achieved on
identifying different segments in ECG signal.

Keywords: electrocardiogram, pattern
recognition, ECG features, ECG segmentation.

1   Introduction

An ECG signal originates from the electrical
activity of the heart that coordinates the contraction and relaxation of the
different chambers of the heart. The analysis of ECG signal and detection of
its characteristic points can be used to identify various heart rhythm
abnormalities, chest pains and other diseases. One cardiac cycle in a ECG
signal comprises P, QRS and T wave complexes.

The field of
automatic ECG analysis has become quite mature. There has been a lot of prior
work done in identifying characteristic points in ECG signals. However most of
these use sophisticated and complex signal processing techniques which make
them computationally expensive. In 11, the Pan Tompkins proposed a method
which recognizes the QRS complexes using the information on the signal’s slope,
amplitude and width. But the dual-threshold technique used in this method for
searching back the missed out complexes is only useful if the heart rate is
regular and unable to find out the missed beats in case of abnormalities.  In 12, all the P, QRS and T complexes are
detected using wavelet transform method but the P and T onsets and offsets are
not detected with much accuracy under serious noise influence. 13 shows
detection of the P wave in addition to the QRS complex using Hidden Markov
Model. In 14, QRS complexes are detected using moving-average filters but
this methodology is not robust to false positives or false negatives. The QRS
complex detection technique proposed in 15 applied first-order derivative and
adaptive threshold adjustment to detect the complexes and filtered the
high-frequency noise by employing discrete wavelet transform. 16 introduces a
new and fast version of ECG delineation algorithm using line fitting but is not
robust against certain arrhythmias where no wave is detected. Support vector
machine has been used for detection of P and T waves in 17. In 18 the QRS
complexes have been clustered into different groups using self-organizing
neural networks for detection. The algorithm proposed in 19 can be evaluated
for both clinical and telehealth ECG data. The work in 20 describes a complex
QRS detector which is based on dyadic wavelet transform. It gave good
performance for multiform premature ventricular contractions, bigeminy, and
couplets tapes. 21 employs S-transform to isolate QRS complexes and Shannon
energy for localizing R waves. Detection of QRS complexes is also found in 22
that has been performed using difference equation operation. In 23 a QRS
complex detector with limited hardware resources has been proposed.

In our paper,
we aim towards detecting the P, QRS and T complexes in a reliable and robust
way using local windowing which gives a very high detection accuracy and has
O(N) computational complexity in detecting P, Q, S and T waves.

This paper is organized as follows. In section 2, we present a brief
discussion on the anatomy of ECG signal and its characteristic waveforms,
Section 3 provides a description of the dataset that has been used to evaluate
the proposed method. In section 4, we discuss the methodologies and algorithms
implemented in this work. The results that the evaluation has yielded are shown
in section 5 and 6 with quantitative as well as qualitative interpretations.
Finally, Section 7 concludes the paper.

2   Review of the Morphology of
ECG Signal

The ECG captures the direction and magnitude of electrical
depolarization and repolarization generated by a person during his one cycle of
heartbeat. The components of a normal ECG tracings consists of multiple
waveforms each indicating an electrical event during one heart beat. These
waveforms are labeled as P wave, QRS complex and T wave as shown in Fig. 1 .
There is another small wave called U wave which is the successor of the T wave
and may not always be observed as a result of its small size 2. We ignore U
wave in this work.

P wave marks the beginning of the ECG cycle
and is the first short upward movement of the ECG tracing. It indicates that
the atria are contracting, pumping blood into the ventricles. It is followed by
the QRS complex, normally beginning with a downward deflection, denoted as Q; a
larger upward deflection, a peak denoted as R; and then a downward S wave.

Fig.1. Schematic diagram of single ECG wave. {src:


The QRS complex represents ventricular
depolarization and contraction. The PR interval indicates the transit time for
the electrical signal to travel from the sinus node to the ventricles. T wave
is normally a modest upwards waveform representing ventricular repolarization.
However in certain cases, T wave can be inverted 3.

Each of these wave has a characteristic duration. The P-Wave lasts for
about 80 ms. The  normal PR interval in
an ECG wave ranges from 120 ms to 200 ms. Duration of PR-Segment is 50 ms to
120 ms. The QRS complex duration is about 80 ms to 120 ms. Duration of
ST-Segment is 80 ms to 120 ms. Duration of ST-Interval is 320 ms. The QT
interval is heart rate dependent. The normal QT intervals are less than 450 ms
for men and less than 460 ms for womenbut may vary from 270 ms at a heart rate
of 150 beats per min to 500 ms at a heart rate of 40 beats per min 4.

3 Dataset Description

Several databases are available for studying
and analyzing ECG data. The dataset  used
in this paper is the QT database which contains 105 records, each being 15
minutes in duration 5. It has been created by incorporating new data from
Holter recordings of patients into the MIT-BIH Arrhythmia Database, the European Society of Cardiology ST-T Database and several
other databases 6-7.The sampling frequency of all the records in this
database is 250 Hz. The reason behind choosing this database for the evaluation
of our algorithm is that reference annotations have been given to mark the
waveform boundaries in addition to those already marked in the other databases.
More specifically, this database includes annotation for P and T complexes in
addition to annotations for Q, R and S complexes thus helping us to compare our
obtained results.

4   Methodology

From the discussion on the morphology of ECG
signal in section 2, it can be observed that the points of interest viz. P, Q,
R, S and T have a distinct and characteristic physical appearance. Also if any
one of these points is known, then rest of the points can be identified from
its neighborhood with fair accuracy. For instance, P peak is the local maxima
between the R peak of the corresponding wave and T peak of the previous wave; Q
trough is the local minima between P peak and R peak. Similar neighborhood
characteristics exist for S and T wave. Hence by only knowing the position of R
peak, all the other waves can be identified from the signal. In this work, we
exploit these local features of P, Q, R, S and T waves to locate them.

The steps followed in this work can be
summarized as follows:

Step 1: The digitized ECG data from the database is
filtered with a bandpass FIR filter with lower and upper cutoff frequency of 3
Hz and 45 Hz respectively to remove noises originating due to electromyogram
(EMG) signals, high frequency interferences, DC offset and baseline wandering

Step 2: From the filtered signal, the R peak is
extracted using the R segmentation algorithm proposed by Hamilton in 9.

Step 3: After extracting the location of R peaks, the
location of remaining four peaks is computed using local context window in the
neighborhood of corresponding R peak.

The primary contribution of this work is in
step 3 and is discussed in detail in following sub-sections.


Detection of P peaks

2. The points A and B denote
the beginning and end of the context window respectively for the detection of
P peak; A and B are 100 ms apart; Point B is 100
ms offset from R.


After filtering the signal and locating R
peaks, we proceed towards locating P peaks. As stated earlier, P peak is
approximated as the local maxima between R peak and T peak of previous wave.
However, considering the entire region between T peak and R peak can lead to
increased false positives since this region is quite extended, can be noisy and
have multiple peaks and troughs. Hence, a reduced context window of 100 ms
duration is chosen which is offset from R peak by 100 ms on the left. A typical  boundary of the context window for detecting
P waveare marked A and B as shown in Fig 2. The peak of P wave is taken as
maximum of the values in the context window.


Detection of Q – trough


Q trough is the point of inflexion between PR
segment and QRS complex. To determine its position, a context window of 100 ms
is taken. The window terminates at the position of R peak. The Q peak is taken
at point of minimum value within the window as shown in Fig. 3.

3.The points A and B denote the beginning and end of the
context window respectively for the detection of Q  trough; A and B are 100 ms
apart; Point B coincides with the location of R.

4.3   Detection of S – trough

The S trough is the point of inflexion between QRS complex and ST
segment. To determine its position, a context window of 100 ms is taken. The
window originates at the position of R peak as shown in Fig. 4. The S peak is
taken at point of minimum value within the window.


4.The points A and B denote the beginning and end of the
context window respectively for the detection of S trough; A and
B are 100 ms apart; Point A coincides with the location of R.

4.4   Detection of T – peak

As stated in section 2, T peak possess a unique property of being
inverted in some cases. Thus, within the context window, the T peak will be
either the minima or maxima, whichever has the maximum magnitude. To remove
this ambiguity, all the values within the window are squared. Thus T peak will
necessarily be at the location of the value having maximum squared magnitude.
However, there is a glitch. In case there is an inverted T peak, the voltage
level at the peak might lie below 0 V, and possibly in between 0 mV and -1 mV.
In that case, squaring a value between 0 and 1 will, in turn, reduce its magnitude.
Thus a threshold of 1mV is added to all the values before squaring them.

T peaks occur fairly long after QRS wave and may be present in an
extended region. Thus the size of context window is increased to 200ms duration
and is offset to the right by 200 ms from the position of R peak.Fig. 5 shows
the window boundaries A and B for locating T peak.

5. The points A and B denote the beginning and end of the
context window respectively for the detection of T peak; A and B
are 200 ms apart; Point A is 200 ms offset from R.

5   Comparing the Annotation

this section we present a qualitative visual evaluation of our proposed method.
The record  sel17453 from the QT database
is annotated with the annotations given in the dataset itself and with the
annotations generated from our model as shown in Fig. 6. We observe that the
annotations closely match with each other. This indicates that our model is
working as expected on this benchmark dataset.

(a) Raw unannotated
ECG data extract

(b) Extract
annotated with .q1c

Fig. 6.Original signal and annotation from .q1c on the waveform of the
signal from record  sel17453 in the interval 612 to 614.5


(c) Extract
annotated with .pu0

(d) Extract
annotated with our proposed method

Fig. 7.Annotations from .pu0
and from our proposed method on the waveform of the signal from record  sel17453
in the interval 612 to 614.5 sec

6   Results and Discussions

In this section we present a quantitative evaluation of our model. By
applying the methods described in section 4, we annotate all the 105 records in
QT database and compare our annotations with the annotations given in the
dataset. The dataset has 9 annotation files in total. To evaluate our proposed
method, we chose two of the annotation files from the dataset. The first one is
.pu0 annotation which contains automatically determined waveform
boundary measurements for all beats. The second set of annotation files
considered is .q1c annotation which contains manually determined
waveform boundary measurements for a small fraction of beats. We compared our
results against reference annotations allowing for a 5% tolerance level; that
is, a prediction is deemed correct if its value falls within a range of ±5% of
the reference value.

Table 1. Evaluation results.



Total number of
correct predictions

Total number of
incorrect predictions

Overall Accuracy

Median Accuracy
























































As an evaluation metric, for each P, Q, R, S and T, we list the total
number of correct predictions, total number of incorrect predictions, overall
accuracy and median accuracy across 105 records achieved by our proposed method
for respective peaks and troughs.

The results are extremely impressive. We
obtain 100% median accuracy on 105 records for all the waves across both the
reference annotations. We also obtain very staggering overall accuracy on .pu0
annotations. However the accuracy for .q1c is not as good as that for .pu0.
However manual inspection of .q1c annotations showed that some annotations were
fairly deviated from where they ought to be. Fig 8 shows an extract of the data
of ECG record sel17453 from the dataset and it is annotated from its
.q1c file. It can be observed that R and S are not correctly labeled; also T is
slightly offset from its appropriate location. We think that small sample size
of .q1c annotations accompanied with inaccurate annotations might have affected
the statistics that resulted in lower accuracy for P, Q and S.


Fig. 8. .q1c annotations on the waveform of the
signal from record  sel17453 in the interval 618.5 to 622 sec

It is also observed from Table 1. that the
overall accuracy for T peak detection is lower than its counterparts. It is to
be pointed out that detecting T peaks is in fact a non trivial task. Detecting
T wave accurately is more challenging than detecting QRS complex due toits low
amplitudes, low signal-to-noise ratio (SNR), amplitude and morphology
variability, and possible overlapping of the P wave and T wave 10. The
approximation used to detect boundaries of T wave in this proposed method works
efficiently for normal ECG signal but may give inaccurate results for certain
kinds of abnormal ECG signals. We acknowledge this as a limitation of our
proposed method.

7   Conclusion

In this work, we demonstrated a robust and fast method to detect the P,
Q, S and T waves. The algorithm runs in linear time with respect to size of
input data because the algorithm is essentially finding maximum or minimum
value within an array of numbers. The method is highly accurate, particularly
for normal ECG signals. The proposed technique can be used to estimate the
boundaries of an ECG signal and then the extracted samples can be used for
further analysis.



The authors would like to thank Innovation & Entrepreneurship
Development Centre, NIT Silchar for funding this project. The authors are also
grateful to Mr. Arkajyoti Saha and Ms. Maitrayee Deb of Silchar Medical College
and Hospital for their valuable inputs and suggestions.


1 Baldonado, M., Chang, C.-C.K., Gravano, L., Paepcke, A.: The
Stanford Digital Library Metadata Architecture. Int. J. Digit. Libr. 1 (1997)

2 di Bernardo, D. and Murray, A., 2002. Origin on the
electrocardiogram of U-waves and abnormal U-wave inversion. Cardiovascular
research, 53(1), pp.202-208.

3 Hoffman, B.F. and Cranefield, P.F., 1960. Electrophysiology of
the Heart.McGraw-Hill, Blakiston Division.

4 Joshi, Anand Kumar, ArunTomar, and MangeshTomar. “A Review Paper
on Analysis of Electrocardiograph (ECG) Signal for the Detection of Arrhythmia
Abnormalities.” International Journal of Advanced Research in
Electrical, Electronics and Instrumentation Engineering 3, no. 10 (2014).

5 Laguna P, Mark RG,
Goldberger AL, Moody GB. A Database for
Evaluation of Algorithms for Measurement of QT and Other Waveform Intervals in
the ECG.Computers
in Cardiology24:673-676

6 Moody GB, Mark RG. The impact of the MIT-BIH Arrhythmia Database. IEEE
Eng in Med and Biol 20(3):45-50 (May-June 2001). (PMID: 11446209)

7 Taddei
A, Distante G, Emdin M, Pisani P, Moody GB, Zeelenberg C, Marchesi C. The
European ST-T Database: standard for evaluating systems for the analysis of
ST-T changes in ambulatory electrocardiography. European Heart Journal13:
1164-1172 (1992)

8  Thakor, Nitish V., and
Y-S. Zhu. “Applications of adaptive filtering to ECG analysis: noise
cancellation and arrhythmia detection.” IEEE transactions on
biomedical engineering 38.8 (1991): 785-794.

9  Hamilton, P. “Open
source ECG analysis.” In Computers in Cardiology, IEEE (2002): 101-104.

10  Elgendi, Mohamed,
Bjoern Eskofier, and Derek Abbott. “Fast T wave detection calibrated by
clinical knowledge with annotation of P and T waves.” Sensors 15,
no. 7 (2015): 17693-17714.

11 Pan, Jiapu, and Willis J. Tompkins. “A real-time QRS detection
algorithm.”IEEE transactions on biomedical engineering 3 (1985):

12 Li, Cuiwei, Chongxun Zheng, and Changfeng
Tai. “Detection of ECG characteristic points using wavelet
transforms.”IEEE Transactions on biomedical Engineering 42, no. 1
(1995): 21-28.

13 Coast, Douglas A., Richard M. Stern, Gerald G. Cano, and Stanley A.
Briller. “An approach to cardiac arrhythmia analysis using hidden Markov
models.”IEEE Transactions on biomedical Engineering 37, no. 9
(1990): 826-836.

14Elgendi, Mohamed. “Fast QRS detection with an
optimized knowledge-based method: Evaluation on 11 standard ECG
databases.”PloS one 8, no. 9 (2013): e73557.

15 Karimipour, Atiyeh, and Mohammad Reza Homaeinezhad.
“Real-time electrocardiogram P-QRS-T detection–delineation algorithm based
on quality-supported analysis of characteristic templates.”Computers in
biology and medicine 52 (2014): 153-165

16 Leutheuser, Heike, Stefan Gradl, Lars Anneken, Martin
Arnold, Nadine Lang, Stephan Achenbach, and Bjoern M. Eskofier.
“Instantaneous P-and T-wave detection: Assessment of three ECG fiducial
points detection algorithms.” In Wearable and Implantable Body Sensor
Networks (BSN), 2016 IEEE 13th International Conference on, pp. 329-334.
IEEE, 2016.

17 Mehta, S. S., and N. S. Lingayat. “Detection of
P and T-waves in Electrocardiogram.” In Proceedings of the world
congress on Engineering and computer science, pp. 22-24. 2008.

18 Lagerholm, Martin, Carsten Peterson, Guido Braccini,
Lars Edenbrandt, and Leif Sornmo. “Clustering ECG complexes using Hermite
functions and self-organizing maps.”IEEE Transactions on Biomedical
Engineering 47, no. 7 (2000): 838-848.

16 Khamis, Heba, Robert Weiss, Yang Xie, Chan-Wei Chang,
Nigel H. Lovell, and Steph9n J. Redmond. “QRS Detection Algorithm for
Telehealth Electrocardiogram Recordings.”IEEE Transactions on
Biomedical Engineering 63, no. 7 (2016): 1377-1388.

20 Kadambe, Shubha, Robin Murray, and G. Faye
Boudreaux-Bartels. “Wavelet transform-based QRS complex detector.”IEEE
Transactions on biomedical Engineering 46, no. 7 (1999): 838-848.

21 Zidelmal, Zahia, Ahmed Amirou, D. Ould-Abdeslam, Ali
Moukadem, and Alain Dieterlen. “QRS detection using S-Transform and
Shannon energy.”Computer methods and programs in biomedicine 116,
no. 1 (2014): 1-9.

22 Yeh, Yun-Chi, and Wen-June Wang. “QRS complexes
detection for ECG signal: The Difference Operation Method.”Computer
methods and programs in biomedicine 91, no. 3 (2008): 245-254.

23 Gutiérrez-Rivas, Raquel, Juan Jesús García, William
P. Marnane, and Álvaro Hernández. “Novel real-time low-complexity QRS
complex detector based on adaptive thresholding.”IEEE Sensors Journal
15, no. 10 (2015): 6036-6043.