a free software tool for automatic analysis of ecg ·  · 2013-10-09a free software tool for...

19
A Free Software Tool for Automatic Analysis of ECG Christian Iglesias Zazueta, Xos´ e A. Vila, Mar´ ıa J. Lado Escola Superior de Enxe˜ ner´ ıa Inform´ atica - Universidade de Vigo http://www.milegroup.net Abstract. The proposal of this work was to develop an automatic al- gorithm for QRS complex (beat) detection in electrocardiograms (ECG) using free software. The recognition of the QRS complex was imple- mented using both wavelets and the Pan-Tompkins algorithm. Initially, the algorithm read a header file where all the information was stored. With the information obtained, a binary file containing the ECG data was retrieved and processed. In this way, beats were detected by auto- matically thresholding the signal. Several data files from the PhysioBank database were used to test the algorithms. The Pan-Tompkins algorithm reached a sensitivity of 99,81%, with a positive predictivity of 98,64%. Related to the wavelet application, five different wavelet bases were used. Best results provided a sensitivity of 99,08%, with a positive predictivity of 98,28%. 1 Introduction Over the last decades, the close relationship between Medicine and Computer Science has strongly affected the daily clinical practice in hospitals and health centers. Moreover, the diagnosis of different pathologies is being affected by the technological development in many fields [1], [2]. One of the research medical areas that benefits from using computers for detecting abnormalities is the field of physiological signals analysis. In fact, dif- ferent pathologies affecting respiratory, brain and cardiovascular functions can be detected by analyzing the patients’s physiological activity, such as electroen- cephalogram (EEG) [3], electroculograms (EOG) [4], or oxygen saturation signal [5]. In a general way, the use of computers in Medicine is related to the develop- ment of computerized methods for the automated detection of several diseases, including respiratory fails, cardiovascular problems, cancer detection or even in- fections. In this field, one of the most useful tools employed by the clinicians to obtain these physiological signals and to analyze the cardiac function are electrocardiograms (ECG) [6]. An ECG is the representation of the electrical activity of the heart muscles, and the variations produced in time. The cardiac muscles contract in response of depolarization, and the result of this electrical activity is known as an ECG [7]. The heart has two electrical stages, and the corresponding activity can be

Upload: phamnhi

Post on 01-May-2018

224 views

Category:

Documents


3 download

TRANSCRIPT

A Free Software Tool for Automatic Analysis ofECG

Christian Iglesias Zazueta, Xose A. Vila, Marıa J. Lado

Escola Superior de Enxenerıa Informatica - Universidade de Vigohttp://www.milegroup.net

Abstract. The proposal of this work was to develop an automatic al-gorithm for QRS complex (beat) detection in electrocardiograms (ECG)using free software. The recognition of the QRS complex was imple-mented using both wavelets and the Pan-Tompkins algorithm. Initially,the algorithm read a header file where all the information was stored.With the information obtained, a binary file containing the ECG datawas retrieved and processed. In this way, beats were detected by auto-matically thresholding the signal. Several data files from the PhysioBankdatabase were used to test the algorithms. The Pan-Tompkins algorithmreached a sensitivity of 99,81%, with a positive predictivity of 98,64%.Related to the wavelet application, five different wavelet bases were used.Best results provided a sensitivity of 99,08%, with a positive predictivityof 98,28%.

1 Introduction

Over the last decades, the close relationship between Medicine and ComputerScience has strongly affected the daily clinical practice in hospitals and healthcenters. Moreover, the diagnosis of different pathologies is being affected by thetechnological development in many fields [1], [2].

One of the research medical areas that benefits from using computers fordetecting abnormalities is the field of physiological signals analysis. In fact, dif-ferent pathologies affecting respiratory, brain and cardiovascular functions canbe detected by analyzing the patients’s physiological activity, such as electroen-cephalogram (EEG) [3], electroculograms (EOG) [4], or oxygen saturation signal[5].

In a general way, the use of computers in Medicine is related to the develop-ment of computerized methods for the automated detection of several diseases,including respiratory fails, cardiovascular problems, cancer detection or even in-fections. In this field, one of the most useful tools employed by the cliniciansto obtain these physiological signals and to analyze the cardiac function areelectrocardiograms (ECG) [6].

An ECG is the representation of the electrical activity of the heart muscles,and the variations produced in time. The cardiac muscles contract in responseof depolarization, and the result of this electrical activity is known as an ECG[7]. The heart has two electrical stages, and the corresponding activity can be

2

measured by placing electrodes on the skin. In fact, to produce twelve electricalviews of the heart, ten electrodes are needed. However, for heart monitoring,only three electrodes are required [8]. Digitalization of the ECG produces aninexact signal, and it becomes important to adjust some parameters in order toobtain a fitted diagnosis by the specialist. One of the variables to be fitted in theanalysis is the sample frequency, which defines the number of samples per unitof time that should be taken from the continuous signal to obtain an acceptabledigital signal and which usually varies from 200 to 500 samples per second [9].ECG is important because it can provide information about heart damages, beatfrequency, abnormality of heart beats, position of chambers and enlargement ofthe heart [10].

Furthermore, from the analysis of an ECG, clinicians can detect arrhythmias,cardiac muscle defects, congenital heart defect, coronary artery disease, ectopicheartbeat, heart enlargement, cardiac inflammation, chemicals in the blood, pastheart attack, present or impending heart attack, or abnormal heart rate [10]. Asit has been previously stated, the ECG analysis can reflect the physical conditionof human heart. In this way, an accurate detection of the ECG wave should beimportant to diagnose cardiac diseases. A good performance of an automateddiagnosis scheme strongly depends on an accurate and reliable detection of theQRS complex, and both the T and P waves [11]. Related to the QRS complex,it is one of the components included on the ECG. It traces a complete cardiaccycle, occurring after the P wave (atrial depolarization) and before the T wave(ventricular repolarization). A QRS complex should not exceed 100 ms. A pro-longed duration of a QRS complex signifies a conduction delay of the ventricles.The first wave of the complex is named Q wave, and it has negative values. Theslope of the R wave is a popular signal feature used to locate the QRS complex,thats why is the most import wave in our work [12]. It is not necessary that allQRS complexes have the three waves (Q, R and S) [13].

When developing a computerized method to assist specialists in the diagno-sis of cardiac lesions, in particular, in the detection of the QRS complex, databecoming from the ECG must be digitally stored on a file, and retrieved forlater analysis. It is clear that different data formats can be employed, such asASCII file, where the data are stored in a single-column format; WFDB format,typical of the WFDB (WaveForm Database) Library, which can be easily down-loaded and installed from the PhysioNet website (http://www.physionet.org)1;or EDF+ (European Data Format) (http://www.edfplus.info).

In this research work, an automated system for detecting QRS complex inECGs, starting from binary files, to help clinicians in the diagnosis of cardiacdiseases has been developed. The paper is organized as follows: Section 1 givesa general introduction; Section 2 presents the methodological framework andthe state of the art; Section 3 includes the original contribution to scientific

1 PhysioNet is a scientific community for biomedical investigation, which providesa large number physiologic signals and open source software for analyzing them,converting formats, visualization, data mining, processing and evaluation, amongothers.

3

advancement, the databases employed in the study, as well as the algorithmsimplemented; Section 4 presents and discusses the results obtained; and Section5 describes the main conclusions of this work.

2 Methodological Framework and State of the Art

The detection of the QRS complex in an ECG is a difficult task, because ithas a time-varying morphology and is influenced by noise and variations in thepatient, this leading to physiological variations that strongly affect the ECGvalues. Bearing this in mind, a QRS complex detector should be invariant todifferent noise sources, and should be capable to perform an adequate detectioneven when the morphology of the ECG is varying in time [14].

Software QRS detection has been a research topic for more than 30 years.There are different methods to detect the QRS complex, such as patient moni-tors, stress test systems, Holter analysis systems, neural networks, genetic algo-rithms, wavelet transforms, filter banks, or heuristic methods based on nonlineartransforms [12], [15]-[16].

QRS detection in ECG signals has been the focus of a wide body of researchfor the last few decades. Many of the developed methods are based on the use ofdigital filters, wavelet transforms and neural networks. We will review now someof the algorithms for detecting the QRS complex.

2.1 Bank of Digital Filters

To be able to detect the QRS complex employing derivatives and filters, thealgorithms should adjust to the typical frequency range of the QRS, with rangesfrom 10 to 25 Hz. Prior to the detection, a filter stage is implemented to attenuatesignal components such as P-wave, T-wave, baseline drifts and coupling noise.Algorithms use a combination of a low-pass filter and a high-pass filter to makea bandpass filter with cut-off frequencies between the typical range of the QRSsignal (10-25 Hz) [12].

When using derivative algorithms,the highpass filter is replaced with a dif-ferentiator. In order to detect the QRS complex, the result of the differentiatoris compared with a threshold value, which is usually adapted depending on thecharacteristics of the changing signal. The peak detection logic is completed bydecisions rules to reduce the detection of false positives.

The ECG signal is filtered in parallel with two different lowpass filters withdistinct cut-off frequencies. Some algorithms implement the bandpass filter witha lowpass filter and a highpass filter [12]. The ECG is first bandpass filtered andthen differentiated. The filters use coefficients that are experimentally adjustedduring the implementation. To control the peak, a variable storages the mostrecent maximum and then the signal is compared wit this variable, if the featuredrops below the 50% of the variable, a peak is detected and the variable updatesto this new value. A fiducial mark is set to the location of the largest peak in theband-pass filtered signal [12]. Then, a decision stage is applied with a peak level

4

Lp and a noise level LN . The signal is divided into 15 points, and the maximumof each segment is compared with the peak level and the noise level.

2.2 Wavelet-Based QRS Detection

The starting point of the wavelet-based QRS detection is an integral transformdefined by:

Wψf(a, b) =

∫ ∞−∞

f(t)ψab(t)dt. (1)

This transform uses a set of functions that analyzes a variable time andfrequency resolution for different frequency bands[ 16]. The method consists indecomposing signals into elementary blocks well localized in time and frequency,and the local regularity of signals can be characterized. The local maxima ofthe wavelet transform at different scales is used to locate sharp variations of theECG signals and with this detect each R-peaks in each cardiac beat [15].

2.3 Neural Networks

Neural networks are another way to analyze ECG signals [16]. The signal isfiltered with two different bandpass filters, and then the outputs are multiplied.This multiplication performs the AND operation; if both outputs of the signalare high, then the result is high and indicates the QRS complex. The goal ofthis method is to try to predict the current signal value from its past values. AsECG signals consists almost of non-QRS segments, neural networks converge toa point where this samples are well predicted and when this segments changesit detects the QRS complex.

2.4 Importance

The common factor for all the algorithms aimed at helping clinicians in the ECGanalysis is the fact that the majority of them have been implemented by partic-ular investigation groups, which are forced to develop their own and proprietarysoftware, due to the lack of a common software package, easily accessible anddownloadable, that fulfill the particular requirements of each research associa-tion. It must also be noticed that there also exist commercial systems for ECGanalysis, but they are usually designed for clinical uses and do not have theprogrammability needed by researchers in signal processing, looking for new andyet unforeseen discriminators or algorithms. Because of this, investigators mustdevelop specific applications to efficiently reach their particular goals.

To perform this task, many programming languages are employed, such asMatlab [17], C language [18], Java [19], or even LabView [20].

One of the most extended programming environments in the last years forresearch programming tasks in the R language [21], [22], an open-source softwareenvironment for statistical computing and graphics, that is presently used by a

5

growing number of researchers. The R language is an implementation of the Slanguage, which was inspired by dialects of Lisp. It can be considered both acomputing environment and programming language, and it compiles and runson a wide variety of UNIX, Windows and MacOSX platforms. The main charac-teristics of the R language are a wide number of functions specifically developedfor statistical calculations; high extensibility via third party packages suppliedwith the R distribution, and many more are available through the CRAN familyof Internet sites; existence of user defined data types, a suite of mathematicaloperators for vectors and matrices, and an integrated collection of data analysistools; and facilities for highly customized plots.

An increasing number of biomedical applications implemented with R lan-guage can be found in the literature, including generation of correlated discreteordinal data arising from longitudinal studies of medical research [23], detec-tion of breasts cancer [24], population pharmacokinetic modeling for analyzingdrugs effects and individual variations [25], heart rate variability analysis [26],or time-series analysis [27].

Due to the growing scientific community employing the R programming lan-guage, and attending to the requirements of researchers, that usually need tounify software functionality into one open source and easily extendible tool, wehave decided to employ R for developing a software program to automaticallydetect the QRS complex, in an attempt to help clinicians in the analysis of ECGrecordings. Details of the implementation are now given in the next Section.

3 Original Contribution

In this Section, we present the algorithms implemented to detect the QRS com-plex in ECG recordings. Previously the database used for validation is described.Finally, the validation method and results are explained.

3.1 Database

The database used in this paper consists on 10 ECG recordings, which wererandomly selected from the MIT-BIH Arrhythmia Database, which has been ex-tensively described elsewhere [28], and can be easily downloaded from the Phys-ioBank archives (http://www.physionet.org/physiobank/database/mitdb/).

Briefly, the MIT-BIH Arrhythmia Database contains 48 half-hour excerptsof two-channel ambulatory ECG recordings, digitized at 360 samples per secondper channel with 11-bit resolution over a 10 mV range.

Each recording was independently annotated by two or more cardiologists;disagreements were resolved to obtain the computer-readable reference anno-tations for each beat, included with the database. It must be indicated thatannotations are files that contain real beat positions, apnea episodes, or otherrelevant information about the patient. Furthermore, to complete each ECGrecord, a header text file containing information about the sample frequency,signal size, patients medication, and number of channels was generated for each

6

ECG. The 10 randomly selected ECG were those labeled as 100, 101, 103, 105,109, 119, 124, 200, 215, 220. For each of them, three files were downloaded: .dat,containing the ECG data, .atr, containing the real, true beat (QRS complex)annotations, and .hea, containing other interest annotation.

3.2 Algorithm Description

Previous to the detection of the QRS complex, the ECG file had to be importedby the computer program. Our program acquired the ECG in binary file, thatshould be in 16-bit format, to be correctly read. Two different algorithms forreading the data files were developed in both R and C language. Even althoughthe program was initially written in R language, a problem arose, since ECGrecordings are very large files, and the reading time grew with the file size. Tosolve this problem, a C algorithm to read the ECG data was also implemented,saving computation time, and making the algorithm much more efficient. Inthis way, the user could select either the C or the R routine. Moreover, sincethe application of the previous cascade algorithm required to work with dyadicsignals, the ECG recordings were restricted to be a power of two, and in order tocompare the results, these recordings were used as input data for both developedalgorithms.

The implementation of the QRS complex detector algorithm was then per-formed employing two different techniques. Firstly, the Pan-Tompkins algorithmwas implemented. Secondly, a wavelet-based method was developed.

3.3 Pan-Tompkins Algorithm

The Pan and Tompkins algorithm is based on analysis of the slope, amplitudeand width of the QRS complex [12]. The most important section of the QRSin this work is the R wave. The slope of this wave is used to detect the QRScomplex (Figure 1).

Fig. 1. QRS complex.

The method consists first on passing the signal throughout a block of filters.The block of filters consists on a band-pass filter, low-pass filter, high-pass filter,

7

derivate function, squaring function and a moving-window integration (Figure2).

Fig. 2. Block process of Pan and Tompkins algorithm.

3.3.1 Bandpass Filter: First, the signal is passed through a bandpass filter toreduce the influence of muscle noise, baseline wander and T-wave interference.This passband filter was constructed using both low-pass filter and a high-passfilter in cascade, to achieve the 3 dB bandpass of 5-12 Hz.

3.3.2 Lowpass Filter: On this step, we have used a second order lowpass filterto generate the cut-off frequency of 11 Hz. The transfer function is:

H(z) =(1− z−6)2

(1− z−1)2(2)

The difference equation is given by:

y(nT ) = 2y(nT − T )− y(nT − 2T ) + x(nT )− 2x(nT − 6T ) + x(nT − 12T ) (3)

This low-pass filter generates a 6 sample delay (25 ms) for this sample rate.

3.3.3 Highpass Filter To produce the bandpass filter, we subtracted the out-put of the lowpass filter, and filtered it again using a highpass filter. The lowcut-off of this filter is 5 Hz.

The transfer function is expressed as follows:

Hlp(z) =Y (z)

X(z)=

(1− z−32)

(1− z−1)(4)

The difference equation is:

y(nT ) = y(nT − T ) + x(nT )− x(nT − 32T ) (5)

8

with this, the high-pass filter is obtained by dividing the output of the low-pass filter by its gain and subtracting from the original signal.

Hhp(z) =P (z)

X(z)= z−16 − Hlp(z)

32(6)

The difference equation is:

y(nT ) = x(nT − 16T )− 1

32[y(nT − T ) + x(nT )− x(nT − 32T )] (7)

Thhis high-pass filter generates a 16 sample delay (18 ms).

3.3.4 Derivation: After the bandpass filter was applied, the signal was differ-entiated to provide the QRS slope information.

The transfer function is:

H(z) = (1/8T )(−z−2 − 2z−2 + 2z−1 + z−2) (8)

The difference equation is:

y(nT ) = (1/8T )[−x(nT − 2T )− 2x(nT − T ) + 2x(nT + T ) + x(nT + 2T )] (9)

This derivate has a filter delay of 2 samples (10ms).

3.3.5 Squaring: The squaring function makes all data points to be positiveand to make nonlinear amplification of the output of the derivate, emphasizingthe higher frequencies. It can be written as:

y(nT ) = [x(nT )]2 (10)

3.3.6 Moving-Window Integration: Once the signal was positive and thehigher frequencies were emphasized, a moving-window integration was applied tothe signal. This integration was applied to obtain waveform feature information.It can be expressed as:

y(nT ) = (1/N)[x(nT − (N − 1)T ) + x(nT − (N − 2)T ) + ...+ x(nT )] (11)

where N is the number of samples in the width of the integration window. Theefficiency of the QRS complex detector depends on the correct implementation ofthis function. If N is too large, the waves could be mixed, and if it is too narrow,the information of the R wave would be lost. For example, Pan and Tompkinsused a sample rate of 200 samples/s with a window of 30 samples wide (150 ms)[12]. Starting from this point, we have made this window to be automaticallycalculated, even although the user can vary this window manually.

9

3.3.7 Threshold and Beat Detection: We have stored in a variable themean and the maximum value of the output of the Moving-Window integration.With this information, we have performed a threshold comparison. If the signalwas greater than the product of the maximum value and the mean then it wasconsidered to be a QRS complex, and the position stored. Then, the beginningof the slope of this signal was considered as a location position. Finally, wegenerated a text file with the positions, that was used to compare our resultswith the annotation file .atr, downloaded from PhysioNet.

3.4 Wavelet-Based Algorithm

Wavelet transform (WT) is an ideal tool to analyze signals containing differentstructures [29]. It decomposes signals into different scale components and pro-vides a method for space-frequency localization, and it is better able to focuson very high frequency signals, such as a QRS complex, than the short Fouriertransform or the local cosine basis, for example. It must also be considered thatthe wavelet coefficients produced in a wavelet analysis provide explicit informa-tion on the location and type of signal singularities, and the QRS complex can beconsidered as a singularity of the ECG, since it corresponds to sharp changes inthe signal and can be detected using wavelet functions. Our efforts were concen-trated on a computerized detection scheme that automatically detects the QRScomplex. A detailed explanation about the WT can be found in [30]. Briefly, theanalysis is performed using a single prototype function ψ(t). The wavelet basisfunctions derive from arbitrary dilation and translation of this function, and areusually written as:

ψu,s(t) = s−1/2ψ(t− us

) (12)

where s > 0 is a dilation factor and u is a real number representing thetranslations. The function ψ(t) is called the mother wavelet, and can be thoughtof as a bandpass filter, is a well-localized and oscillating, having zero average:∫ +∞

−∞ψ(t)dt = 0 (13)

The analysis of a function f(t) employing wavelets produces the wavelet coef-ficients, and consists in the extraction of the information of the signal, with thewavelet coefficients. The synthesis allows retrieving the function using the samecoefficients.

In many occasions, the values of the parameters u, s can be restricted to adiscrete sublattice. In this case, the dilation parameters a0 > 1, and the trans-lation step b0 > 0 are fixed, and the family of wavelets constructed in this waybecomes:

ψm,n(t) = a−m/20 ψ(a−m0 t− nb0) (14)

10

where m, n are real numbers. It must also be noticed that usually the WTprovides a redundant description of the original function. However, for specificelections of the s and u parameters, an orthonormal wavelet basis of L2(IR) canbe obtained. In these cases, the multiresolution analysis is provided.

In practical situations, the multiresolution analysis must be applied over dis-crete signals, with finite length. In these cases, a fast algorithm that cascadesdiscrete convolutions with two filters h (lowpass filter), g (highpass filter), andsubsamples the output can be applied. A filter bank analysis is performed. Fol-lowing this idea, f(t) can be decomposed into two functions f1(t), which is ablurred, smoothed version of the original signal, and d1(t), containing the de-tails of f(t). In this way, the original signal can be expressed as:

f(t) = f1(t) + d1(t) =∑n

d[n]ψ(t− n) +∑n

a[n]∅(t− n) (15)

where d[n] corresponds to the detail coefficients, and a[n] represents the coef-ficients at a coarser resolution. The process can be repeated in f1(t), and, thus,one can represent f(t) as a sequence of coefficients a[n], d[n], given by:

aj+1[p] =

+Ψ∑n=−Ψ

h[n− 2p]aj [n] (16)

dj+1[p] =

+Ψ∑n=−Ψ

g[n− 2p]aj [n] (17)

Figure 3 represent the wavelet decomposition and reconstruction of a signalaj . First, the signal is decomposed and subsampled by a factor of 2, by applyingfilters h and g, and the wavelet and smoothed coefficients (dj+1 and aj+1, respec-tively), are obtained. The processes can be repeated over the aj+1 coefficients,this producing dj+2 and aj+2 coefficients. The process can be repeated, subsam-pling by 2 in each new performed transformation. To reconstruct the signal, thefilters are now applied by reversing the decomposition procedure.

Fig. 3. Wavelet decomposition and reconstruction of a signal.

11

The previous scheme was considered for developing the wavelet algorithmto detect the QRS complex. The code was implemented employing the basicroutines of the waveslim software package, an R package that can be easilyinstalled and downloaded from the R CRAN. These wavelet routines work overdyadic length signals (power of 2), and allow for decomposing signals employingdifferent wavelet bases.

The algorithm developed is a 3-step process involving:

3.4.1 Wavelet Application: The wavelet decomposition was applied up tothree levels. In particular, several bases were tried: Haar wavelet, Least Asym-metric Daubechies (LAD) with 8 coefficients, and Daubechies (DAUB) waveletbases with 4, 6 and 8 coefficients [29]. Given the size of the original signal, toefficiently apply the WT in terms of computation time, a moving window of2.8 seconds was situated at the beginning of the signal, and the correspondingWT was calculated. The window was then moved 1.4 seconds, and the processwas repeated. In this way, a WT was obtained for every 2.8 seconds interval.To achieve the WT for the complete ECG signal, only the central portion of 50percent of each interval was considered, avoiding, in this way, the overlappingof data that were analyzed in two consecutive intervals. In this way, a uniquevalue for all the wavelet coefficients was obtained for each decomposition level(Figure 4). As it can be observed, the wavelet coefficients reach the higher val-ues in the three decomposition levels in the positions corresponding to the QRScomplexes in the original signal. This was the starting point of the next step ofthe algorithm.

3.4.2 Maxima Calculation: When the wavelet coefficients were calculated upto level three, the local absolute maxima of the WT along the three waveletscales were obtained. To perform this task, an empirically determined thresholdvalue was applied, and absolute values of the wavelet coefficients that exceed thegiven threshold were considered. The study determined that the selection of 60percent of the absolute maximum value in each windowed segment, and for eachdecomposition level, provided the best results.

3.4.3 Beat Detection: The QRS complexes were extracted from the maximavalues calculated in the former stage. If a maximum value appeared in any ofthe scales, with a misalignment of less than 0.1 seconds across two consecutivescales, the maximum was considered to be a QRS complex. A vector giving allthe detected beats was obtained, that it, the corresponding beat annotationswere obtained.

3.5 Validation Method

To compare the results provided by the algorithms, and to verify if differenceswere achieved by both of them when detecting the QRS complex, a validation was

12

Fig. 4. Original ECG portion and wavelet decomposition up to the third level.

performed employing the bxb routine, a basic functionality of the WFDB librarythat allows for comparing beat-by-beat annotations. This routine implements thebeat-by-beat comparison algorithms described in [31]. Briefly, the performanceanalysis metric of any QRS detection method is expressed in terms of the thesensitivity and positive predictivity, given by:

Sensitivity(Se) =TP

TP + FN(18)

PositivePredictivity(P+) =TP

TP + FP(19)

where TP is the number of true detection of the QRS complex, FN is thenumber of undetected beats, and FP is the number of false detections. Thestatistics employed in bxb are based on tallies of matching annotations in thereference (real) and test (result) annotation files. It is not needed that matchingannotations have exactly equal annotation times. This difference is assumedto begin 150 ms after the previous annotation, and to end 150 ms before thefollowing annotation, even although it can be modified by the user.

13

4 Results and Discussion

In this work, two different algorithms for detecting beats in ECG recordings wereimplemented. Figures 5 and 6 show an example of the QRS complex detection inthe same ECG portion, employing both the Pan and Tompkins and the waveletalgorithm. We have previously mentioned that an .atr file containing the real beatpositions was downloaded from PhysioNet for each ECG recording. To compareour results with the true QRS annotations, the bxb function was applied, andsensitivities and positive predictivity were calculated. The mean error for theRR interval, defined as distance between two consecutive R peaks, as well as thethe number of real beats, average values of sensitivity and positive predictivitywere calculated (Tables I-VI).

Fig. 5. Example of the QRS complex detection in a portion of an ECG recording,employing the Pan and Tompkins algorithm.

14

Fig. 6. Example of the QRS complex detection in a portion of an ECG recording,employing the wavelet algorithm.

Table 1. RR interval error, sensitivity (Se) and positive predictivity (P+) in % ob-tained for the detection of the QRS complex, for the Pan and Tompkins algorithm.The number of real beats is also provided, as well as the number of detected beats andthe RMS RR interval error.

ECG RECORDING Real Beats Detected Beats Se ( %) P+ (%) RMS RR interv. err (ms)

100 1459 1458 99,93 100,00 2,61101 1174 1174 99,83 100,00 6,19103 1336 1335 99,93 100,00 26,09105 1645 1624 98,72 92,12 149,50109 1615 1612 99,81 99,94 40,24119 1278 1278 100,00 100,00 10,39124 1038 1028 100,00 100,00 7,59200 1694 1693 99,94 94,32 142,33215 2150 2150 100,00 100,00 8,69220 1292 1292 99,92 100,00 2,02

Average 1468,10 1464,40 99,81 98,64 39,56

15

Table 2. RR interval error, sensitivity (Se) and positive predictivity (P+) in % ob-tained for the detection of the QRS complex, for the Haar wavelets. The number ofreal beats is also provided, as well as the number of detected beats and the RMS RRinterval error.

ECG RECORDING Real Beats Detected Beats Se ( %) P+ (%) RMS RR interv. err (ms)

100 1459 1459 100,00 99,86 23,13101 1174 1174 100,00 99,83 25,14103 1336 1336 100,00 100,00 8,97105 1645 1627 98,91 97,84 108,30109 1615 1613 99,88 99,32 59,29119 1278 1278 100,00 88,08 422,51124 1038 1028 100,00 99,81 66,84200 1694 1625 95,93 98,19 214,55215 2150 2096 97,49 100,00 124,25220 1292 1275 98,61 99,92 109,93

Average 1468,10 1451,10 99,08 98,28 116,28

Table 3. RR interval error, sensitivity (Se) and positive predictivity (P+) in % ob-tained for the detection of the QRS complex, for the LAD8 wavelets. The number ofreal beats is also provided, as well as the number of detected beats and the RMS RRinterval error.

ECG RECORDING Real Beats Detected Beats Se ( %) P+ (%) RMS RR interv. err (ms)

100 1459 1451 99,45 96,60 145,63101 1174 1172 99,83 93,46 197,46103 1336 1332 99,70 94,94 177,12105 1645 1616 98,24 70,14 320,22109 1615 1609 99,63 52,60 401,07119 1278 1213 94,91 75,95 489,29124 1038 1023 99,51 41,60 711,23200 1694 1595 94,16 72,73 337,16215 2150 2049 95,30 90,78 204,06220 1292 1277 98,76 99,84 113,84

Average 1468,10 1433,70 97,949 78,864 309,72

16

Table 4. RR interval error, sensitivity (Se) and positive predictivity (P+) in % ob-tained for the detection of the QRS complex, for the DAUB4 wavelets. The number ofreal beats is also provided, as well as the number of detected beats and the RMS RRinterval error.

ECG RECORDING Real Beats Detected Beats Se ( %) P+ (%) RMS RR interv. err (ms)

100 1459 1459 100,00 99,93 9,36101 1174 1173 99,91 99,41 55,07103 1336 1336 100,00 100,00 11,49105 1645 1626 98,84 94,21 151,79109 1615 1613 99,88 95,95 121,64119 1278 1235 96,64 97,86 310,43124 1038 1028 100,00 98,47 134,22200 1694 1633 96,40 89,19 249,03215 2150 2094 97,40 99,86 128,09220 1292 1279 98,92 100,00 89,95

Average 1468,10 1447,60 98,799 97,488 126,14

Table 5. RR interval error, sensitivity (Se) and positive predictivity (P+) in % ob-tained for the detection of the QRS complex, for the DAUB6 wavelets. The number ofreal beats is also provided, as well as the number of detected beats and the RMS RRinterval error.

ECG RECORDING Real Beats Detected Beats Se ( %) P+ (%) RMS RR interv. err (ms)

100 1459 1457 99,86 99,86 49,02101 1174 1173 99,91 98,49 92,80103 1336 1334 99,85 99,70 59,04105 1645 1623 98,66 77,88 280,37109 1615 1612 99,81 63,87 353,18119 1278 1219 95,38 95,38 366,95124 1038 1025 99,71 66,95 532,44200 1694 1503 94,63 84,01 291,57215 2150 2088 97,12 97,52 146,39220 1292 1276 98,69 100,00 102,69

Average 1468,10 1431,00 98,36 88,37 227,44

17

Table 6. RR interval error, sensitivity (Se) and positive predictivity (P+) in % ob-tained for the detection of the QRS complex, for the DAUB8 wavelets. The number ofreal beats is also provided, as well as the number of detected beats and the RMS RRinterval error.

ECG RECORDING Real Beats Detected Beats Se ( %) P+ (%) RMS RR interv. err (ms)

100 1459 1447 99,18 95,39 176,12101 1174 1174 100,00 92,81 211,05103 1336 1330 99,55 95,20 175,90105 1645 1610 97,87 69,10 326,69109 1615 1608 99,57 56,44 374,66119 1278 1236 96,71 77,93 483,37124 1038 1026 99,81 44,13 685,52200 1694 1579 93,21 74,27 333,32215 2150 2100 97,67 91,15 167,79220 1292 1276 98,69 99,69 109,07

Average 1468,10 1438,60 98,226 79,611 304,36

Table 1 to 6 summaries the performance of the algorithms. Table 1 producedand average of 99,81% of sensivity for a 39,56 ms of RMS interval error. Eventhough this algorithm produces a more efficient average we can see that sen-sibility of Haar wavelets in table 2 on some records like 100,101 and 102 wasbetter.

5 Conclusions and Future Works

In this research work, two algorithms for detecting the QRS complex in ECGrecordings were developed. Results indicate that the best method to detect beatsis Pan and Tompkins method with an average sensitivity of 99.81% , beingthe corresponding positive predictivity of 98.64%. The algorithm of Pan andTompkins presents a good average of beats detected comparing with this samealgorithm implemented by Pan and Tompkins with assembly language (99.3%correctly beats detected) [12].

Pan and Tompkins algorithm resulted on a good average of real detectedbeats, as well as the wavelet-based methods developed here. The Haar waveletsprovided the best results, with a 99,08% of sensitivity. By contrary, worst resultswith wavelets were achieved when using the LAD8 basis. Other wavelet workslike [15],[32] produced over 99,8% of sensitive.

In future an improvement of the algorithm will be implemented to detect99.9% of correct beats. Algorithm will address the issue of automatically con-trolling the reading of the signal. The algorithm should be able to read anyformat for the ECG signal. Moreover, the algorithm should be implemented tocontrol an ECG signal of multiple channels, and not only one, as it occurs in thepresent work. Furthermore, the WT algorithms should be developed for accept-

18

ing any size of signal, avoiding, in this way, the present limitation of workingwith dyadic recordings.

References

[1] Mietus, J. E., Peng, C. K., Ivanov, P. C., and Goldberger, A. L. (2000). De-tection of obstructive sleep apnea from cardiac interbeat interval time series.In Computers in Cardiology 2000, 753-756.

[2] Doi, K. (2007). Computer-aided diagnosis in medical imaging: Historical re-view, current status and future potential. Computerized Medical ImagingGraph, 31:98-211.

[3] Halford, J. J. (2009). Computerized epileptiform transient detection in thescalp electroencephalogram: Obstacles to progress and the example of comput-erized ECG interpretation. Clin Neurophysiol, 120:1909-1915.

[4] Boulos, M. I., Umapathy, K., Shokrollahi, P., McConville, K. M., Sudenis, T.,Jewell, D. R., Krishnan, S., and Murray, B. J. (2011). Automated detectionof nocturnal slow eye movements modulated by selective serotonin reuptakeinhibitors. Progr Neuro Psychopharmacol Biol Psychiatr, 35:126-130.

[5] Lee, Y. K., Bister, M., Blanchfield, P., and Salleh, I. M. (2004). Automateddetection of obstructive apnea and hypoponea events from oxygen saturationsignal. Conf Proc IEEE Eng Med Biol Soc, 1:321-324.

[6] Roche, F., Pichot, V., Sforza, E., Court-Fortune, I., Duverney, D., Costes, F.,Garet, M., and Barthelemy, J. C. (2003). Predicting sleep apnoea syndromefrom heart period: a time-frequency wavelet analysis. Eur Respir J, 22:937-942.

[7] Armstrong, M. (1985). Electrocardiograms. Bristol, U.K., Wright.

[8] Ueno, A.; Akabane, Y.; Kato, T.; Hoshino, H.; Kataoka, S.; and Ishiyama, Y.(2007). Capacitive Sensing of Electrocardiographic Potential Through ClothFrom the Dorsal Surface of the Body in a Supine Position: A PreliminaryStudy. IEEE Trans Biomed Engineering, 54:759-766.

[9] Jalaleddine, S.M.S.; Hutchens, C.G.; Strattan, R.D.; and Coberly, W.A. (1990).ECG data compression techniques - A unified approach. IEEE Trans BiomedEngineering, 37: 329-343.

[10] Hombach, V. (2006). Electrocardiography of the Failing Heart. CardiologyClinics 24: 413-426.

[11] Zhang, F., and Liang, Y. (2011). QRS detection based on morphological fil-ter and energy envelope for applications in body sensor networks. J SignalProcessing Systems, 64:187-194.

[12] Pan J., and Tompkins, W.J. (1985). Real-time QRS detection Algorithm. IEEETrans Biomed Engineering, 32:230-235.

[13] Medical-Elearning: The QRS complex: http://qrscomplex.net/. Last accessedMay 21st, 2012.

[14] Friesen, G.M., Jannett, T.C., Jadallah, M.A., Yates, S.L., Quint, S.R., andNagle, H.R. (1990). A comparison of the noise sensitivity of nine QRS detectionalgorithms. IEEE Trans Biomed Engineering, 37:85-98.

[15] Li, C., Zheng, C., and Tai, C. (1995). Detection of ECG characteristic pointsusing wavelet transforms. IEEE Trans Biomed Engineering, 42:21-28.

[16] Dokur, Z., Olmez, T., Yazgan, E., and Ersoy, O.K.. (1997). Detection of ECGwaveforms by neural networks. Med Eng Phys, 19:738-741.

19

[17] Narayana, K.V.L., and Rao, A. B. (2011). Wavelet based QRS detection inECG using MATLAB. Innovative Systems Design and Engineering, 2:60-69.

[18] Hamilton, P., (2002). Open Source ECG Analysis. Computers in Cardiology2002, 29:101-104.

[19] Iliopoulos, C.S., and Michalakopoulos, S. (2010). Combinatorial ECG Analy-sis for Mobile Devices. Proceedings of the 11th ACM SIGMM InternationalConference on Multimedia Information Retrieval, 409-412.

[20] National Instruments. Using LabVIEW for heart rate variability analysis. Pub-lished online at http://zone.ni.com/devzone/cda/epd/p/id/5832 on Apr 24,2009. Last accessed May 21st, 2012.

[21] http://www.r-project.org/. Last accessed May 21st, 2012.[22] http://cran.r-project.org/. Last accessed May 21st, 2012.[23] Ibrahim, N.A., and Suliadi, S. (2011). Generating correlated discrete ordinal

data using R and SAS IML. Comput Methods Programs Biomed, 104:122e-132e.

[24] Roca-Pardinas, J., Lado, M.J., Tahoces, P.G., and Cadarso-Suarez, C. (2012)Reducing false positives in a CAD scheme for detecting breast microcalci-ficacions: a cuantitative study with GAMs, Cancer Prevention, (AlexandrosGeorgakilas, Ed), 459-476.

[25] Sun, X., Wu, K., and Cook, D. (2011). PKgraph: An R package for graphicallydiagnosing population pharmacokinetic models. Comput. Methods ProgramsBiomed, 104:461-471.

[26] Rodrıguez-Linares, L., Mendez, A.J., Lado, M.J., Olivieri, D.N., Vila, X.A.,and Gomez-Conde, I. (2011). An Open Source Tool for Heart Rate VariabilitySpectral Analysis. Comput Methods Programs Biomed, 103:39-50.

[27] Kosorus, H.; Honigl, J.; and Kung, J. (2011). Using R, WEKA and RapidMinerin Time Series Analysis of Sensor Data for Structural Health Monitoring. Pro-ceedings of DEXA 2011, 306-310.

[28] Moody, G.B., Mark, R.G. (2001). The impact of the MIT-BIH ArrhythmiaDatabase. IEEE Eng Med Biol, 20:45-50.

[29] Daubechies, I., (1992). Ten Lectures on Wavelets SIAM, Philadelphia, PA.[30] Mallat, S., (2008). A wavelet tour of signal processing: The sparse way. 3rd

Edition, Academic Press, New York.[31] ANSI/AAMI EC38:1998, the American National Standard for Ambulatory

ECGs.[32] Banerjee S., Gupta R, Miltra M. (2011). Department of Applied Physics, Uni-

versity of Calcuta: Delineation of ECG characteristic features using multi res-olution wavelet analysis method. 475-487.