Fast QRS Detection with an Optimized Knowledge-Based Method: Evaluation on 11 Standard ECG Databases

The current state-of-the-art in automatic QRS detection methods show high robustness and almost negligible error rates. In return, the methods are usually based on machine-learning approaches that require sufficient computational resources. However, simple-fast methods can also achieve high detection rates. There is a need to develop numerically efficient algorithms to accommodate the new trend towards battery-driven ECG devices and to analyze long-term recorded signals in a time-efficient manner. A typical QRS detection method has been reduced to a basic approach consisting of two moving averages that are calibrated by a knowledge base using only two parameters. In contrast to high-accuracy methods, the proposed method can be easily implemented in a digital filter design.


Introduction
According to the World Health Organization, cardiovascular diseases are the number one cause of death worldwide [1]. An estimated 17.3 million people died from cardiovascular diseases in 2008, representing 30% of all global deaths [1]. Thus, recently, medical researchers have placed significant importance on cardiac health research. This has produced a strong focus on preventative, medicinal, and technological advances. One such research pathway is leading researchers toward improving the conventional cardiovascular-diagnosis technologies used in hospitals, clinics and the home.
The most common clinical cardiac test is electrocardiogram (ECG) analysis. It represents a useful screening tool for various cardiac abnormalities because it is simple, risk-free, and inexpensive [2]. Therefore, the analysis of ECG signals has been extensively investigated over the past two decades. Many attempts have been made to find a satisfying universal solution for QRS complex detection, including the Pan and Tompkins algorithm [3], which has been used extensively in the literature for beat detection. The current advances in battery-driven devices such as smartphones and tablet computers have made these technologies invariably part of daily life, even in developing countries [4]. The advances have also increased the possibility of implementing more sophisticated algorithms such as the Pan and Tompkins method [3] in smartphones. However, there is a significant trade-off as there will always be a power-consumption limitation in processing ECG signals on battery-operated devices.
Analyzing real-time ECG signals collected by a battery-driven device needs to be fast and feasible in real-time, despite the existing limitations in terms of memory and processor capability. The same holds for the ability to analyze large ECG recordings collected over one or more days. Therefore, the main goal of this study is to produce a fast robust QRS detector that suits batterydriven applications and continuous 24/7 ECG monitoring, with theoretical justification for its parameters choice, tested over 11 large-standard datasets with different sampling frequencies, recording lengths, and noise. This study seeks to compare the various QRS detection methods against the developed QRS detection on standard databases. Furthermore, the theoretical basis of the well-known Pan and Tompkins algorithm [3] will be analyzed and evaluated against the proposed algorithm. The failures will be discussed, and the processing time of the proposed algorithm will be elaborated on.

Data Used
Several established ECG databases are available for evaluating QRS detection algorithms for ECG signals. As a sufficiently broad test scenario, 11 representative datasets published on PhysioNet [18] served for analyzing and comparing the proposed algorithm. These sets represent different subject groups and recording conditions, such as sampling rates (between 128 Hz and 1 kHz) and interferences. Lead I of every record is used without any exclusion. The corresponding reference R markers provided in the datasets acted as the benchmark.

Training Set
The MIT-BIH Arrhythmia Database [5] is widely used to evaluate QRS detection algorithms. However, in this study, the database used for training as it includes different shapes of arrhythmic QRS complexes and noise. Most prominent were power-line interferences (60 Hz and its harmonics, see Fig. 1 (a)), which are known to be a major disturbance [6]. In addition, the design considered high-frequency noise, mostly originating from muscle activation (see Fig. 1 (b)), as well as low-frequency baseline fluctuations (see Fig. 1 (c, d, e)). Among the representative physiological events present in the datasets, special attention was paid to missing P waves (e.g., in junctional escape beats [7]; Fig. 1 (e)) and inverted (e.g., premature ventricular contractions, Fig. 1 (f)), notched (left bundle branch block, Fig. 1 (g)), as well as biphasic QRS complexes (right bundle branch block, Fig. 1 (h)). Finally, pacing-related phenomena were taken into account (see Fig. 1 (i, j)).

Testing Set
Ten datasets were used for testing: the meta-dataset QT Database with 111,301 beats [8]; the T-Wave Alternans database with 19,003 beats, selected for its wide range of pathological conditions [9]; the Intracardiac Atrial Fibrillation database with 6,705 beats [10]; the ST Change database with 76,181 beats featuring stress ECGs [11]; the Supraventricular Arrhythmia database with 184,744 beats [12]; the Atrial Fibrillation Termination database with 7,618 beats [13]; the Fantasia database with 278,996 beats from relaxed healthy subjects [14]; the Noise Stress Test database with 26,370 beats recorded under noise conditions typical for clinical environments [15]; the St. Petersburg Institute of Cardiological Technics Arrhythmia database with 175,918 beats [7]; and the Normal Sinus Rhythm database with 183,092 beats [7]. In the Fantasia database, one record ('f2y02') was corrupted and was accordingly excluded. These benchmark datasets were selected for testing because of their representative character regarding pathological and typical ECG artifacts. Consequently, these were taken into account in testing the robustness of the proposed method.

Methodology
In this section, a new, knowledge-based, numerically efficient, and robust algorithm is proposed to detect QRS complexes in ECG signals based on two event-related moving-average filters. The structure of the proposed algorithm is shown in Figure 2. It is clear that the knowledge base supports the decision making of both stages: generating blocks of interest and thresholding. It is expected that developing a detector that depends on prior knowledge of the ECG features will improve the overall performance and detection accuracy. Clifford et al. [16] provided a mini knowledge-base of the normal limits for the main events within the EGG, for a healthy male adult at 60 beats per minute (bpm), shown in Table 1.
The prior knowledge of the duration of the main events of the ECG signals can assist the feature extraction and support the decision making of the algorithm. For example, in this work, knowing that the QRS duration in a normal healthy subject varies from 29 to 43 samples, for a sampling frequency (SF) of 360 Hz, determines W 1 in generating blocks of interest and thresholding (cf. Figure 2). Similarly, the average heartbeat duration determines W 2 in generating blocks of interest. The average value for heartbeat duration is one second in healthy subjects, which means 360 samples (for a sampling frequency of 360 Hz). At this stage, W 1 and W 2 can be initialized by the prior knowledge that has been mentioned above. However, these durations vary from person to person. Therefore, the exact value for W 1 (QRS duration) and W 2 (one beat duration) will be determined after a brute force search, which will be discussed later in the parameter optimization section.

Band-pass Filter
Morphologies of normal and abnormal QRS complexes differ widely. The ECG signal is often corrupted by noise from many sources, which has been discussed. Therefore, band-pass filtering is an essential first step for nearly all QRS detection algorithms. The purpose of band-pass filtering is to remove the baseline wander and high frequencies that do not contribute to detecting QRS complexes. A band-pass filter is used, typically a bidirectional Butterworth implementation [17]. It offers good transition-band characteristics at low coefficient orders, which makes it efficient to implement [17]. Thakor et al. [18] and Chen and Chen [19] scored high accuracy using a third-order Butterworth filter with a passband of F 1 -F 2 Hz to remove baseline wander and high frequencies, and to suppress the P and T waves and maximize the QRS area, where F 1 is the starting frequency and F 2 is the stopping frequency. The effect of the Butterworth filter can be seen in Figure 3 (b). However, rigorous optimization over the passband, to find the optimal frequency band, will be discussed in the parameter optimization section.

Squaring Function
The signal is squared point by point, to enhance large values and boost high-frequency components, using the following equation: The impact of the squaring is shown in Figure 3 (c).

Generating Blocks of Interest
Blocks of interest are generated using two event-related moving averages. The first moving average MA QRS is used to extract the QRS features while the second-moving average MA beat extracts the QRSs beat. Then, an event-related threshold is applied to the generated blocks to distinguish the blocks that contain R peaks from the blocks that include noise. The purpose of the QRS moving (MA QRS ) average is to smooth out multiple peaks corresponding to QRS complex intervals in order to emphasize and extract the QRS area: where W 1 is the approximate duration of the QRS complex, rounded to the nearest odd integer, and n is the number of data points. Based on the knowledge-base analysis section, the QRS duration W 1 varies from 29 to 43 samples (for a sampling frequency of 360 Hz). Therefore, rigorous optimization to find the optimal W 1 will be discussed in the parameter optimization section.
The purpose of the one-beat moving average (MA beat ) is similar to MA QRS but emphasizes the QRSs beat to be used as a threshold for the first moving average (MA QRS ): where W 2 is the approximate duration of a heartbeat, rounded to the nearest odd integer, and n is the number of data points. Based on the knowledge-base analysis section, heartbeat duration W 2 is about 360 samples (for a sampling frequency of 360 Hz); however, it varies from person to person. Rigorous optimization to find the optimal W 1 will be discussed in the parameter optimization section. The blocks of interest are generated based on the two moving averages discussed. In other words, applying the secondmoving average MA beat as a threshold to the first-moving average MA QRS produces blocks of interest, as shown in Figure 3 (d).
However, the use of MA beat without an added offset reduces the detection accuracy because of its sensitivity to a low signal-to-noise ratio (SNR). The SNR defined the ratio of the mean signal of a region of interest to its standard deviation [20], which means if the statistical mean of the signal increases, the SNR increases. This leads to introducing an offset based on the statistical mean of the signal as where b is the fraction of the z z signal that needs to be removed, z z is the statistical mean of the squared ECG signal z, as illustrated in Figure 4, and a is an offset for the threshold MA beat signal. Thus, a refers to the offset, while b refers to the offset fraction.
In short, to increase the accuracy of detecting QRS complexes in noisy ECG signals, the dynamic threshold value THR 1 is calculated by offsetting the MA beat signal with a, as follows: The blocks of interest are then generated by comparing the MA QRS signal with THR 1 . If a block is higher than THR 1 , it is classified as a block of interest containing ECG features (P, QRS, or T) and noise; otherwise, as shown in lines 10-16 in Figure 5. By this stage, blocks of interest have been generated, Blocks½n. Therefore, the next step is to reject the blocks that result from noise. The rejection should be related to the anticipated block width.

Thresholding
Here, the undesired blocks are rejected by using the new THR 2 threshold to reject the blocks that contain P and T waves and noise. By applying the THR 2 threshold, the accepted blocks contain only QRS complexes: As discussed, the threshold THR 2 equals W 1 , which corresponds to the anticipated healthy QRS width. If the block width equals the window size W 1 , then the block contains a QRS complex. However, the QRS duration varies in arrhythmia ECG signal durations. Therefore, the condition is set to capture both average (healthy beats) and wide (arrhythmia beats) QRS complex durations. Therefore, if a block width is greater than or equal to W 1 , it is classified as a QRS complex. If not, the block is classified as a P wave, T wave or noise.

Detecting R Peaks
The last stage is finding the maximum absolute value within each block, the R peak.

Parameters Optimization
The function of the QRS detector, which is presented in Figure 5, has five inputs: the frequency band (F 1 -F 2 ), event-related durations W 1 and W 2 , and the offset fraction (b). Any change in these parameters affects the overall performance of the proposed algorithm. These parameters are interrelated and cannot be optimized in isolation. A rigorous optimization, brute-force search based on the knowledge-base information, over all parameters, is conducted, as shown in Figure 6. It is time-consuming, as the  complexity of the algorithm is (( , but it is required before making any claims. The MIT-BIH Arrhythmia Database was used for training and optimization.

Results
The QRS detection algorithm is typically run using two statistical measures: sensitivity (SE) and positive predictivity (+P); whereas SE~TP=(TPzFN) and zP~TP=(TPzFP). Here, TP is the number of true positives (QRS complexes detected as QRS complexes), FN is the number of false negatives (QRS complexes have not been detected as QRS complexes), and FP is the number of false positives (non-QRS complexes detected as QRS complexes). The SE reports the percentage of true beats that were correctly detected by the algorithm. The +P reports the percentage of beat detections that were true beats. Figure 6 shows that the optimizations of the beat detector's spectral window for lower frequency varied from 1-10 Hz, with the higher frequency up to 26 Hz. All combinations of the frequency band 1-26 Hz have been explored to include all frequency bands that have been recommended in the literature such as 8-20 Hz [21], 5-15 Hz [18,19], and 5-11 Hz [3]. The window size of the MA QRS (W 1 ) ranged from 55 to 111 ms, whereas the window size of the MA beat (W 2 ) changed from 555 ms to 694 ms as discussed in the knowledge-base analysis section. However, the offset was tested over the range 0-10% of the mean value of the squared filtered ECG signal. The database used in the optimization process is the MIT-BIH Arrhythmia Database because it contains abnormal rhythms, different QRS morphologies, and low SNR signals, as described in the Challenges in the ECG section. The total number of beats in the MIT-BIH Arrhythmia Database is 109,984, and there are 48 records. As discussed, several publications have listed the use of all files in the database, excluding just the paced patients, segments, and certain beats. However, in the optimization process all records have been used without excluding any beat. After the rigorous optimization, all parameter combinations were sorted in descending order according to the overall accuracy, as shown in Table 2; thus, the first combination provides the optimal solution. The highest overall-accuracy score is 99.83% (cf. Table 2); therefore, the optimal frequency range for QRS detection in the MIT-BIH Arrhythmia Database is 8-20 Hz, as proposed by Benitez et al. [21]. Moreover, the optimal values for the moving averages and offset are W 1 = 97 ms (35 samples for SF = 360 Hz) and W 2 = 611 ms (220 samples for SF = 360 Hz), and b~8. (Investigators do not have to think about the optimization as it is already done here for them; all they need to do is simply implement the proposed algorithm with these optimal parameters.)

Testing Results
Now, an optimal QRS detector is accomplished over the MIT-BIH Arrhythmia Database. Then, we can test this detector on . Demonstrating the effectiveness of using two moving averages to detect the QRS complex. (a) One beat ECG signal, (b) filtered one-beat ECG signal with Butterworth band-pass filter, (c) squaring the filtered signal, and (d) generating a block of interest after using two event-related moving averages: The dotted red line is the MA QRS , and the solid green line is the MA beat . The R peak within the block of interest is then detected after the event-related threshold is applied. doi:10.1371/journal.pone.0073557.g003  other datasets straight out of the box without any tuning. In other words, the algorithm's parameters (F 1 , F 2 , W 1 , W 2 , and b) do not need to be trained in real-world application for every subject. The parameters are optimized on a large training set (MIT-BIH data set); thus, the robustness of the algorithm can be examined against different databases with different sampling frequencies and the ECG signals collected by different doctors in dissimilar conditions. Table 3 shows the performance of the QRS detection algorithm on 11 databases. In addition, the performances are summarized across these databases and compared to other reported results. Because the algorithm has not been re-tuned over any databases, the results are promising, and the algorithm can detect R peaks over different databases, sampling frequencies, types of arrhythmias, and types of noise. The number of beats used    [34] scored higher performance, a sensitivity of 99.89% and a specificity of 99.94%, than the proposed algorithm. This is because Li et al. excluded files 214 and 215 from the MIT-BIH Database, and therefore, the algorithm is not superior in terms of performance. However, their algorithm was based on wavelets feature extraction and singularity for classification, which is considered numerically inefficient. Moreover, the algorithm developed by Ghaffari et al. [25] scored a sensitivity of 99.91% and a specificity of 99.72% over 109,837 beats (not all beats); their algorithm was based on wavelets feature extraction and thresholds for classification, which is also considered numerically inefficient. Conversely, the proposed knowledge-based algorithm presents a clear advantage over the previously reported algorithms in terms of performance (large number of databases) and numerical efficiency. This was clear with the MIT-BIH Arrhythmia Database, as discussed above. In addition, the QTDB where the detector scored an SE of 99.67% and a +P of 100%, over 111,193 beats, without excluding any beats as Martinez et al. [30] and Aristotle [30] did. Furthermore, the overall performance of the detector on the NSTDB was higher than Benitez et al. [36], with clear mentioning of the number of beats used, specifically 26,370 beats.

Discussion
After the description of the detector and its results on different datasets, perhaps further elaboration on the detectors performance is required. However, comparing the performance of the proposed algorithm with previously published algorithms is difficult. This is because the algorithms are not tested on the same data, in particular the same beats. By excluding the number of beats and/or certain records, the performance of any detector will score higher detection rates. Here are a few examples to clarify the idea:   N Continuous spline wavelet transform using local maxima of the continuous wavelet transform at different scales have been used by Alvarado et al. [41]. They reported sensitivity of 99.87% and positive predictivity of 99.82% after using just nine files out of 48 files from MIT-BIH Arrhythmia Database. N Zhang et al. [42] used the continuous wavelet transform, followed by fixed thresholds. They reported accuracy of 99.5% after using just eight files out of 48 files from MIT-BIH Arrhythmia Database.
Most of the proposed algorithms were tested on one dataset, the MIT-BIH Arrhythmia Database. The authors exclude some records from the database to improve the overall accuracy. Here is an example based on the proposed detector: If records 108 and 207 are excluded from this study, the proposed detector scores SE of 99.9% and +P of 99.95%, which does not reflect the real performance of the algorithm. Therefore, the author urges readers, researchers, and biomedical-signal-analysis community of using the standard databases with excluding any record or beat. Now, after the misleading conclusions based on data elimination have been discussed, the performance of the proposed detector can be discussed technically. The main technical aspects of any QRS detector are frequency-band choice, window-size and threshold choices, failure, and processing time.

Implementation Steps
In general, the Pan and Tompkins algorithm is more complex compared to the proposed algorithm, and thus has more implementation steps, as shown in Table 4. The Pan and Tompkins algorithm requires a resampling step for any ECG signal not sampled at 200 Hz. Its filters are designed for 200 Hz, so performance will be degraded at other sampling frequencies.
Moreover, as the Pan and Tompkins algorithm is amplitude dependent, subtraction of the statistical mean of the ECG signals is also required. It also imposes a differentiation step to emphasize the QRS complex slope information. Furthermore, the thresholding step is complicated (really this word, not just a phrase that contains it) compared to that of the proposed algorithm. The thresholding code of the Pan and Tompkins algorithm is taken from DigiScope software [43].

Frequency-Band Choice
In the literature, the QRS frequency band has been used without actually identifying the optimum QRS frequency range for the detection of the QRS complexes. Different researchers used different passbands; for example, Thakor et al. [18] proposed an estimate of QRS complex spectra and suggested that the passband that maximizes the QRS energy is approximately 5-15 Hz. Pan and Tompkins [3] used cascaded low-pass and high-pass filters to achieve a passband of about 5-11 Hz. Li et al. [34] used a quadratic spline wavelet with compact support and one vanishing moment. They concluded that most QRS complex energies are at the scale of 2 4 ; that is, the Fourier transform frequency range lies between 4 and the 13.5 Hz. Sahambi et al. [44] used the first derivative of a Gaussian smoothing wavelet and found that most QRS complex energies are at the scales of 2 3 and 2 4 , with corresponding frequency ranges between 4.1 Hz and 33.1 Hz. Benitez et al. [36] developed a QRS detection algorithm using the properties of the Hilbert transform with band stop frequencies at 8 and 20 Hz in order to remove muscular noise and maximize the QRS complex, respectively. Moraes et al. [38] combined two improved QRS detectors using a band-pass filter between 9 and 30 Hz. Chen and Chen [19] introduced a QRS detection algorithm based on real-time moving averages and assumed the QRS frequencies were concentrated at approximately 5-15 Hz. Mahmoodabadi et al. [45] used Daubechies2 to detect QRS complex using scales of 2 3 -2 5 , which covers the frequency range 2.2-33.3 Hz.
Most of these authors evaluated their algorithms using the MIT-BIH Arrhythmia Database and determined the frequency bands experimentally, without justifying their choice. Thus, an optimal frequency band for detecting QRS complexes is proposed based on rigorous brute-force optimization, which is 8-20 Hz, as elaborated in the parameter optimization section. This result confirms the findings of Elgendi et al. [46] that 8-20 Hz optimizes the QRS detection. Moreover, Figure 7 shows the influence of a certain frequency band on the overall accuracy. It is clear that F 1 scores consistent results above 5 Hz, as shown in Figure 7(a). Thus, in designing a band-pass filter, the starting frequency should lie within 5-10 Hz. Regarding the stopping frequency, F 2 , perhaps the optimal choice is 20 Hz, which has the highest average and lowest standard deviation; 19 and 21 Hz can still provide relatively high accuracy.

Window-Size and Threshold Choices
The window size is an important factor in detection; it should reflect the duration of the QRS complex, which is an individual characteristic that further depends on the heart rate, and thus is hard to predict. Researchers generally use a fixed window size for the moving average that demarcates the QRS complex; for example, Pan and Tompkins [3] used a fixed window size of 30 (which is 150 ms). However, their adaptive thresholds were based on the eight most recent beats [3]. The disadvantages of their algorithm are the window size is determined empirically and thresholds depend on the accuracy of the heart rate determined in the previous segment. A domino effect of errors will occur. Therefore, a new solution is needed that does not depend on the recent heart rate. The proposed method uses a predefined but on average perfect constant window size by searching for the optimized window sizes for the QRS and heartbeat durations. However, the algorithm shares some steps with Pan and Tompkins algorithm. A comparison is presented in Table 4 to show the main differences and the novelty of the proposed methodology, which is the optimized knowledge-base consideration. In addition to efficiency, the author aimed at reducing the complexity of detection methods. Therefore, the proposed method uses a predefined but on average optimal constant window size (see Table 4) to demarcate the QRS complex. The second moving average filter was implemented to eliminate the multiple static thresholds by demarcating each heartbeat, which works as a datadriven threshold for the first moving average MA QRS . Thus, the proposed detector overcomes the unjustified parameters value and the use of fixed thresholds. Figure 8 shows the influence of the window sizes of the moving averages and offset on the overall Table 4. Comparison between the proposed QRS detector and the Pan and Tompkins algorithm. Step Proposed Detector Pan and Tompkins [3] Resampling accuracy. It is clear that the optimal window size W 1 for detecting QRS can be 30, 35, or 40 samples (for SF = 360 Hz). The optimal window size W 2 for demarcating a heartbeat was hard to determine, as it perhaps can be 220, 230, 240, or 250 samples (for SF = 360 Hz). The optimal offset fraction b varies from 2 to 10% (cf. Figure 8 (c)). However, the optimal combination based on the brute-force search was W 1 = 35 samples 97 ms, W 2 = 220 samples 611 ms, and the offset fraction was b = 0.8, as shown in Table 2. Combinations 2 to 17, in Table 2, provide relatively high accuracy as well.

Instances of Failure
After the training phase, which is discussed in the parameters optimization section, the parameters of the developed QRS algorithm were optimized over the MIT-BIH Arrhythmia Database. The optimized algorithm will be tested on all other databases without any tuning. The algorithm has been used straight out of the box and has not been re-tuned over any databases. In the testing phase, usually algorithms fail at specific instances within the ECG recordings, which are considered either false positives (FPs) or false negatives (FNs). These instances of  Figure 10). In Figure 9, the two moving averages succeeded in generating blocks of interest that demarcated all QRS complexes, but also demarcated the wide P waves, causing FPs before B1, B4, and B5 shown in Figure 9; and threshold THR 2 could not help in rejecting them. On the other hand, the moving averages could not generate blocks of interest due to the fast rhythm as B3, B5 and B7 show in Figure 10.
For the INCART database, the algorithm incurred a total of 5197 FPs and 1995 FNs. Because of the very noisy signals, Record 53 had 428 FPs and 104 FNs (cf. Figure 11). The annotations of this database may need revision as the position of the R peaks is very hard to determine, as shown in Figure 11. However, the algorithm runs over the database without any adjustments to the annotated R peaks. FPs and FNs were 315 and 50 when the algorithm was applied on the Fantasia database. The highest FP values were in record f1o09, where the ECG signals contain wide U waves, as shown in Figure 12 Figure 11). The annotations of this database perhaps needs revision as the position of the R peaks is very hard to determine, as shown in Figure 11. However, the algorithm runs over the database without any adjustments to the annotated R peaks.
Using the AFTDB database, the detector achieved a low number of FPs, and FNs, 17 and 34, correspondingly. Due to the fast rhythm of the atrial fibrillation, the number of FNs was higher than that of the FPs, which is similar to the detectors performance on the MIT-BIH Arrhythmia Database; Figure 10 may clarify the idea of the occurrence of FNs in a fast rhythm. It was expected that SVDBs performance would have more FNs than FPs, as it contains supraventricular arrhythmias. However, the highest number of FNs was registered from Record 848-SVDB due to the rapid heart rhythm. The number of FPs also increased because of the noisy reversed-polarity QRS beats, as in Record 886, which had the highest number of FPs, exactly 99 of a total of 356. Figure 13 shows how the isolated QRS-like artifacts caused FNs in Record iaf7_afw from the IAF database, scoring the highest number of FNs, 80 FNs out of a total of 83. On the other hand, the number of FPs was the highest, 250 out of a total 419 FPs, in Record iaf5_afw, which contains wide U waves similar to the example presented in Figure 12.
It can be seen in Figure 14, because of the T wave alternans and low-amplitude QRS complexes, that detecting R peaks is challenging. The performance of the detector on the TWA database incurred 156 FPs and 230 FNs. The first FN (at left) occurred because the moving average could not generate blocks of interest; however, the second FN (at right) happened since it has been demarcated (cf. Figure 14). The duration of the block (second FN at right) is below the optimized duration of QRS complex W 1 , and is thus rejected causing FN, while the FP arises due to the existence of noisy T wave alternans.
Analyzing the performance of NSTDB is quite confusing, perhaps because the annotations are not completely correct and certainly need modification. However, the detector ran over the dataset as it is and incurred 2,844 FPs and 1,199 FNs overall. Regarding the ST database, the FPs and FNs were 131 and 33 in total, respectively. The highest number of FPs occurred in Record 305-STDB due to large T waves, while the inverted polarity of QRS complexes caused the large number of FNs. On the other hand, the detectors obtained a total of 305 FPs and 3 FNs over the       QT database. The FPs are mainly caused by the steeply upwardsloping T waves (cf. Figure 15).

Processing Time
In this study, the proposed detector was implemented in MATLAB 2010b (The MathWorks, Inc., Natick, MA, USA) on Intel TM i5 CPU 2.27 GHz. Perhaps it is misleading to suggest that mentioning the average speed of the proposed detector, over a certain time length of ECG signal, would provide a comparative result. This is because the processing time depends on the number of beats within each ECG recording, not on the record length. As the 11 databases contain different recording lengths, a categorization by recording length is needed to evaluate the speed of the Pan and Tompkins algorithm and the proposed detector fairly on the same computer. It can be seen in Figure 16 that the proposed algorithm was faster and steadier across all recoding-length categories compared to Pan and Tompkins algorithm. The speed measured in seconds, while the recording-length category was in minutes. The number of beats of the 30-minute recordings category was relatively consistent-with a mean 6 SD, number of beats 22916448-over all records of this category. The same holds for 1-minute and 15-minute recording categories. On the contrary, the 130-minute beat average was 10,171 with an SD of 2,600 beats; thus, the processing time depends on the number of beats rather than the recording length. For example, Record 16272-NSRDB contains 7,988 beats, and the proposed detector took 1.5 seconds to process it, while it took 3.5 seconds to process 14,875 beats in Record 19830-NSRDB. In general, without taking the number of beats into consideration, the speed of the proposed detector is fast. The suggested detector handles 15-minute recordings in about 0.15 seconds, while it takes about 2.2 seconds to handle 130-minute ECG recordings.

Limitations of Study and Future Work
One of the next steps regarding the result of this study is to detect arrhythmic ECG beats, using the RR interval as the main  feature. In addition, the detection of P and T waves based on the accurate detection of R peaks need to be examined.
Optimization was performed over the MIT-BIH Arrhythmia Database as a whole. For better comparability, the whole data set could have been separated into a training and a test set in which the training set is used for optimizing and the test set for evaluating the performance. Perhaps the leave-one-out cross validation suits this optimization step.
In this investigation, the processing time of the Pan and Tompkins algorithm and the proposed algorithm is carried out using MATLAB for batch processing of ECG files. MATLAB does only high precision floating point arithmetic. Perhaps, the implementation of the proposed algorithm in C-language is required to compare the performance over fixed point integer arithmetic (i.e., it doesn't need a high performance computer with a multi-precision floating point processor to run).
It is important to note that the largest ECG recording used in this study is 130 minutes. Larger recordings (e.g., 24 hours) with different noise levels are needed in order to generalize the findings of this study.
Technically, exploring the event-related moving average methodology for detecting events in ECG signals is promising in terms of computational complexity and efficiency. This can be further improved by investigating other band-pass filters, with different orders, and also by developing fast-moving average techniques for real-time analysis and mobile phone applications.

Conclusion
A new approach for detecting QRS in ECG signals is presented. It contains two parts: the optimization, which was more complex, and the algorithm itself, which is tuned now and can be implemented and used with relative easiness. The performance of the optimized knowledge-based detector is promising. It has been tested on different databases that contain unusual noise, QRS, T, and U waves morphologies. The extensive use of the MIT-BIH Database as a testing database can hide overtuning of the detector parameters to fit this particular database. Consequently, the validation of the same detector on a second dataset without any later parameter tuning can help to obtain more reliable performance results. After the algorithm was applied on other databases, high detection rates were obtained on the QT database, NSR, TWA, IAF, ST, SV, AFT, FANTASIA, NST and ICART databases. Interestingly, the detector's speed over 130-minute recordings is about 2.2 seconds; thus, the proposed detector is an auspicious tool for processing large-recorded ECG signals. Furthermore, its simplicity makes it an ideal algorithm for mobile-phone applications and battery-driven ECG signal devices. Moreover, such a fast robust algorithm could have several interesting applications in an online analysis of cardiac data collected by the smallest long-term recording devices that have been studied in the form of necklaces and smart electrodes. The assessment of the QRS detector has been reliably conducted over the existing standard databases. Moreover, the number of annotated beats used in testing the new algorithm is considered sufficient as it is tested on a good representation of the possible morphologies found in ECG signals.