Introduction

In automated electrocardiogram (ECG) signal analysis, the first step is to accurately detect the QRS complex, which is subsequently used for measuring other features of the ECG signal. Perhaps, the most critical use of QRS detection occurs in intensive care unit arrhythmia monitoring systems, which includes ECG machines in operating room monitors. The duration, amplitude, and morphology of the QRS complex are useful in diagnosing cardiac arrhythmia, conduction abnormalities, ventricular hypertrophy, myocardial infarction, electrolyte derangement, heart rate variability (HRV), and other disease states.10 Also, the precise detection of QRS complex is required for accessing the state of the heart, as it corresponds to the electrical excitation of the two ventricles. Any cardiac dysfunction changes the morphology of the waveform and the duration of the RR interval, which is considered clinically important, as it indicates disorders in the re-polarization and depolarization process preceding the critical cardiac arrhythmia. There are substantial precedent algorithms for the detection of the QRS complex available in the literature. Some algorithms are based on digital filters,27 amplitude thresholding,1 derivatives of the ECG signal,15 filter bank method,13 Hilbert transform,3 template matching and morphological filtering,6,12,31,40 Empirical Mode Decomposition,14 wavelet transform,2,4,9,20,22,30,32,36,38,39 Hidden Markov method,8 Neural network,16 total variation de-noising,35 matched filters,18 max–min difference28 but still there are challenges to detect QRS complex accurately due to several reasons including diversity of the QRS waveform, abnormalities present in ECG signal, low signal-to-noise ratio (SNR) and artifacts accompanying ECG signals. Many of the existing algorithms are not able to perform noise reduction and QRS complex detection simultaneously.

The high amplitude of R peak in QRS complex makes it the most prominent feature for detection. The other peaks (P, Q, S, and T) present in the ECG signal are detected by taking R peak as the reference.10 Many a time in the noisy or diseased signal like Right Bundle Branch Block (RBBB), left ventricular hypertrophy, obesity, anasarca, chronic obstructive pulmonary disease (COPD), hyperinflation of lungs, pneumothorax, diffuse myocardial disease (e.g., myocarditis, cardiomyopathy), hypothyroidism; the R peaks has low amplitude and has broad and tall S peaks.11 Also, sometimes clinically there is RsR, rS, QS type of complexes, in which amplitude of R peak is low. In such cases, the R peaks are difficult to detect. Also, the noise present in ECG signal degrades the quality of the signal a lot. The estimation of QRS complex in these cases can be enhanced many folds using some other information which can be extracted from the ECG signal. As S peak is the second dominant feature which can be estimated, therefore we propose for an independent estimate of S peak along-with traditional R peak detection to estimate QRS complex. The independent detection of other peaks like S peak present in the cardiac cycle can aid in the accurate detection of QRS complex.

A novel algorithm has been proposed to estimate S peak independently, previously to the best of our knowledge QRS complex was being estimated from R peak only. Further these detected S peaks along-with R peaks are used to detect QRS complexes. To the best of our knowledge, it is the first time that S peak is detected independent of R peak from the ECG signal and is used to aid the detection of QRS complex. The amplitude of S peaks is quite low, therefore appropriate digital filters are designed for the enhancement of S peaks. Different morphology and noise will affect the S peak in different ways, therefore, adaptive thresholding has been used to detect the S peak. Detected S peak along with detected R peak.1,2,3,9,10,13,14,15,22,27,30,34,36,40 are fused to estimate the QRS complex.

This algorithm gives very precise and accurate detection of QRS complex even for highly noisy signals having varying QRS complex morphology, small and broad QRS complex, QRS complex with sharp and tall P, T waves. It is validated with all the signals of MIT-BIH arrhythmia database.26 The performance of the algorithm is also validated by adding power line interference, electrode motion artifact, baseline wandering interference and muscle artifact to the signals of MIT-BIH arrhythmia database and on signals of noise stress database of physionet.org.26 The false negatives and false positives are substantially reduced especially for noisy signals as compared to results reported in literature.1,3,5,9,10,13,15,19,21,22,23,25,29,32,33,34,37,38,40,41 The algorithm attains 99.99% sensitivity and positive predictivity.

This paper has been organized as follows. “The Proposed Method” constitute the main body of our work, where the problem is discussed and we discuss the algorithm for accurate detection of QRS complex. Results and simulation studies are presented in “Database and Experimental Results”.

The Proposed Method

Noise Suppression in ECG Signal

The ECG signal consists of P, QRS and T waves. The accurate delineation of QRS complex is required for the diagnosis of the state of the heart. The observed ECG signal is corrupted by various artifacts such as baseline wandering artifact, motion artifact, electrosurgical and muscle contraction artifact, power line interference and electrode contact noise, which are superimposed on the ECG signal. The observed ECG signal can be mathematically expressed as,

$$y[n]=\alpha x[n]+w[n],$$
(1)

where x[n] is the ECG signal, \(\alpha\) is the attenuation parameter where \(\alpha\)\(\in\)R and w[n] are the artifacts and noise present in ECG signal. Here, the assumption is being made that the artifacts are linearly added to the ECG signal. For accurate detection of QRS complex, the artifacts must be removed from the observed ECG signal. The ECG signal consists of different waves having different frequencies occurring at different intervals. Therefore, the time–frequency analysis is the best way to analyze them. Here, the wavelet-based time–frequency analysis is used to have the complete accurate representation of the ECG signal. For de-noising, the observed ECG signal is decomposed by discrete wavelet transform (DWT) with the db6 wavelet used as the mother wavelet as its shape resembles the QRS complex. Moreover, the performance of the algorithm was also checked in literature2 and experimentally with other wavelets. It was found that db6 is the best suitable mother wavelet for ECG signal analysis. The DWT analyses the signal at different resolution (hence, multiresolution) through the decomposition of the signal into several successive frequency bands. The signal detail corresponding to scale index s is defined for a finite length signal as

$$d_{s}[n]=\langle {\langle {y[n],\psi _{s}[n]}\rangle ,}\psi _{s}[n]\rangle ,$$
(2)

where \(\psi _{s}[n]\) is the mother wavelet.

For wavelets, the scale factor s is inversely related to the frequency f. Depending upon frequency support of the observed ECG signal, it is decomposed up to a desired level and frequency. With the sampling frequency of 360 Hz, the complete information of the observed ECG signal is present till 10th level of decomposition.2 Therefore the signal y[n] is decomposed till 10 levels and the detail coefficients obtained are labeled as \(d_1[n]\) to \(d_{10}[n]\) respectively. The frequency band of each detail coefficients obtained at a particular scale is shown in Table 1.

Table 1 Frequency distribution of detail coefficients.
Figure 1
figure 1

Energy distribution of detail coefficients.

As in literature,2 the frequency bands of electrosurgical noise is 100 kHz–1 MHz and muscle contraction noises is dc-10 kHz, they are eliminated by discarding the details \(d_1[n]\) and \(d_2[n]\). The motion artifacts and baseline wandering noise is caused due to respiration and has frequency varying from 0.15 to 0.8 Hz. These two types of noises are discarded by removal of the lowest frequency component, i.e., detail coefficient \(d_{9}[n]\) and \(d_{10}[n]\). The most of the ECG signal energy is concentrated at the QRS complex.2,36 For the energy analysis, the average energy content of the detail coefficients for all signals of MIT-BIH arrhythmia database is calculated and the plot is shown in Fig. 1. The plot of the energy distribution of detail coefficients shows that most of the energy is concentrated at scale 4. Therefore, it is considered that \(d_4[n]\) and its neighboring scales carry the dominant details of the QRS complex. Also, according to Table 1 the detail coefficients \(d_3[n]\), \(d_4[n]\) and \(d_5[n]\) has the frequency band of QRS complex (5–25 Hz). Therefore, all other approximations and details are discarded and signal is estimated from detail \(d_3[n]\), \(d_4[n]\) and \(d_5[n]\) only. But from literature17 and experimentally it is observed that \(d_3[n]\) contains power line interference and electrode contact noise having a frequency range of 50–60 Hz, therefore it is discarded. The noise-free ECG signal \({\hat{x}}[n]\) is therefore estimated from \(d_4[n]\) and \(d_5[n]\) only.

$${\hat{x}}[n]=d_4[n]+d_5[n],$$
(3)

where \(d_4[n]\) and \(d_5[n]\) are details at level 4 and 5 respectively and is obtained from DWT of the signal y[n].

Figure 2
figure 2

(i) Observed ECG signal. (ii) Signal estimated after wavelet transform.

Figure 2 shows the observed ECG signal (record 106m of MIT-BIH arrhythmia database) and signal estimated from \(d_4[n]\) and \(d_5[n]\) after the removal of artifacts. In this figure, both R and S peaks of the signal are enhanced. But here we are aiding the detection of QRS complex by independently detecting the S peak. As the detection of S peaks also helps in better estimation of QRS complex for noisy or diseased signals. The technique to estimate the S peaks is discussed in the following subsections.

Enhancement of S Peak

The signal \({\hat{x}}[n]\) estimated after performing the wavelet transform on the observed ECG signal has enhanced S peaks but this stage is constructed to further accentuate the S peaks and to reduce the influence of the Q and R peaks present in ECG signal. This is done by passing the denoised signal \({\hat{x}}[n]\) through the following digital filter.

$${\hat{y}}_1 [n]={\hat{x}}[n-4]-{\hat{x}}[n]$$
(4)

Figure 3 shows the enhanced S peaks obtained as the output of the digital filter.

Figure 3
figure 3

Wavelet transformed signal and signal obtained after passing through digital filter.

The enhanced S peaks in signal \({\hat{y}}_1[n]\) are further accentuated by cubic nonlinear transform as given in Eq. (5). Here, the cubic nonlinear transform is used as it maintains the sign of the signal while amplifying the peaks of the signal \({\hat{y}}_1[n]\).

$${\hat{y}}_2[n]= \frac{1}{|{\hat{y}}_1[n]|}{\hat{y}}_1^3[n] .$$
(5)

Adaptive Thresholding Technique for Finding Location of S Peaks

The S peak in the signal \({\hat{y}}_2[n]\) corresponds to maximum positive amplitude in the segment corresponding to the QRS. Therefore in order to detect the S peak first the boundaries of the QRS complex are obtained and then the maxima point in the estimated boundaries of QRS complex corresponds to the S peak. The boundaries of QRS complex are detected using feature signal obtained by counting the number of zero crossings per segment.19 Therefore a small amplitude high-frequency signal \(\hat{h}[n]\) is added to the processed signal \({\hat{y}}_2[n]\). The amplitude of \(\hat{h}[n]\) is appropriately chosen such that the frequency of non-QRS part in resultant signal \({\hat{z}}[n]\) is much larger than QRS part, which helps us in detecting the QRS complex. As seen in Fig. 3, the signal \({\hat{y}}_2[n]\) has high amplitude during QRS complex and low amplitude otherwise. The signal \({\hat{z}}[n]\) is obtained as,

$${\hat{z}}[n]= \hat{h}[n]+{\hat{y}}_2[n],$$
(6)

where the high-frequency sequence \(\hat{h}[n]\) is computed as,

$$\hat{h}[n]= (-1)^n\hat{e}[n].$$
(7)

The amplitude of the high-frequency sequence \(\hat{h}[n]\) is calculated from the amplitude of \({\hat{y}}_2[n]\) such that the effect of this addition increases the frequencies of non-QRS complex part of the signal and is given as

$$\hat{e}[n]= \lambda \hat{e}[n-1]+c(1-\lambda ).|({\hat{y}}_2[n])|$$
(8)

where \(\lambda\) is forgetting factor and \(\lambda\)\(\in\) (0;1), c \(\in\) [1,4] and |.| is absolute operation. The frequency of the signal is estimated by zero crossings in the signal \({\hat{z}}[n],\) which are detected as,

$$\hat{k}[n]= |\frac{sign({\hat{z}}[n])-sign({\hat{z}}[n-1])}{2}|$$
(9)

Further these zero crossings are passed through a low pass filter as in (10) to remove other artifacts. Counting the number of zero crossings per segment with a moving window leads to the feature signal \(\hat{f}[n]\), which is defined as,

$$\hat{f}[n]= \lambda _d\hat{f}[n-1]+(1-\lambda _d)\hat{k}[n]$$
(10)

The adaptive threshold \(\hat{\theta }[n]\) is calculated as in (11) by a first-order recursive filter which is applied on the obtained feature signal. For detection of S peaks, the calculated threshold \(\hat{\theta }[n]\) is compared with feature signal \(\hat{f}[n]\).

$$\hat{\theta }[n]= \lambda _\theta \hat{\theta }[n-1]+(1-\lambda _\theta )\hat{f}[n]$$
(11)

where \(\lambda _\theta\) and \(\lambda _d\) are forgetting factors.

$$\lambda _\theta \in (0;1),\quad \lambda _d\in (0;1)$$
(12)

when the feature signal \(\hat{f}[n]\) falls below the adaptive threshold \(\hat{\theta }[n]\), the sequence obtained is \(N_1[k]\) and \(N_2[k]\) is the sequence obtained when feature signal rises above the threshold.17 These \(N_1[k]\) and \(N_2[k]\) points are taken as the boundaries of the QRS complex interval in signal \({\hat{x}}[n]\). As in (13), the maximum point obtained in this interval is S peak

$$S_{\rm peak}[k]=\max({\hat{x}}[N_1[k],N_2[k]]).$$
(13)

The complete process of thresholding is also shown in Fig. 4.

Figure 4
figure 4

Steps of adaptive thresholding.

The detected \(S_{\rm peak}\) are used for detecting R peaks. From the detected S peak, traverse back with a window of 10 ms and find the maxima point soon before the detected S peaks. The location of maxima point obtained is the location of R peak.

Estimation of QRS Complex by Using Fusion Algorithm

The R peak is the strongest peak present in QRS complex and is traditionally used to detect the QRS, therefore we suggest to fuse these two estimates to obtain a robust and better estimate of QRS complex. Here R peaks estimated by the suggested method is denoted as Rs[k] and R peak detected by traditional method is denoted by Rr[k]. These two estimates are ‘OR’ed to obtain fused detection of QRS complex as shown in Fig. 5.

Figure 5
figure 5

Estimation of QRS complex by using fusion algorithm.

As shown in Fig. 6, the QRS complex missed by the techniques reported in the literature34 are detected by the proposed algorithm. The algorithm helps in detecting the QRS complexes which were missed by traditional methods, which is more elaborated in a section of simulation.

Figure 6
figure 6

Performance of the algorithm for record 106m of MIT-BIH arrhythmia database.

Database and Experimental Results

The proposed algorithm was validated on the 48 half-hour digitized signals of the first channel, i.e., modified limb lead II (ML II) taken from MIT-BIH database of physionet.org.26 From 48 recordings, 13 recordings are of healthy persons and 35 recordings are of persons with various cardiac disorders. The recordings were digitized at 360 samples per second per channel and each recording has 650,000 sampling points. It has a variety of wave-forms and artifacts that an arrhythmia detector might encounter in routine clinical use like complex ventricular arrhythmia and supra-ventricular arrhythmia and conduction abnormalities.

The performance of the algorithm is assessed using these statistical measures:

$${\text{Sensitivity}}\,({\text{SE}}) =\frac{\text{TP}}{{\text{TP}}+{\text{FN}}}$$
(14)
$${\text{Positive}}\,{\text{predictivity}}\, (+{\text{Pr}}) =\frac{\text{TP}}{{\text{TP}}+{\text{FP}}}$$
(15)
$${\text{Detection}\,{\text{accuracy}} =\frac{{\text{TP}}}{{\text{TP}}+{\text{FN}}+{\text{FP}}}}$$
(16)
$${\text{Mean}}\,{\text{Square}}\,{\text{Error}}\, ({\text{MSE}}) = \frac{{{\text{Actual beats}}-{\text{(TP)}}}^{2}}{\text{Actual beats}}$$
(17)
$${\text{Error}}\,{\text{rate}} = \frac{{\text{FP}}+{\text{FN}}}{{\text{TP}}}$$
(18)

where TP is the number of true positives (true positive is QRS complex detected within the 30 ms of the annotated QRS complex), FN the number of false negatives (false negative is annotated QRS complex which is not detected), and FP the number of false positives (false positive is QRS complex detected outside the range of 30 ms of the annotated QRS complex).27

Sensitivity tells us the percentage of true QRS complexes that are correctly detected by the algorithm and positive predictivity tells us the percentage of QRS complex detection that was true.10 The algorithm consists of few parameters, i.e., forgetting factors \(\lambda,\)\(\lambda _d ,\) and \(\lambda _\theta,\) which are chosen by rigorous simulations on the available data set. The values used here for \(\lambda\), \(\lambda _d,\) and \(\lambda _\theta\), are 0.99, 0.97, and 0.99 respectively. Here, the R peaks \(R_{\rm r}[k]\) detected independently as in Ref. 34 the best results reported so far and R peaks \(R_{\rm s}[k]\) detected through S peaks by the proposed algorithm are fused together by ‘OR’ operation. The overall performance comparison of the algorithm with the detectors available in the literature is shown in Table 2. The comparison of FN and FP resulted with the proposed algorithm and the detectors available in literature, for the signals of MIT-BIH arrhythmia database are shown in Table 3. The fused algorithm gave better results as compared to the techniques reported in the literature.7,13,24,32,34,38,41 The average sensitivity of 99.99% and positive predictivity of 99.99% and the average detection accuracy of 99.98% has been achieved with a total number of false positive reduced to 80 and false negatives reduced to 42 for the signals of MIT-BIH arrhythmia database. The average error rate comes out to 0.2% for this algorithm, which is far better than reported results in Refs. 7, 13, 24, 32, 34, 38, and 41 Figure 7 shows the improvement against the results reported in Ref. 34 for all the signals of MIT-BIH arrhythmia database and it has shown improvement mainly for diseased and noisy signals like 103m, 104m, 105m, 106m, 107m, 109m, 111m, 116m, 201m, 202m, 203m, 201m, 214m, 215m, 217m, 222m, 228m, 231m and 232m .

Table 2 Performance comparison with published detection methods.
Table 3 Performance of proposed algorithm on MIT-BIH arrhythmia database.
Figure 7
figure 7

(i) Comparison of sensitivity. (ii) Comparison of positive predictivity with algorithm.34

Further to understand the algorithm more, the results obtained with various noisy and diseased signal are discussed. Figure 8 shows, the record 228m of MIT-BIH arrhythmia database which is having high grade noise, abrupt changes, baseline line wandering artifacts, the QRS complexes which were not estimated by earlier algorithms7,13,24,32,34,38,41 are easily detected by the proposed algorithm.

Figure 8
figure 8

Record 228m and detected QRS complexes.

Similarly as shown in Fig. 9, the record 201m of MIT-BIH arrhythmia database is an irregular rhythmic pattern with premature ventricular contractions (PVC) and some episodes of ventricular trigeminy. There is Complex of RsR type, which was missed by the algorithms reported in the literature. The proposed algorithm detected this missed peak through detection of S peak. Also, as shown in table III, the false negative and false positive obtained by this algorithm for this record are 3 and 3 respectively, which is the significant improvement as compared to results reported in literature.7,10,13,24,32,34,38,41 The sensitivity and positive predictivity obtained is 99.86 and 98.75% respectively for this record.

Figure 9
figure 9

Record 201m and detected QRS complexes.

Also, the record 222m has episodes of paroxysmal atrial flutter/fibrillation followed by nodal escape beats. There are several intervals of high-frequency noise/artifact as shown in Fig. 10. But still, there is the accurate detection of the QRS complex in this record by the proposed algorithm.

Figure 10
figure 10

Record 222m and detected QRS complexes.

The algorithm is also compared with the detectors available in literature.7,13,24,32,34,38,41 Table 3 shows the performance comparison of the algorithm with studies of the R peak detectors reported in the literature.7,13,24,32,34,38,41 The main advantage of the present method lies in its results with noisy and diseased signals. The number of false negatives and false positives detected by this algorithm are significantly lower than the other methods. The proposed method achieved better performance than other methods proposed in the literature.

To study the performance of the proposed algorithm with noise, the algorithm is also validated by adding noise to the ECG signals of MIT-BIH arrhythmia database and also validated on signals of noise stress database of physionet.org.24 This was done to have the performance of the algorithm for the signals highly corrupted with noise. The four different noises for which are used for evaluating the performance of the algorithm are power line interference, electrode motion artifact, baseline wandering interference and muscle artifact. The power line interference has 60 Hz pick up and harmonics, which is modeled as sinusoidal and combination of sinusoidal. The amplitude for modeling power line interference is taken 50% of peak to peak ECG amplitude. Electrode motion noise is transient interference that occurs due to loss of contact between the electrode and skin. Baseline wandering occurs due to change in electrode-skin impedance with electrode motion. Muscle artifact occurs due to contractions of muscle which result in millivolt-level potentials. Here, the power line interference is modeled and other three interference are taken from the noise stress database of physionet.org which is added linearly to the ECG signal. Each of four types of noise is added to an ECG signal of MIT-BIH arrhythmia database by scaling at ten different levels. The signal to noise ratio at each scaling level is calculated as,

$${\text{SNR}}_{\rm dB} = 10 log_{10}\left(\frac{P_{\rm signal}}{P_{\rm noise}}\right),$$
(19)

where \(P_{\rm signal}\) is signal power and \(P_{\rm noise}\) is noise power. The sensitivity and positive predictivity are calculated for all the signals corrupted with noise scaled at different levels. Then the average of sensitivity and positive predictivity obtained at particular SNR is calculated. The plot of the average sensitivity and positive predictivity wrt SNR is shown in Figs. 11 and 12. Figure 11(i) shows the behavior of the algorithm when electrode motion artifact is added. The sensitivity and positive predictivity obtained with electrode motion artifact at SNR of 2.5 dB is 88.9 and 96.79%, which increases with increase in SNR. At SNR of 36.5 dB, the sensitivity and positive predictivity obtained is 99.78 and 99.8% respectively. Similarly, in Fig. 11(ii) when muscle artifact is added to signals of MIT-BIH arrhythmia database the sensitivity increases from 90.65 to 99.89% with SNR increase from 9.9 to 48.03 dB respectively. The positive predictivity increases from 92.88 to 99.86% with an increase in SNR from 9 to 48.03 dB. Figure 12(i) shows the average sensitivity and positive predictivity obtained for all signals of noise stress database. It is clear from Figure 12 that sensitivity and positive predictivity increases with increase in SNR. The sensitivity and positive predictivity obtained for noise stress database even at SNR of 0 dB are 97.75 and 97.2% respectively. Figure 12(ii) shows the result when baseline wandering artifact is added. At SNR of 2 dB, the sensitivity and positive predictivity obtained is 98.30 and 97.03% respectively. Even at 0 dB, the results obtained are pretty good for detection of QRS complex.

Figure 11
figure 11

Results with (i) electrode motion artifact. (ii) Muscle artifact at varying SNR.

Figure 12
figure 12

Results with (i) noise stress database. (ii) Baseline wandering artifact at varying SNR.

Conclusion

In this paper, a novel and effective technique for automatically detecting QRS complex is developed. The proposed algorithm is based on detection of R and S peaks independently. S peaks help in identification of QRS complex for the signals with low amplitude QRS complex, wide QRS complex and high level of noise. To best of our knowledge, it is the first time that S peaks are detected to aid in the detection of R peaks. Appropriate digital filters are designed to enhance S peaks which are further detected by using adaptive thresholding. Then the R peaks detected independently and R peaks detected through S peaks are fused together by an ‘OR’ operation. As expected, the results have improved for diseased and noisy signals which can be seen in the result section. The proposed algorithm is able to detect QRS complex with high accuracy and is robust against noise. The detections are not affected by various artifacts and morphology of the ECG signal. The effectiveness of the proposed algorithm is tested on MIT-BIH arrhythmia database. The detection performance is measured in terms of true positive, false positive and false negative for each record. The results obtained were compared with existing QRS complex detection algorithm. The algorithm is able to achieve sensitivity and positive predictivity of 99.99%. The algorithm is also validated after adding the noises to all signals of MIT-BIH arrhythmia database. The performance of the algorithm is seen at varying SNR. The performance of the algorithm is also checked with the signals of noise stress database at varying SNR. The future scope of the proposed algorithm is that when ECG signal has large Q wave in absence of R and S waves, as in myocardial infarction; the algorithm can be designed to detect Q waves independently and then fuse with the proposed algorithm.