1 Introduction

Interest in mobile health care has been rising in recent years due to the increase in people’s health awareness. Specifically, the need for electrocardiogram (ECG) portable monitoring system has risen as it has an important role in supervising the patient’s heart and predicting cardiac arrhythmias. A portable cardiac monitoring system, i.e. Holter system, is an electronic system that records the ECG signal continuously in ambulatory conditions via electrodes attached to the skin of the patient. Such a Holter system has the ability to detect heart beats via an embedded signal processor using digital signal processing techniques in order to compute heart rate variability (HRV) and support doctors in their decision to give medication for patients in case of cardiac malfunctioning [1, 2]. In ambulatory conditions, the Holter system should meet several requirements in order to efficiently perform its task, namely ultra-low energy operation for long battery lifetime, accuracy of heart beat detection, small size for wearability, and low weight of the electronic device [3, 4]. In order to obtain accurate heartbeat detection, the algorithm should be able to deal with several types of noise aggressors added to the ECG signal. These signals are mainly the Electromyography signal (EMG), baseline wander, 50/60 Hz power-line frequency components, and especially electrode motion artifact noise [57]. The motion artifact is a noise introduced to the ECG as a result of the variation of the electrode skin impedance due to movement of the patient. In fact, electrode movement causes skin deformations around the electrode site which in turn cause changes in the electrical characteristics of the skin around the electrode. This noise signal results in poor ECG signal quality and as a result, a possibly erroneous clinical diagnosis, since the shape of such noise mimics that of the normal QRS complex and its frequency spectrum overlaps with that of the ECG [3, 8, 9]. The beat detection issue in the ECG signal with motion artifact was addressed in several ways in the literature. Many approaches adopted motion artifact reduction using adaptive filtering [1012], blind source separation (BSS) [13, 14] or the discrete wavelet transform [9] in order to remove motion artifacts, obtain a clean ECG signal and facilitate heart beat detection. These techniques are complex and consume much power for portable device applications [15]. In addition, there are several technical difficulties that prevent these techniques from obtaining good results especially when the level of noise is high. This paper introduces a beat detection algorithm developed to perform in ambulatory conditions and to have a high robustness against high levels of motion artifact noise. It is based on the adaptive threshold continuous wavelet transform technique with the Mexican-Hat wavelet.

2 Literature Review

Motion artifact removal is the step preceding beat detection. It consists of de-noising the signal by subtracting motion artifacts to allow improved beat detection performance. Both adaptive filtering and Blind Source Separation are techniques used for this task; a reference signal correlated with motion artifact is often needed for this operation.

2.1 Motion Artifacts Reduction

The adaptive filtering technique has been used in the literature as a method to remove motion artifacts [1012, 16], specifically Least mean square (LMS) and Recursive Least Square (RLS) techniques were adopted to subtract such a motion artifact from the bio-potential signal and make the beat detection operation easier. The LMS uses gradients of the mean square error to update coefficients in real time. The RLS technique recursively updates coefficients of the filter to minimize a cost function. Both of these techniques need a time varying reference signal having a good correlation with the motion artifacts in order to update the parameters of the adaptive filter online. This reference signal can be obtained by measuring the skin-electrode impedance (SEI) [17] or the skin stretching via accelerometers [18] or by capacitive ECG sensing [19]. However these attempts had limited results, especially for higher noise levels, since the measured reference signal did not have good correlation with noise [19].

The blind source separation technique consists of separating two uncorrelated signals (ECG and motion artifacts) by the means of linearly independent multi-lead ECG recording. Principal Component Analysis (PCA) and Independent Component Analysis (ICA) were used in the literature [13, 14]. Both techniques attempt to determine independent vectors onto which the input signal is projected in order to separate the motion artifact from the ECG signal. These techniques are known to achieve good results but they require a large processing budget and a large memory space because of their high algorithmic complexity [15].

2.2 Heart Beat Detection Algorithms

Heart beat detection algorithms aim to accurately detect QRS complexes without missing any beat or wrongly detect extra beats, even if the beats show up before expected (tachycardia) or after expected (bradycardia) or of an unexpected shape (Premature Ventricular Contraction, atrial fibrillation). In the literature, the QRS detection algorithms adopted several steps including linear filtering, nonlinear filtering, moving average and thresholding. In particular, band-pass filtering and thresholding are common steps of all algorithms because of the role of the band-pass filtering in amplifying the QRS sequence and minimizing the noise and the role of thresholding for decision making [20].

One of the most basic algorithms for ECG beat detection that was developed in 1985 is Pan and Tompkins algorithm [21]. It estimated that the power spectral density of the QRS complex is contained within the frequency band of 5–12 Hz. Therefore it used cascaded low-pass and high-pass filters to select that frequency band, followed by signal differentiation and a nonlinear operation that squares the resulting signal and finally a moving average filter. Moreover this approach sets two thresholds: one of the noise level estimation and another for the QRS level estimation. The most important feature of this algorithm is the search back property that sets a time interval, based on the previous RR intervals, if no heart beat was detected within this interval (for example because it has an amplitude below the threshold) then the highest peak within that interval is likely to be considered as a heartbeat. However, this algorithm is not suitable for portable applications since it is not adapted to deal with motion artifact noise.

The discrete wavelet transform technique has been used for heart beat detection since it is considered to have a good time-frequency resolution [22]. It consists of decomposing the signal spectrum into several sub-bands depending on the chosen mother wavelet, allowing the representation of the ECG signal temporal features at different resolutions. This transform is performed using cascaded wavelets that have characteristics of low-pass and high-pass filters followed by down-sampling as shown in Fig. 1. The decision is made after computing a signal by a General Likelihood Ratio Test (GLRT) formula. If the signal exceeds a threshold, then it is considered as a real heartbeat. This technique gave a high detection performance with the MIT database [23, 24], and is also considered to be of low power consumption. However, its performance in portable applications with high motion artifact noise levels is not reported in the literature.

Fig. 1
figure 1

Discrete wavelet transform functional diagram [22]

In order to perform the beat detection task, Romero et al. [25] used the CWT technique and precisely the Mexican-Hat wavelet, the selected band-pass filter has a central frequency of 18 Hz. The algorithm takes three-second length data segments to be convolved with the wavelet. Heart beat detection is performed in the CWT domain when the corresponding Modulus Maxima is higher than a threshold. In order to make the algorithm less sensitive to peaks that occur due to high levels of noise, the threshold varies adaptively across time by using a weighted sum of the previous threshold (thold) and the newly calculated threshold (thcurrent). However, this algorithm did not yield good results when performing the noise stress test with MIT database records as the P+ decreases to 80% for an SNR equal to 0 dB. This degradation is due to the fact that the selected frequency band does not decrease the effect of motion artifacts and therefore a lot of false positive beats were detected.

3 Methods

The wavelet transform is a technique that, by a linear transformation, converts a signal into another form that makes certain aspects of the original signal more amenable to study and some features easier to spot. The wavelet transform expression of a continuous signal \({\text{x}}\left( {\text{t}} \right)\) is given by:

$$T\left( {a,b} \right) = {\raise0.7ex\hbox{$1$} \!\mathord{\left/ {\vphantom {1 {\sqrt a }}}\right.\kern-0pt} \!\lower0.7ex\hbox{${\sqrt a }$}}\mathop \int \limits_{ - \infty }^{\infty } x\left( t \right)\psi^{*} \left( {\frac{t - b}{a}} \right)dt$$
(1)

where \(\psi^{*}\) is the complex conjugate of the chosen wavelet, \(a\) is the scale of

the wavelet or the dilation parameter and \(b\) is the location parameter of the wavelet. The wavelet function must satisfy these mathematical criteria:

  1. 1.

    A wavelet must have a finite energy, that is:

    $$E = \mathop \int \limits_{ - \infty }^{ + \infty } \left| {\psi \left( t \right)} \right|^{2} dt < \infty$$
    (2)
  2. 2.

    If \(\widehat{\psi }\left( f \right)\) is the Fourier Transform of \(\psi \left( t \right)\) that is:

    $$\widehat{\psi }\left( f \right) = \mathop \int \limits_{ - \infty }^{\infty } \psi \left( t \right)e^{ - j2\pi ft} dt$$
    (3)

    then the following condition must hold:

    $$C_{g} = \mathop \int \limits_{0}^{\infty } \frac{{\left| {\widehat{\psi }\left( f \right)} \right|^{2} }}{f} df < \infty$$
    (4)

This means that the wavelet has no zero frequency component i.e. \(\widehat{\uppsi }\left( 0 \right) = 0\) or the wavelet \({\uppsi }\left( {\text{t}} \right)\) has a zero mean. This implies also that the wavelet’s frequency response is a band-pass filter.

3.1 Wavelet Selection

The Mexican hat wavelet is selected as an analyzing wavelet for several reasons:

  • Its impulse response (see Fig. 2) resembles the shape of the QRS complex and therefore it is likely to output a high peak when convoluted with a real heartbeat.

    Fig. 2
    figure 2

    Impulse response of the Mexican-Hat wavelet (scale a = 1)

  • Its frequency response (see Fig. 3) is a band-pass filter, which reduces the low frequency noise such as the baseline wander as well as the high frequency noise namely the electromyography.

    Fig. 3
    figure 3

    Frequency response of Mexican-Hat wavelet

  • Ease of variation of the scale \(a\) and therefore the variation of central frequency and cutoff frequencies of the band-pass filter.

The equation of the Mexican hat wavelet is:

$$\psi \left( t \right) = \left( {1 - t^{2} } \right)*e^{{ - \frac{{t^{2} }}{2}}}$$
(5)

The corresponding frequency characteristic of that wavelet is represented in Fig. 3.

The relation between central frequency fc and scale \(a\) is:

$$f_{c} = \frac{{\sqrt {\frac{5}{2}} }}{2\pi a}$$
(6)

The wavelet convoluted with the ECG signal outputs a signal with singularities (peaks) that correspond to the position of the QRS complex. These singularities are called Modulus Maxima (MM) (see Fig. 5a) and are defined as follows [26]:

$$\frac{{d\left( {\left| {T\left( {a,b} \right)} \right|} \right)^{2} }}{db} = 0$$
(7)

3.2 Scale Selection

All heart beat detection algorithms adopt band-pass filtering to get rid of undesired high frequencies as the electromyography and low frequencies of baseline wandering [27]. But the frequency range suited to the application differs from one algorithm to another. In order to determine the best scale of the Mexican- hat wavelet i.e. the best frequency band, a set of clean ECG signals from the MIT database was selected, to which motion artifact noise was added with a signal to noise ratio (SNR) equal to 6 dB (see Fig. 5) using the noise stress test function (NST) of the WFDB toolbox available on the physionet website [28]. All these signals were convolved with wavelets of frequency response that have central frequencies ranging from 10 Hz to 40 Hz as shown in Fig. 4. For each scale, the average Modulus Maxima value of all real heartbeats was computed using the beat annotation of MIT database records. Besides, peaks that do not correspond to real heart beats (potential false positive beats) with a Modulus Maxima value greater than half of the average value previously computed are counted for each scale. This operation was performed for the records 100, 103, 107, 112, 113, 115, 117, 118 and 119.

Fig. 4
figure 4

Number of peaks having a Modulus Maxima greater than half of the average Modulus Maxima of real beats for several MIT database ECG records

Figure 4 shows that the number of Modulus Maxima that correspond to motion artifact noise decreases gradually for all the ECG records starting from 10 Hz till reaching around 30 Hz. It stabilizes for some records and starts to increase again for others starting from 32 Hz. This means that for all the records, the number of Modulus Maxima that are likely to be considered as false positive beats is minimal for a scale corresponding to the central frequency 32 Hz. For this reason, and so as to avoid the high frequencies of electromyography noise (having a frequency range of 35–40 Hz) the wavelet whose central frequency of the corresponding band-pass filter frequency characteristic is 32 Hz (i.e. scale a = 0.0079) has been chosen as an analyzing wavelet for this algorithm. This scale reduces most the effect of motion artifacts by reducing the value of the corresponding Modulus Maxima.

3.3 Adaptive Threshold

After computing the CWT signal for the chosen scale, a threshold value is set depending on the Modulus Maxima value. The value of the threshold adaptively varies across time, after a new peak is detected, following this equation:

$$New\_ th = \frac{Old\_Th + \sum \;Modulus \;Maxima\; of\; 2\; previous\; peaks}{4}$$
(8)

As a result the threshold adapts to the variations of the Modulus maxima values (Fig. 5)

Fig. 5
figure 5

a portion of record 100 of the MIT-database without any added motion artifact noise. b Same portion with motion artifact added with SNR=6 dB. c CWT of the portion (b) with the adaptive threshold

3.4 Search Back Property

As in Pan and Tompkins’ algorithm [21], the search-back property is adopted for this algorithm. In fact, if there is no peak detected with MM greater than the current threshold within a time period of 1.66 × (previous RR interval), then the threshold value is divided by 2 and search-back operation is performed for another peak value. This technique enables to avoid missing beats with low modulus Maxima especially with the high adaptive threshold value that has been adopted.

4 Results and Discussion

To compare the results achieved by our developed algorithm to other algorithms in the literature the standard MIT database [29] was chosen as a reference database. The MIT database contains 48 half-hour ambulatory ECG recordings, obtained from 47 subjects studied by the BIH Arrhythmia Laboratory between 1975 and 1979. It is the most commonly used database in the literature. To evaluate the performance of the algorithm, Sensitivity Se and positive predictivity P+ are computed using (9) and (10), respectively:

$$S_{e} = \frac{TP}{TP + FN}\%$$
(9)
$$P^{ + } = \frac{TP}{TP + FP}\%$$
(10)

Here, TP (true positive), FN (false negative) and FP (false positive) represent the number of correctly detected QRS complexes, the number of missed detections and the number of extra-detections, respectively.

As a first step, the algorithm was tested across the 48 records without motion artifact noise being added and the results are shown in Table 1 and its performance was benchmarked with state of the art algorithms Table 2

Table 1 Performance of the algorithm against MIT database
Table 2 Benchmarking the results of the algorithm with state of the art algorithms on the MIT database

As a second step and in order to test the performance of the algorithm against various levels of motion artifact, and benchmark it with the state of the art algorithms, the same clean ECG records of the MIT database selected in Fig. 4 were used. Using the NST function, motion artifact noise was added to each of these records by an SNR respectively of 24, 18, 12, 06 and 0 dB. Figure 5 shows a portion of clean ECG signal of record 100 and the same portion when motion artifact of SNR 6 dB was added. The results of the noise stress test for record 100 are plotted in Fig. 6. It can be seen that this algorithm performs better than the other algorithms both in sensitivity and positive predictivity. In fact the sensitivity remains close to 100% even for SNR= 0 dB. As for the positive predictivity it is clear that the performance decreases slowly as the noise level increases from 24 to 6 dB and then decreases drastically beyond this value to reach 90% for SNR = 0 dB, but it still performs much better than Romero’s and Pan and Tompkins’s algorithms that reach 80 and 75% respectively for the same SNR value.

Fig. 6
figure 6

results of the noise stress test. a Sensitivity of noise stress test of record 100. b Positive predictivity of noise stress test of record 100

The results of the noise stress test for the records 123, 202, 212, 213, 219, 220, 221,230,231,232 and 234 are presented in Table 3.

Table 3 Results of the noise stress test of this algorithm compared to state of the art algorithms

5 Conclusion

We developed a single scale Continuous Wavelet Transform based algorithm, designed to adapt to ECG beat detection in portable conditions where the motion artifacts dominates. Such a choice was made to achieve the best compromise between low power consumption for long battery lifetime and high accuracy for the reliability of the portable system. It gave reasonable results when being tested at reasonable SNR levels (24, 18 and 12 dB). However, when the noise level is excessively high (0 dB) the results are not reliable and another solution should be sought.

Furthermore, as a future step, this algorithm should be implemented in a DSP in order to measure its power consumption and benchmark it with existing devices.