1 Introduction

The electrocardiogram (ECG) acquisition is often accompanied by high-frequency electromyographic (EMG) noise. It makes impossible the automatic localization of ECG waves and obstructs the visual analysis. The noise is difficult to be filtered, due to considerable overlapping of its frequency spectrum to the frequency spectrum of the ECG. EMG noise is picked up by the same electrodes as the ECG. EMG noise in resting ECG is quite common in subjects with uncontrollable tremor, in disabled persons having to exert effort in maintaining a position of their extremities or a body posture, in children, etc. [8]. The EMG noise is characterized by a frequency range from 5 to 70 Hz or even 100 Hz and by an amplitude of 100s of microvolts. Setting the low-pass filter of the ECG to a lower cutoff level eliminates not only the muscle noise but also the clinically significant high-frequency components of the signals inside the QRS complex [4, 7], J-waves [12] and pacemaker spikes [7]. For that reason, the American Heart Association (AHA) changed its low-pass filter recommendations from 35 Hz cutoff in 1967 [16] to 150 Hz for adolescents and adults and to 250 Hz for children in 2007 [10]. In the clinical practice, little attention tends to be paid to the filter setting of the ECG instruments, resulting in inappropriate filter application. In fact, Kligfield and Okin [11] found that the low-pass filter setting was 100 Hz and above in 25% of the ECG devices and <100 Hz (most commonly 40 Hz) in 75% of the ECG devices obtained within an American medical community.

The tendency of maximal preservation of the QRS high-frequency components and filtering with a cutoff of >150 Hz leads to a high level of residual noise. The presence of EMG noise could cause serious problems to the analysis of the signal out of QRS and will worsen the detection of ischemia (in the ST-interval), atrial fibrillation and flutter (in the PQ-interval), presence of T-wave alternans, etc.

The conflicting requirements for a strong suppression of EMG noise, and at the same time for a maximal preservation of the ECG high-frequency components, prompted us to create a dynamic procedure—strong filtration in the low-frequency components of the ECG and mild filtration in the high-frequency ones. A so-called wings function criterion for evaluation of the frequency bands of the ECG elements was created [3], which allowed a dynamic application with different filtering rate of the approximation procedure of Savitzky and Golay [13].

We also used an EMG denoising by hybrid application of transform-domain method outside the QRS and approximation methods in the QRS [8]. The disadvantage of the method is the significant consumption of time and computing resources of the transform-domain procedure.

Another attempt for a dynamic application of the approximation procedure was done by analysis of the difference between the original ECG signal and the filtered one (residual noise), inside and outside the QRS [1].

Sayyad and Mundada [14] are using extended Kalman filter and extended Kalman smoother. Priority is given to the smoother, but in both methods a great signal distortion can be observed in the QRS.

Dotsinsky and Mihov [5] are filtering the noise in three steps. (1) Moving averaging with first zero set at 50 Hz to suppress tremor and power-line interference simultaneously. (2) The reduced peaks of QRS complexes are restored by a procedure called linearly angular. (3) Finally, a Savitzky–Golay smoothing filter is applied for supplementary tremor suppression outside the QRS complexes.

Joy and Manimegalai [9] are using wavelet transform to remove the EMG noise. The proposed method selects the best suitable wavelet function based at the 5th decomposition level. The authors claim that the method retains the distinctive features of the ECG.

Myriad filters are known to perform well with Gaussian and impulsive noise. Tulyakova [17] is showing good results with locally adaptive, low-pass Myriad filters for ECG processing.

2 ECG and EMG databases

The method tested on our digital ECG database of patients with renal disease [15], The ECGs (1-min duration, 12 standard leads, 500 Hz sampling rate) were recorded before and 3 min after a hemodialysis session.

EMG noise was obtained from two ECG electrodes placed on one forearm. ECG amplifier was used and the recordings (400 Hz sampling rate) were made during sustained voluntary effort. Both ECGs and EMGs signals were resampled to 1000 Hz. The artifacts were weighted and additively mixed with the different ECG signals subjected to processing.

Noise-free ECGs were obtained from the CTS ECG Test Atlas [6]. It contains artificially simulated ECG-like signals of different shapes. The so-called analytical ECGs are with shapes very close to the biological shapes, with QRS morphology like in real normal ECG.

The CTS Atlas is also containing different noise samples: 50 Hz (60 Hz) power-line interference, baseline noise and high-frequency noise. The HF noise is “white” noise with Gaussian amplitude distribution of 25 µV RMS.

3 Method

We propose a low-pass filter in ECG, self-adjustable to the frequency bands of the ECG waves. The EMG denoising is based on the work of Christov and Daskalov [3] (described also in Bortolan et al. [2]), with some sufficient improvements in the current suggestion of the dynamic filtering, such as:

  • simplified procedure for evaluation of the frequency bands of the ECG waves;

  • better suppression of the EMG noise;

  • automatic on/off triggering of the filter depending on the presence/absence of EMG noise;

  • pseudo-real-time (real-time with a certain delay) implementation of the filter;

  • compliance with the new low-pass filter’s recommendations for cutoff [11].

The filter is continuously operating sample-by-sample in a pseudo-real-time mode. The computational cost depends on the sampling frequency. Block diagram of the method is shown in Fig. 1.

Fig. 1
figure 1

Block diagram of the method. a Evaluation of the frequency spectra of ECG waves, b automatic on/off triggering of the filter, c actual filtering of the ECG signal

3.1 Approximation procedure

A smoothing procedure adopted from the work of Savitzky and Golay [13] is applied. It makes use of the least squares approximation method, applied for defining the weighting coefficients. The mathematical description of the process is:

$$ Y_{i} = \frac{1}{N}\sum\limits_{j = - n}^{j = n} {C_{j} X_{i + j} } $$
(1)

Y and X represent the signal after and before approximation, respectively, n is the length of the approximation interval at both sides of a sample. C is weighted approximation coefficients, and N is a normalization coefficient. The procedure is applied on 2n + 1 samples. The approximation coefficients are

$$ C_{j} = 3n^{2} + 3n - 1 - 5j^{2} , $$
(2)

and the normalization coefficient is

$$ N = \frac{{(2n + 1)\left( {4n^{2} + 4n - 3} \right)}}{3} $$
(3)

3.2 Evaluation of the frequency spectra of ECG waves

Evaluation of the frequency spectra of the ECG waves is done by blocks 1–5 of the block diagram of Fig. 1 and is demonstrated in Fig. 2.

Fig. 2
figure 2

Frequency response of ECG waves. a ECG, b filtered ECG, c “wings” function, d transfer the “wings” into “n,” used to define the dynamic window of the Savitzky–Golay filter

The raw ECG (subplot 1 of Fig. 2) is first filtered by Savitzky–Golay (SGF) in a fixed window of 60 ms (block 1 of Fig. 1).

Then, a first-difference filter (FDF—block 2 of Fig. 1) with transfer function of

$$ T_{\text{FDF}} (z) = \frac{{1 - z^{m} }}{2} $$
(4)

is applied. The FDF is a comb filter with first notch frequency f = 1/(mT S). We selected m to be

$$ m = \frac{{2T_{\text{PL}} }}{{T_{\text{S}} }}, $$
(5)

where T PL is a power-line period, and T S is the sampling interval. The FDF high-pass 3-dB frequency is set at about 6 Hz, and the higher-frequency notches reject all harmonics of power-line interference.

SGF and FDF filters are intended to filter EMG noise, power-line interference and baseline drift. The goal is a complete suppression of the noises, no matter of the QRS distortion and amplitude reduction, as shown in subplot 2 of Fig. 2.

The cutoff frequency of SGF for a window of 60 ms is F c = 17 Hz. By a window of 40 ms (difference between two samples, 40 ms apart), FDF is tuned to pass at the same frequency bandwidth 6–18 Hz.

Power-line period instability [see Eq. (5)] would slightly worsen the FDF functionality, but with no effect to the final result, since the power-line interference is filtered twice: by SGF and by FDF.

A so-called wings function is found by multiplying the slopes of two adjacent segments of 10 ms length having a common point. The product absolute value is then taken and inverted (block 3 of Fig. 1). For a 1000 Hz sampling rate, the “wings” function is:

$$ {\text{Wings}} = W^{\prime } = {\text{abs}}\left( {\left( {S_{i} - S_{i - 10} } \right)\left( {S_{i} - S_{i + 10} } \right)} \right) $$
(6)

The segment length of 10 ms was chosen in order to obtain a certain level of signal smoothing in the process of frequency response evaluation. We have found that this value is not particularly critical, as smaller interval results in more varying “wings” function and thus stronger additional smoothing is needed, and vice versa [3]. Sliding this function along the signal, it reflects the variations of the angle between the two segments. The movement of the segments resembles the wings of a butterfly, hence the name “wings.”

Well-shaped negative peaks of W′ correspond to every Q, R and S wave of the ECG. Negative peaks appear also at the maximum slew rate of QR and RS segments. This is demonstrated in Fig. 2c, where the “wings” function is shown as a thin line.

W′ is further smoothed by two-pass moving averaging with a window of 50 ms (block 4 of Fig. 1). The “two-pass” is performed twice in the same forward direction. The result is a negative wave (shown with a thick line in Fig. 2c) that responds to the wave frequency of the ECG.

Block 5 of Fig. 1 transfers the particular values of the “wings” function to a number of samples (n, Fig. 2d), defining the window length over which the final Savitzky–Golay filter (block 11) will be applied. If W is the smoothed “wings” and W max, W min its maximum and minimum values, the transfer formula to n, varying from n min to n max, is:

$$ n = n_{\hbox{min} } + \left( {n_{\hbox{max} } - n_{\hbox{min} } } \right)\frac{{W - W_{\hbox{min} } }}{{W_{\hbox{max} } - W_{\hbox{min} } }} $$
(7)

The values n min = l–n max = 32 were chosen after careful testing of multitude of ECG signals from different databanks.

The filtering is done by applying two-pass Savitzky–Golay (block 11 of Fig. 1) with a dynamic change in its smoothing window at every sample, as defined by “n.” The maximal filtering window (n max = 32) of the two-pass filter has been chosen to be consistent with the −3 dB cutoff.

3.3 Automatic on/off triggering of the filter

The EMG noise is not consistently present in the ECG signal. It may be absent entirely or be intermittent with different magnitude of the noise. For that reason, an automatic on/off triggering of the filter is an essential option. As far as we know, this is the first such attempt.

The ECG is filtered initially by Savitzky–Golay in a fixed window of 60 ms (block 1 of Fig. 1). This would suppresses the high-frequency EMG noise, if it accompanies the ECG. Next few steps are to assess the presence/absence of noise: The raw ECG and the filtered one are subtracted (block 6 of Fig. 1), S = sum of all absolute values in a window of 50 ms is calculated (block 7 of Fig. 1), and then, S is compared to a threshold value (block 8 of Fig. 1). The result of this comparison controls the on/off triggering of the filter (block 10 of Fig. 1). In order to avoid frequent switching, the turning-on is done after consecutive groups of noise indications in a period of 50 ms. In opposite, the turning-off is performed after consecutive noise-free indications in 100 ms. The turning-off condition is made more difficult because the ECG is usually accompanied by small EMG noise.

The above sequence would not work properly because the result of subtracting ECG − ECGfiltered is strongly influenced by the filtering of the high-frequency QRS components of the signal (Fig. 3). Therefore, on/off triggering decision is made outside QRS, the indication of which is given by the decrease in “n” with more than n max − 5 (block 9 of Fig. 1).

Fig. 3
figure 3

a Raw ECG, b filtered ECG, c ECGraw − ECGfiltered

3.4 Pseudo-real-time implementation

The filter is using the time-linear smoothing procedure of Savitzky–Golay, so taking into account the maximal of n = 32 ms on both sides of the approximation window, and the two-pass implementation of Savitzky–Golay, it can work online with a delay of 2 × 32 = 64 ms (pseudo-real-time implementation). However, since the signal n is delayed of 110 ms (30 ms by block 1, 20 ms by block 2, 10 ms by block 3 and 50 ms by block 4) with respect to the input signal, the minimal overall delay of the proposed filter is 110 ms. Because of the on/off triggering, the “off” (no filtering) branch of the algorithm must be delayed (block 12 of Fig. 1), to equalize the active filtering branch.

4 Results

4.1 Noise suppression

The EMG noise suppression is demonstrated in Fig. 4. ECG with superimposed EMG noise with maximal value of around 0.1 mV is shown in the first subplot. The second subplot is a noise-free ECG as a result of the filtering procedure. It can be seen that the processed ECG has diagnostic capabilities even in the low-frequency zones such as P-waves, ST-segments and T-waves. The difference between subplot 1 and subplot 2 (shown in subplot 3) is representing the EMG noise that has been suppressed. As a result of the filtering, Fig. 4c contains not only the suppressed EMG but also ECG distortions. They are dozens of times less than the suppressed EMG noise, invisible to a naked eye and will be subject of attention later on.

Fig. 4
figure 4

Noise suppression. a Noisy ECG, b filtered ECG, c suppressed EMG noise (first − second subplots)

Another example of EMG noise suppression is demonstrated in Fig. 5, where the first plot is real EMG, and the second plot is the filtered EMG.

Fig. 5
figure 5

Noise suppression. a Real EMG noise recorded during sustained muscle effort, b filtered EMG

4.2 Signal distortion

A noise-free ECG obtained from the CTS ECG Test Atlas [6] is shown in the first subplot of Fig. 6. The processed ECG is shown in the second subplot. No distortions can be seen with naked eyes. However, at the enlarged scale of the third subplot, which presents the difference between the raw ECG and the processed one, distortion of around 0.06 mV, manifested as decrease in the QRS amplitude, can be observed. This decrease in QRS is equal to around 6% of its amplitude. The root-mean-square (rms) error of distortion shown in Fig. 6c) is: RMS = 7.7 µV.

Fig. 6
figure 6

Signal distortion. a Noise-free ECG, file ANE20000.IEC of the CTS ECG Test Atlas, b processed ECG, c signal distortion ECG − ECGprocessed

4.3 Quantitative assessment of the filtering efficiency

The filtering efficiency is quantitatively evaluated using conditionally clean ECG signals and typical disturbances to calculate the level of noise suppression L by the initial disturbance n ini mixed with the clean ECG signal and the residual disturbance n res after filtering the contaminated signal.

$$ L = \frac{{n_{\text{ini}} }}{{n_{\text{res}} }} $$
(8)

Noise suppression is computed from rms values.

The quantitative assessment of the filtering efficiency was performed using the noise presented in Fig. 5, mixed with the noise-free ECG of Fig. 6.

Two values for noise suppression are calculated because of the non-homogeneous (dynamic) procedure: strong filtration of the low-frequency components of the ECG as P-wave, PQ-interval, ST-interval, T-wave and TP-interval, and mild filtration of the high-frequency QRS components.

$$ L_{\text{inQRS}} = 3.3\,{\text{dB}}\quad L_{\text{outQRS}} = 9.3\,{\text{dB}} $$
(9)

4.4 On/off triggering

The distortion shown in Fig. 6 is theoretical and will not be obtained in practice, due to switching-off of the filtering procedure in case of noise-free ECG. The block diagram and the on/off triggering algorithm were discussed in the previous chapter. The triggering is demonstrated in Fig. 7. The first subplot is an ECG accompanied with bursts of EMG noise of different amplitudes in 1.0–4.0, 8.0–12.0 and 14.0–18.2 s. The lower trace in subplot 1 is for the check n > n max − 5 (block 9 of Fig. 1). It is a peculiar indication of the occurrence of natural high-frequency signal as QRS and prevents erroneous decision for the presence of EMG noise and corresponding switching-on of the filter. The dashed line in subplot 1 indicates the on/off triggering.

Fig. 7
figure 7

On/off triggering. a Upper trace—ECG with bursts of noise, lower trace—indication of the occurrence of HF signal as QRS, dashed trace—on/off switching of the filter, b processed signal

The combined effect of filtering in case of noise, and no filtering in case of noise-free ECG, is shown in subplot 2 of Fig. 7.

5 Discussion

5.1 Recommendations of the AHA standards

In introduction, it was mentioned that the old (1967) recommendations for a low-pass filter of the AHA was 35 Hz cutoff [16], while the new (2007) recommendations are 150 Hz for adolescents and adults, and 250 Hz for children [10]. The effect of the filtering with cutoffs of 35, 150 and 250 Hz is shown in Fig. 8. No suppression of EMG noise can be observed with cutoffs of 150 and 250 Hz; however, there is no signal distortion in the HF band of the ECG (the QRS). Certain suppressions of the EMG can be seen with a cutoff of 35 Hz. At the same time, there is a distortion, manifested as reduction in the QRS amplitude from 0.86 mV in the original to 0.81 mV (a reduction of 5.8%), in the filtered ECG.

Fig. 8
figure 8

Recommendations of the AHA standards. a Original ECG with EMG noise, bd filtered signal with a cutoffs of, respectively: 35, 150 and 250 Hz

5.2 Frequency response of the suggested filter

The frequency response of the suggested filter is shown in Fig. 9. An ECG with specially selected high-amplitude T-waves is shown in subplot a). “Wings” function has been applied. The number of samples “n” defining the dynamic window of the Savitzky–Golay filter is shown in subplot b). Instantaneous cutoff frequency of the filter, as a result of the corresponding length of the filtering window, is shown in subplot c). It can be seen that the low-frequency components of the specific ECG is filtered with a cutoff of 14 Hz, the high-amplitude T-wave is filtered with 26 Hz, and the high-frequency QRS from 100 to 415 Hz.

Fig. 9
figure 9

Frequency response of the suggested filter. a ECG, b number of samples “n,” defining the dynamic window of the Savitzky–Golay filter, c instantaneous cutoff frequency of the suggested filter

5.3 Comparison of the proposed method with other published methods

Good results in EMG noise filtration can be obtained only by a dynamic procedure. Several attempts have been made during the years (Table 1). There are several reasons why some of the methods cannot be implemented in real time: filtration complexity [8], additional procedure after filtration [5] and need for preliminary location of QRS-onset and QRS-offset [1, 5] The currently suggested method is the only one of those mentioned in Table 1, which can trigger on/off, in dependence of noise presence/absence.

Table 1 Comparison of several methods for dynamic filtration of high-frequency noise in ECG

6 Conclusions

The conflicting requirements for a strong suppression of EMG noise, and at the same time a maximal preservation of the ECG high-frequency components, prompted us to create a dynamic procedure, self-adjustable to the frequency spectra of the waves.

The low-frequency components of the ECG as P-wave, PQ-interval, ST-interval, T-wave and TP-interval are strongly filtered with a cutoff of 14–40 Hz, while the high-frequency QRSs are mildly filtered with 100–500 Hz.

The wide preservation of the signal morphology improves the diagnostic capabilities of the ECG in the presence of EMG noise in both high- and low-frequency range. In case of noise-free ECG, the filter is automatically switched off.