A MATHEMATICAL ALGORITHM FOR ECG SIGNAL DENOISING USING WINDOW ANALYSIS

BACKGROUND
The presence of parasite interference signals could cause serious problems in the registration of ECG signals and many works have been done to suppress electromyogram (EMG) artifacts noises and disturbances from electrocardiogram (ECG). Recently, new developed techniques based on global and local transforms have become popular such as wavelet shrinkage approaches (1995) and time-frequency dependent threshold (1998). Moreover, other techniques such as artificial neural networks (2003), energy thresholding and Gaussian kernels (2006) are used to improve previous works. This review summarizes windowed techniques of the concerned issue.


METHODS AND RESULTS
We conducted a mathematical method based on two sets of information, which are dominant scale of QRS complexes and their domain. The task is proposed by using a varying-length window that is moving over the whole signals. Both the high frequency (noise) and low frequency (base-line wandering) removal tasks are evaluated for manually corrupted ECG signals and are validated for actual recorded ECG signals.


CONCLUSIONS
Although, the simplicity of the method, fast implementation, and preservation of characteristics of ECG waves represent it as a suitable algorithm, there may be some difficulties due to pre-stage detection of QRS complexes and specification of algorithm's parameters for varying morphology cases.


INTRODUCTION
The presence of parasite interference signals could cause serious problems in the registration of ECG signals.Most common problems are power line interference, electromyogram (EMG) or myopotential signals, motion artifacts, and baseline (drift) interferences 1 .
In practice, wideband myopotentails from pectoral muscle contraction will cause a noisy overlay with the ECG signal.It can be presented as: In the above equation, the myopotential component of a signal corresponds to additive noise, thus obtaining the true ECG signal from noisy observations can be formulated as the problem of signal estimation or signal denoising 2 .
Fig. 1 shows two actual recorded ECG signals.One of them has very low rate noises, and the other consists of high rate noises.It is clear that the precise detection of onset and off set of its main waves in the noisy signal becomes very hard.Note that the sampling rate of the signals is 1 kHz (According to the PTB diagnosis ECG database for Physionet/Challenge 2006) While there are well-developed methods for power line, interference, and drift suppression, there are still problems in myopotential signal suppression due to the considerable overlapping of the frequency spectra of both types of signals.Thus, the automatic interpretation, following accurate detection of characteristic ECG points and waves such as P wave, T wave, QRS complex and the measurement of signal parameters become an extremely diffi cult, sometimes virtually impossible task 2 .
Generally, adequate ECG denoising algorithms and procedures should have the following properties 1 : a) Improve signal-to-noise ratio (SNR) for obtaining clean and readily observable recordings, yielding the subsequent use of straightforward approaches for accurate automatic detection of characteristic points in the ECG signal and recognition of its specifi c waves and complexes b) Preserve the original shape of the signal and especially the sharp Q, R, and S peaks, without distorting the P and T waves and the smooth transition of the ST-T segment.
Recently some new techniques based on global and local transforms have become popular in connection with signal denoising.At the fi rst step, the signal is decomposed into a transform domain where fi ltering procedures are applied.The noise-free signal is then obtained by an inverse transform.Choosing appropriate basis functions for successful decorrelation of the signal and designing transform domain fi lters accommodated to the ECG sig-nal morphology could turn these techniques into powerful means for ECG signal denoising 1 .
A method for ECG denoising has been proposed based on the wavelet shrinkage approach 3 using time-frequency dependent threshold (TFDT) (ref. 4).The TFDT is high for non-informative wavelet coeffi cients, and low for informative coeffi cients representing the important signal features.Although giving relatively good results in comparison with other ECG denoising methods, the latter has some disadvantages: Some oscillations may occur at the end of the QRS-complexes using long-length decomposition fi lters due to the poor time localization of the basis functions; and in the opposite direction very short-length fi lters may corrupt the shapes of the "slow" P and T waves 1 .
Using artifi cial neural networks (ANNs) for noise and baseline removal is also used in many articles; e.g., a neural network based adaptive algorithm for ECG denoising is presented in 5 .Furthermore, G.Cliff ord 6 presented a general technique using energy thresholding and Gaussian kernels for biomedical signal denoising and he showed that signifi cant noise reduction, compression, and turning point location is possible by this method.Also, there are many mathematically based algorithms using wavelet analysis to denoise ECGs and these can be found in many articles and papers.
Despite these mentioned algorithms, there are also problems in ECG denoising to preserve ECG morphology with a high degree of confi dence.In the present study, we aim to improve the denoising procedure by using a mathematical algorithm.
The paper is organized as follows.Section 2 is the main part of the paper.It starts with a discussion about the mathematical concepts of QRS dominant scale and R-wave detection (subsections 2-1 and 2-2 respectively).In the third part of this section, the mathematical concepts of the proposed denoising algorithm are clarifi ed in detail.The fi nal part explains the proposed baseline-wandering algorithm.Section 3 has three parts.In the beginning, it discusses about the effi ciency of this algorithm in denoising.In the second and third part of this section, the results of implementation of this algorithm are investigated in both a true ECG signal that is corrupted with additive noises manually and an actual recorded ECG signal respectively.

MATERIALS AND METHOD
The process of analyzing ECG signals with no prior information seems a lengthy process and needs advanced mathematical consideration.The prior information might consist of some special ECG characteristic points, HR, ECG waves bandwidth.In our algorithm, we use two extra sources of information, which are: i.The QRS complex dominant scale, a QRS , is determined.ii.Locations of R-waves in ECG signal are specifi ed.
In addition, we assume noises cannot be observed in QRS complexes due to the high energy of the QRS complex compared with the low energy of the corrupting noises.

2-1. Determination of QRS-complex dominant scale
The duration of each component of ECG signal can be expressed as a function of time interval and the corresponding dominant rescaled wavelet coeffi cients.The following dominant scale for QRS complex is derived as below and has been proposed in 8 : Where, D QRS is the QRS complex duration and T S is rescaled wavelet coeffi cients.
While the width of the R-wave is slightly larger than the width of Q and S waves, the dominant scale of QRS complex does not change noticeably from that of R-wave.Thus, it is practical to use the evaluated dominant scale of the QRS complex for R-wave in the rescaled wavelet map 9 .

2-2. R-Wave detection
Based on the algorithm proposed 9 in, in order to detect the R-wave vicinity, continuous wavelet transform of ECG signal is used.R-wave is more signifi cant at its dominant scale; therefore, it is suffi cient just to analyze the CWT of ECG signal at its R-wave dominant scale.The method is  Noisy ECG (b) A mathematical algorithm for ECG signal denoising using window analysis based on detection of high peaks primarily through which threshold search is used.

2-3. Method for denoising the ECG signal
It is possible to eliminate undesired high frequency components (noises) in the ECG signal using windowed analysis.By knowing the QRS complexes dominant scale and the position of every R-wave as mentioned before, a window is considered.The length of this window is defi ned as an integer function of QRS dominant scale, a QRS , and location of every detected R-wave.(Equation (3)).

(
) Where, α and β are constant parameters, P i is the sample index of i th detected R-wave, f is sample frequency, and x is the sample index, which varies through: 2 The formula defi nes window length thorough the ECG signal.The length of this window varies from 1 at the location of every detected R-wave and increases until it reaches its maximum value, α .a QRS , between two detected R-waves as is shown in Fig. 2.
To remove noises, denoising window slides through the noisy signal and the value of the signal at the center of the window is set to the mean value throughout the window.If an ECG signal is represented as a discrete function y(x), which x denotes sample index, then the consequent denoised signal, x y ) ( , at the x th sample index is obtained as follows: In this approach, the lowest value of window length, d i (x) = 1, which occurs in the location of every detected   Figs. 3-a and 3-b show the variation of window length related to changes in α and β.In Figure 3-a, the variation is depicted in which β is constant and equals to β = 0.02, and α gets three diff erent values, 0.2, 1.3, and 3.0 alternatively.In Figure 3-b, the variation is depicted in which α is constant and equals α = 1.3, and β gets three diff erent values, 0.002, 0.02, and 0.2 alternatively.It is assumed that detected R-waves are located at sample indexes 298, 1130, and 1950 respectively.A mathematical algorithm for ECG signal denoising using window analysis

2-4. Method for baseline wandering removal
Another problem in ECG signal denoising task is baseline wandering.In this regard, we follow a slightly similar method, so as to a window analysis is proposed to remove baseline wandering.We consider a constant length for this window which equals two seconds, for instance, if sample frequency of signal, f, is equal to 1000Hz, then the length of the window is 2000 sample.Then the main value through this window is calculated (Equation ( 6)).
Baseline wandering is removed by subtracting the calculated mean value, ) ( ~x y from ECG signal.Considering equations 5 and 6, both noiss and baseline wandering are eliminated simultaneously, the consequent formula can be expressed as Equation 7. Where, Y(x) is the fi nal resulting signal while it is mainly freed from noise and baseline wandering interference.

3-1. Discussion of the eff ects of Parameters α and β on denoising effi ciency
Fig. 4-a shows a recorded noisy ECG signal that we would like to denoise.Figs.4-b and 4-c show the denoising process with unsuitable high and low values respectively for parameter α, which caused rough and inadequate noise removal.Furthermore, Figs.4-d and 4-e show denoising process with unsuitable high and low values for parameter β respectively.Note that QRS complex morphology deformation in Fig. 4-d and inadequate denoising in the vicinity of the QRS complexes in Fig. 4-e is obvious.
By choosing optimum values for these two parameters we can have both adequate denoising and ECG morphology preservation that is shown in Fig. 4-f.

3-2. Denoising algorithm Performance Assessment
In order to guarantee the performance of the proposed denoising algorithm, we implemented this method on a true ECG signal that is corrupted manually with additive noises (Fig. 5-a).
Fig. 5-b shows the actual signal and the denoised one.We can see that the denoised signal morphologically is most similar to its original signal.On the other hand, the main waves of ECG signal still maintain their basic morphologies.This is observable in all P and T waves and QRS complexes.

3-3. Empirical Results
In order to validate the proposed algorithm, we implemented the method on noisy recorded ECG signals.An empirical result is shown in Fig. 6.It is clearly seen that noise removal process with acceptable performance is held while its main morphologies are kept.Baseline wandering is also removed by considering local averages over two seconds of ECG signal as mentioned before.
A slight malfunctioning of the method around sample 4.8×10 4 is because of R-wave detection fault and this is because of the fairly high value of noises in that region.CONCLUSION A simple mathematical algorithm for suppressing of noises from ECG signal is proposed in this paper.The advantages of this four-stage algorithm can describe as: • Very fast algorithm for ECG denoising • Mathematically simple algorithm • Preserve QRS complex characteristic points, especially Q and S waves.Despite above advantages, there are still some limitations in the denoising stage.Those limitations will appear if: • The morphology of QRS complex is a prolonged one with rather small dominant scale.• Pre-stage detection of R-waves fails.
• The smoothness and morphology preservation of denoised ECG signals strongly depend on the selected values for parameters α and β.

Fig. 3 .
Fig. 3.The behavior of window length function with respect to α and β changes: (a) the value of β = 0.02 is held constant and α changes (b) the value of α = 1.3 is held constant and β changes.