Introduction. Registration and processing of electrocardiogram (ECG) signals is widely used in various systems of medical diagnostics. The active development of systems for monitoring the state of the body based on the analysis of heart rate variability makes it necessary to accurately detect ECG QRS-complexes to minimize the errors in measuring the duration of the cardiac cycle under the influence of interference and noises of various origins [1, 2]. The QRS-complex of the ECG is the most high-frequency and high-amplitude fragment of the electrocardiogram, reflecting the processes of bioelectric excitation of the ventricles of the heart. The highest-amplitude component of the QRS-complex is the R-wave, with its help the heart rate is measured. R-wave detection is the main stage of automated ECG signal processing [2].

There are many different algorithms for detecting the ECG R-waves using the first and second derivatives, frequency filtering, wavelet transforms, matched filters, syntactic methods and neural networks, as well as various combinations of algorithms [3,4,5,6,7,8,9,10,11].

The purpose of the study is to develop an effective method for detecting ECG R-waves, which consists of the following sequential stages of digital processing of the ECG signal: wavelet multiresolution decomposition; selection of nonlinear operators; adaptive detection algorithm.

Materials and methods of research. Signal decomposition based on multiscale discrete wavelet transforms is a decomposition of the original signal into a sequence of approximating and detailing coefficients [7]. The key parameters of the wavelet decomposition are the type of the wavelet function and the number of decomposition levels. Numerous studies show that in problems of ECG signal processing the most effective results are achieved using the 4th order of Daubechies wavelets (db4) [7, 12].

To determine the optimal parameters of the ECG signal wavelet decomposition in the problems of R-wave detection, consider the mathematical model of the ECG signal with additive noise and interference. To obtain model dependences of the ECG signal, we use the simulation model proposed in [13]. This simulation model makes it possible to form biosignal fragments with the required morphology and specified values of the amplitude-time parameters.

The creation of mathematical models of distorting influences is based on a priori information about the nature of the arising interference or noise. Distorting effects during ECG signal registration are mainly caused by electrical interference caused by the influence of power supply networks, noise of the analogue path for recording a biosignal, fluctuations in the polarization potentials of electrodes, as well as physiological artifacts caused by respiration, movements of the examined person and spontaneous myographic activity of peripheral muscles [1, 3].

The mathematical model describing the influence L of external electromagnetic fields of power supply networks has the form

$$ L(k)={L}_{\mathrm{max}}\sin \left(2\uppi {f}_pk/{f}_s\right), $$

where Lmax is the amplitude of the interference caused by the influence of the power supply network; fp is the frequency of the power supply network; fs is the sampling frequency of the interference signal; k is the ordinal number of the signal sample.

Interference caused by human breathing and displacement of electrodes during involuntary movements lead to distortion of the isoline and shape of the ECG signal and the emergence of isoline drift – a quasi-periodic signal of a stochastic nature, the main frequency band of which is located below the average heart rate [1, 3].

The analysis of the factors that influence the appearance of the ECG signal isoline drift, carried out by the author of this article, showed that the ECG signal isoline drift W(k) can be expressed as a sum of deterministic and random components:

$$ W(k)={W}_{\mathrm{max}}\left(\sum_{i=1}^4\sin \left(2\uppi {f}_ik/{f}_s\right)+\uppsi (k)\right), $$

where Wmax is the amplitude of the model isoline drift signal; fi is an array of frequencies of an additive set of harmonic signals representing a deterministic component ψ(k) – a random component obtained by filtering white Gaussian noise with a lowpass filter with a cutoff frequency of 1 Hz.

The ECG signal isoline drift was simulated at frequencies f1 = 0.1 Hz, f2 = 0.2 Hz, f3 = 0.4 Hz, f4 = 0.8 Hz.

Interference from the peripheral muscles located in the projection of the electrodes is a random signal of a broadband nature. The mathematical description of myographic activity is presented as a normal process with zero mean and variance \( {\upsigma}_1^2 \) [3]. The additive component of noise with a normal distribution also simulates the influence of the internal noise of the ECG signal registration unit and the random nature of the appearance of motion artifacts.

To select the optimal level of decomposition and the type of wavelet decomposition coefficients when detecting R-waves of the pacemaker, in this work, the correlation coefficient was determined between the model pacemaker containing only QRS-complexes and the sequence of the wavelet decomposition coefficients of the model pacemaker.

Based on research carried out by the author, a technique for detecting the R-waves of the pacemaker is proposed, which sequentially includes: multiscale wavelet transform of the initial ECG signal for six levels of decomposition; formation of the sum of the detailing coefficients of the fourth and fifth levels; replacing negative counts of the received signal with zeros; squaring the result.

After passing through the preliminary stages of processing, the ECG signal entered the input of the adaptive circuit for detecting signal maxima, the temporal position of which corresponds to the position of the R-wave.

The essence of the adaptive maximum detection algorithm is in the formation of a sliding window with a duration of 2 s and the search for maximums exceeding a given threshold value Lev within that window. The threshold was determined separately for each sliding window based on the following threshold function:

$$ Lev(i)=\left\{\begin{array}{l}0.4\max (i),\kern0.75em \upsigma (i)\ge 0.2\max (i)\&\max (i)<\max \left(i-1\right);\\ {}0.4\max \left(i-1\right),\kern0.75em \upsigma (i)\ge 0.2\max (i)\&\max (i)\ge \max \left(i-1\right);\\ {}1.6\upsigma (i),\kern0.75em \upsigma (i)<0.2\max (i),\end{array}\right. $$

where σ(i) is the standard deviation of the signal readout amplitude values within the ith sliding window; max(i), max(i – 1) are the maximum values of the signal sample amplitudes within the current ith and previous sliding windows, respectively; & denotes the simultaneous fulfillment of the specified conditions.

Numerical values of the threshold function parameters were chosen empirically as a result of the studies carried out according to the criterion of maximizing the correct detections of ECG signal R-waves and minimizing false detections and gaps.

The detector maximum determined the temporal position of the signal maximum in the search time interval while the following conditions were simultaneously observed:

$$ A(n):= Peak,\kern0.75em \mathrm{if}\ A(n)> Lev\&A(n)>A\left(n+1\right)\&A(n)>A\left(n-1\right), $$

where A is the input signal of the adaptive maximum detection scheme (the resulting signal from the 4th stage of ECG signal preprocessing); := means “assign,” that is, if the conditions specified after the “if” are met, the count A(n) is recognized as the peak or maximum of the Peak signal in the time interval of the search.

The detection of the temporal position of the ECG signal R-waves occurred with some error due to signal distortions due to interference and noise. One of the criteria for evaluating the efficiency of the detector was the random error in measuring the duration of the RR-interval.

To estimate the absolute error ΔRR for measuring the duration of the RR-interval, we used the quantile characteristics of errors at a confidence level P = 0.9 [14]:

$$ {\Delta }_{RR}=1.6{\upsigma}_{RR};\kern0.5em {\upsigma}_{RR}=\sqrt{\sum_{i=1}^N{\left[R{R}^{\prime (i)}- RR(i)\right]}^2/N}, $$

where σRR is the root-mean-square deviation of the duration of RR-intervals from the true value; RR(i), RR′(i) represent the true and measured duration of the RR-interval, respectively; N is the total number of RR-intervals in the considered fragment of the ECG.

As a criterion for evaluating the effectiveness of the proposed method for detecting R-waves and existing approaches, we chose the absolute error in measuring the duration of RR-intervals in a wide range of changes in the signal-to-noise ratio:

$$ S/N=10\log \left({S}_{\mathrm{max}}/{X}_{\mathrm{max}}\right), $$

where Smax, Xmax are the total spectral powers of the model ECG signal and the additive signal of the present interference and distortions, respectively.

To verify the developed detector when processing real biosignals, the publicly available ECG signal database from the Massachusetts Institute of Technology was used [PhysioNet. The Research Resource for Complex Physiologic Signals, http://physionet.org]. To assess the efficiency of detecting R-waves, the probability PT of correct detection of control points, the probability PF of false detection of control points, and the indicator Per of the detection error level were used:

$$ {\displaystyle \begin{array}{ccc}{P}_T=\left({N}_T/N\right)\bullet 100;& {P}_F=\left({N}_F/N\right)\bullet 100;& {P}_{er}=\left[\left({N}_m/{N}_F\right)/N\right]\bullet 100,\end{array}} $$

where N is the total number of R-waves; NT, NF, Nm are the number of correctly detected, mistakenly detected and missed R-waves, respectively.

In testing, we used ECG samples from the MIT-BIH Arrhythmia Database, containing 48 fragments of real ECGs, each 30 min long; one weakly noisy sample (No. 100) and two most noisy fragments (samples Nos. 104, 105) were selected for the study [15].

Research results. The research results were obtained in the MATLAB R2013a system of applied computing using the standard functions of the Signal Processing Toolbox.

Figures 1 and 2 show the dependences of the change in the approximating and detailing coefficients of the wavelet decomposition on time for a noisy model ECG signal, respectively.

Fig. 1
figure 1

Approximating coefficients kа of decomposition levels of a noisy ECG (curves 16 correspond to decomposition levels 16).

Fig. 2
figure 2

Detailing coefficients kd of decomposition levels of a noisy ECG (curves 16 correspond to decomposition levels 16).

The obtained results of decomposition of the model ECG show that high levels of detailing expansion coefficients (see Figs. 1, 2, curves 36) are free of high-frequency noise and isoline drift, approximating expansion coefficients contain a significant level of isoline drift and at high levels of decomposition (see Figs. 1, 2, curves 5, 6) QRS-complexes of the ECG become indistinguishable.

Table 1 shows the results of calculating the correlation coefficient between the model ECG containing only QRS-complexes and a sequence of detailing (DC) and approximating (AC) coefficients from the first to sixth levels of wavelet decomposition (WDL).

Table 1 Correlation Coefficients between the Model ECG and the Wavelet Expansion Coefficients

The sum of the detailing coefficients of the fourth and fifth levels of signal decomposition has the greatest correlation with the model ECG signal containing only QRS-complexes. Therefore, this sum of coefficients is preferable for further processing in order to detect the ECG R-waves.

Figure 3 shows the diagrams of processing a model ECG signal with the presence of motion artifacts, baseline drift and broadband noise based on the developed approach, where AECS is the amplitude of the initial ECG signal; kd(4+5) is the sum of the detailing coefficients of the fourth and fifth levels of signal decomposition; Sin is the input signal for the detection scheme, obtained by replacing the negative counts of the coefficients of the fourth and fifth levels of signal decomposition with zeros and then squaring the obtained value. The results show that preliminary processing of a noisy ECG signal allows to effectively suppress the present noise and interference and provides reliable detection of ECG R-waves.

Fig. 3
figure 3

Diagrams of processing of a noisy model ECG signal; for Sin, detected R-waves of the ECG signal (+) and the adaptive threshold value (gray line) are shown.

Figure 4 shows the dependences of the absolute error in measuring the duration of the RR-intervals of the ECG signal on the signal-to-noise ratio S/N for various R-wave detectors. The dependences were obtained with the following model parameters: heart rate 60 beats/min; QRS-complex amplitude 1 arb. unit; QRS-complex duration 80 ms; fp = 50 Hz; fs = 500 Hz; parameters Lmax, Wmax, \( {\upsigma}_1^2 \) were set in accordance with the value of the signal-to-noise ratio S/N.

Fig. 4
figure 4

Dependences of the measurement error ΔRR of the RR-intervals duration on the signal-to-noise ratio S/N for various detectors of ECG R-waves: 1) the algorithm proposed in this work based on wavelet decomposition; 2) matched filter-based algorithm [9]; 3) Pan–Tompkins algorithm [8]; 4) neural network-based algorithm [6].

An analysis of the obtained dependences shows that with a decrease in the signal-to-noise ratio, the error in measuring the duration of the RR-intervals of the ECG signal increases; in low-noise conditions, all four considered algorithms demonstrate a similar level of error. However, high-noise conditions, the Pan–Tompkins algorithm and the algorithm based on matched filtering are characterized by the largest error values, and the algorithm based on neural networks provides the best accuracy. The algorithm proposed in this work is slightly inferior to the neural network algorithm.

Table 2 shows the results of a quantitative assessment of the effectiveness of the developed detector in comparison with existing approaches in processing real ECG signals, where algorithms 1–4 are, respectively, the proposed algorithm based on wavelet decomposition, a matched filter algorithm, a Pan–Tompkins algorithm and a neural network algorithm; S48 is the average value of the probabilities of detecting the ECG singla R-waves calculated for all 48 fragments of real ECGs from the database; the highest probability PT and the lowest probabilities PF and Per are highlighted in bold.

Table 2 Evaluation of the Probabilities (%) of Detecting ECG R-Waves for Samples Nos. 100, 104, 105 When Processed by Algorithms 1–4

Analysis of the results of the detection efficiency of R-waves in real ECGs shows that for a slightly noisy sample (No. 100), the detection efficiency of all methods, except for the Pan–Tompkins algorithm, is 100%. For ECGs with high interference and noise levels (samples Nos. 104 and 105), the best detection results are provided by the neural network method and the method based on wavelet decomposition proposed in this work. The detection efficiency and the level of errors of the proposed method are tenths of a percent inferior to the neural network method.

Conclusion. Analysis of the obtained results showed that the proposed method for detecting R-waves in an ECG signal by wavelet decomposition is an effective means of processing ECG data recorded in real clinical conditions. Based on the developed approach, it was possible to achieve 100% correct detection and complete absence of errors for a weakly noisy ECG signal sample with a duration of 30 minutes, as well as an error rate not exceeding 0.9% for noisy ECGs.

Simulation results showed that the developed detector based on wavelet decomposition provides smaller errors in measuring the duration of RR-intervals of the ECG in a wide range of changes in the signal-to-noise ratio in comparison with the classical approaches based on matched filtering and the Pan–Tompkins algorithm. In terms of accuracy, the proposed algorithm is comparable to a much more complex approach based on neural networks.

The advantages of the proposed method for detecting ECG R-waves include relative simplicity of implementation, sufficient performance for modern computing systems, small errors in measuring the duration of RR-intervals, high rates of true detection, small errors of false detection and omission. The proposed approach loses insignificantly in the detection accuracy and measurement errors of RR-intervals to the neural network detector; however, the latter method is much more complicated and time consuming and requires preliminary training of the neural network on significant experimental data to achieve high efficiency.