Selection of Optimal Parameters for ECG Signal Smoothing and Baseline Drift Removal

Electrocardiogram (ECG) contains crucial clinical information about the cardiac activities of the heart, however, such signal a part of being in large volume is often characterised by a low quality due to the noise and other artifacts. In order to correctly extract the important features from the ECG signal, first it needs to be preprocessed, denoised and normilised. Significant attention in the literature has been directed toward the ECG preprocessing, though there are ambiguity to which wavelet performs the best for ECG signal processing as well as which decomposition level should be used and how the baseline wander can be removed. Parameters of wavelets have been investigated but the lack of evidence for recommendations is not found. This research conducts a comprehensive study to identify some characteristics of optimal decomposition level and to identify the span that should be used. We have taken into consideration all available wavelets within the Matlab environment and tested it on a number of randomly chosen ECG signals. Results indicate that the decomposition level of 4 should be used and that the Biorthogonal wavelet bior3.9 performs the best for smoothing and baseline drift removal. Also, we concluded that the optimal value for span is 100, which guarantees the best baseline wander removal.


Introduction
Cardiovascular disease (CVD) is a disorder affecting both the vasculature (i.e.hypertension) and the heart muscle itself.Cardiovascular disease remains the number one cause of mortality in the western world, responsible for more than 16 million deaths annually worldwide.Approximately 30% of all patients with CVD ultimately die from the disease.Therefore, regular visits to doctors and early detection from Electrocardiogram (ECG) is a critical step in the prevention of cardiovascular disease (Mendis et al., 2011).
An ECG captures the electrical signal within the heart.Traditional ECG signal is displayed on a graph where the X-axis is Time and the Y-axis can be either Voltage (mV) or Amplitude (dB).An ECG graph can be used for analysis of long intervals, measuring the consistency of the beats and looking for proper depolarisation, repolarisation and any irregular beats (Braunwald, 1997).
In electrocardiography, an ECG artifact is used to indicate something that is not "heart-made."These include electrical interference by outside sources, electrical noise from elsewhere in the body, poor contact and machine malfunction.Artifacts are extremely common and knowledge of them is necessary to prevent misinterpretation of a heart's rhythm.Significant attention in the literature has been devoted to accurate analysis of ECG signal that would lead to identifying cardiac abnormalities that a patient might have and therefore correct diagnoses.Most of the clinically useful information in the ECG is found in the intervals and amplitudes defined by its features, such as characteristic wave peaks, frequency components and duration.In order to improve the quality of analysis the first step is to preprocess the signal so different filtering algorithms, which improve the Signal to Noise ratio and removing artifacts, have been introduced.
To improve correct diagnosis, different automatic methods have been proposed in the literature.Researchers addressed different aspects in relation to the ECG signal, proposing different methods to improve the signal to noise ratio, such as: Discrete Wavelet Transform (DWT), Continuous Wavelet Transform (CWT), Hilbert Transform (HT), Fast Fourier Transform (FFT), Short Time Fourier transform (STFT), and Power Spectral Density (PSD).The usage of low pass and high pass filters for ECG signal denoising has been also recommended (Abdel-Rahman and Daqrquq, 2010).Recent research demonstrated the outstanding performance of DWT in processing the ECG signal (Ercelebi, 2004).Different parameters have been investigated, the wavelet function (Karel et al., 2005), threshold calculus (Ghael et al., 1997), and level of decomposition (Alste and Schilder, 1985).Sarutha and colleagues investigated optimal wavelet coeffcients (Saritha et al., 2008).Additionally, the performance criteria have been presented in literature to measure the quality of a wavelet, based on the principle of maximisation of variance (Karel et al., 2005), and the multi-resolution (Mahamoodabadi et al., 2005).It has been shown that the concept of DWT is also suitable for non-stationary ECG signals (Cornelia and Romulus, 2005).
Joshi proposed a wavelet based search algorithm for denoising and subtractive procedure to isolate the baseline wander from the noisy ECG signal and showed that the DWT performs better than previously proposed methods.Authors claim that the concept is also suitable for the non-stationary ECG signals.Particular attention was given to baseline wander and different types of noise eliminations as authors consider that as a main problem in correct ECG analysis (Joshi and Ghule, 2010).Attention to the choice of particular wavelets has also been given consideration in the literature in order to identify the best wavelet for ECG signal preprocessing (Kaur and Singh, 2011), (Stantic and Jo, 2012).
Most of the significant attention in the literature has been directed toward ECG processing and automatic analysis.Medical practitioners have not accepted the current findings as the definitive answers in making quick diagnosis towards arrhythmia patients, which clearly indicates that the additional work needs to be done to provide more reliable diagnosis.It has been shown that the DWT is an outstanding option in ECG signal processing however, previous findings does not address how different settings of wavelets perform differently.Other works considered and recommended different wavelets as well as different decomposition levels, most often without any justification.For example Martis and colleges utilised the Daubechies wavelet db4 with a decomposition level of 4 (Martis et al., 2012), while in another work Daubechies wavelet db6 and decomposition level of 4 has been utilised (Kaur & Singh, 2011).Some attempts to identify and recommend the best performing wavelet with a limited number of wavelets on a single MIT-BIH signal was conducted by Khanam and Ahmad.They utilised the decomposition level 3 without any justification and concluded that the Symlets wavelet Sym20 performs the best (Ruqaiya Khanam, 2013).
Due to ambiguity of the literature and the lack of grounds for recommendation in which wavelet performs the best for ECG signal processing as well as which decomposition level should be used and how the baseline wander can be removed the best, we decided to conduct a comprehensive study and take into consideration all available wavelets within the Matlab environment as well as consider a number of different randomly chosen signals from MIT-BIH database (Moody & Mark, 2001a).
The reminder of the paper is organised as follows: In the next section we provide the necessary background information about ECG as we outline the related works.In section 3 we present the method, providing details about the datasets used and explain what measures we have used to identify the signal and recommend the wavelet, decomposition level and span.Section 4 provides the results, discussion and main findings.And finally, in section 5 we conclude the paper.

ECG Analysis
An ECG is a test that records the electrical activity of the heart.ECG is used to measure the rate and regularity of heartbeats as well as the size and position of the chambers, the presence of any damage to the heart, and the effects of drugs or devices (such as a pacemaker) used to regulate the heart.
An ECG artifact is used to indicate something that is not 'heart-made'.These include electrical interference by outside sources, electrical noise from elsewhere in the body, poor contact, and machine malfunction.Artifacts are extremely common and knowledge of them is necessary to prevent misinterpretation of a heart's rhythm.In many situations, the ECG is recorded in conditions where the signal can be corrupted by different types of noise, therefore noise reduction represents an important objective of ECG signal processing.Noise in the ECG signal can be of such level that the waveforms of interest in the ECG signal are masked by noise and their presence can only be revealed once appropriate signal preprocessing is applied.
Obviously the quality of ECG signal analysis is dependent on the preprocessing stage which is still a very important area of research.Different types of noises that can prevent accurate analysis of the ECG signal have been identified in the literature: Muscle tremor/Noise is caused as the heart is not the only thing in the body that produces measurable electricity.Low amplitude muscle tremor noise can mimic the baseline seen in atrial fibrillation.Another common noise in the ECG signal is Baseline Wandering.One possible cause of baseline wandering is if cables are moving during the reading.Patient movement, dirty lead wires/electrodes, loose electrodes and a variety of other things can cause this as well.If an ECG machine is poorly grounded or not equipped to filter out AC 50 or 60 hertz noise an AC interference noise can also be present.
A lot of attention in the literature has been directed to analysis of the ECG signal in the Frequency domain, by applying Fourier transform, autoregressive moving average, Multiple Signal Classifications, as well as the short term Fourier transform and recently wavelet analysis.Most works have been evaluated on data from the MIT-BIH database (Moody and Mark, 2001a).

Wavelet Transform for ECG Analysis
A wavelet is a wave-like oscillation with amplitude that starts out at zero, increases, and then decreases back to zero.It can typically be visualised as a "brief oscillation" like one might see recorded by a seismograph or heart monitor.Generally, wavelets are purposefully crafted to have specific properties that make them useful for signal processing.Wavelets can be combined, using a "revert, shift, multiply and sum" technique called convolution, with portions of an unknown signal to extract information from.
The wavelet transform is also designed to address the problem of non-stationary ECG signals.The main advantage of the wavelet transform is that it has a varying window size, being broad at low frequencies and narrow at high frequencies, thus leading to an optimal time-frequency resolution in all frequency ranges.The wavelet transform of a signal is the decomposition of the signal over a set of functions obtained after dilation and translation of an analysing wavelet.The ECG signal, consisting of many data points, can be compressed into a few features by performing spectral analysis of the signal with the wavelet transform.These features characterise the behaviour of the ECG signal.Using a smaller number of features to represent the ECG signal is particularly important for recognition and diagnostic purposes.
One of the prominent methods for de-noising of noisy ECG signals is the wavelet theory (Ercelebi, 2004).We classify the methods based on wavelets into several groups and list several typical representatives:  The multi-resolution framework and thresholding strategy (Karel et al., 2005), (Cornelia and Romulus, 2005)  The orthogonal filter banks (Saritha et al., 2008)  The usage of low pass and high pass filters (Abdel-Rahman and Daqrquq, 2010)  Subtractive procedures to isolate the baseline wander (Frau and Eck, 2000), (Joshi and Ghule, 2010).
It has been pointed out the advantages of using DWT associated with a noise thresholding strategy.Through wavelet thresholding relevant noise can be removed from the signal, which allows the utilisation of simple detection logic for the QRS detection.The main advantage of this kind of detection is less time consuming analysis allowing applicability on on-line long lasting ECG signals.It has been also shown that the concept of DWT is suitable for the non-stationary ECG signals (Cornelia and Romulus, 2005), (Saritha et al., 2008), (Joshi and Ghule, 2010).Additionally, the multi-resolution framework gives wavelets a very powerful compression and filtering tool.Karel and colleagues investigated the quality of a wavelet, based on the principle of maximisation of variance in order to propose a performance criteria (Karel et al., 2005).
Baseline wander and different types of noise elimination are considered as a classical problem in ECG analysis.Frau and colleagues presented a method to reduce the baseline wandering of an ECG signal (Frau and Eck, 2000).Joshi proposed a wavelet based search algorithm in different scales for denoising and subtractive procedure to isolate the baseline wander from the noisy ECG signal.This algorithm is tested using the data records from the MIT-BIH database and promising results have been obtained (Joshi and Ghule, 2010).They utilised the concept of DWT and claim that the proposed concept is suitable for the non-stationary ECG signal as it has adequate scale values and shifting in time.They paid particular attention to baseline wander and different types of noise elimination as they consider that as a main problem in correct ECG analysis.In their concept the ECG signal is transformed, thresholded and then inverse-transformed, which results in a cleaned-up signal that still shows important ECG feature details (PQRST peaks). Decomposition: In the first step they decide about the wavelet that will be used and also make a decision on level N and then compute the wavelet decomposition of the signal s at level N.  Thresholding detail coeffcients: For each level from 1 to N, select a threshold and apply soft thresholding to the detail coeffcients. Reconstruction: Compute wavelet reconstruction using the original approximation cofficients of level N and the modified detail coeffcients of levels from 1 to N.
This work identifies two important issues: how to choose the threshold, and how to perform the thresholding.To address those issues they introduced two types of thresholding Hard and Soft thresholding.In Figure 1 is shown the outcome of removing the baseline wander after applying three steps mentioned above.
Figure 1.Baseline drift removal Shantha discussed the design of a good wavelet for a cardiac signal from the perspective of orthogonal filter banks and removing the corresponding wavelet coefficients at higher scales (Saritha et al., 2008).For non-stationary signals it is not adequate to use digital filters or adaptive methods because of the loss in information.Digital filters and adaptive methods can be applied to signal whose statistical characteristics are stationary in many cases.Therefore the DWT has been proven as an appropriate method for non-stationary signal analysis.
Alfaouri and colleagues investigated suitable coefficients of produced wavelet subsignals using thresholding in order to find which coefficients should be removed (Alfaouri and Daqrouq, 2008).The filtration method that applies thresholding to reduce the noise content of the non-stationary signal has been introduced a while ago by Donoho and it is considered as a powerful noise reduction method (Donoho, 1991).The method works with a wide class of one or two-dimensional signals and gives a well and satisfied results.Several other methods to enhance the ECG signal have also been presented in the literature, the most widely used is the least mean square adaptive algorithm (LMS), however, these algorithms are not able to track the rapidly varying non-stationary signal such as a ECG signal.
Al-Qawasmi and colleagues also considered to filter the ECG signal from noise by utilising the DWT (Alfaouri and Daqrouq, 2008).They used a variety of ECG signals and the method was evaluated using MATLABs software.The aim was to adapt the DWT to enhance the ECG signal and to improve the signal to noise ratio.The original ECG signal is filtered by a low pass filter and the process was repeated many times, the residual of a high pass filter is filtered out by a low pass filter before the reconstruction of the original signal by inverse DWT.Authors also utilised two main types of thresholding: Hard thresholding by which all the coefficients below a fixed threshold T that depends on noise variance are discarded and Soft thresholding by which all the coefficients below are discarded and all the coefficients above a fixed threshold T are shrunk.In Equation 1 i; k; w, is the wavelet coefficient and i; k; H is wavelet based filter (Abdel-Rahman and Daqrquq, 2010).However, in another work the threshold value is accomplished experimentally after using a loop of calculating a minimum error between the denoised wavelet subsignals and the original free of noise subsignals (Ranganathan et al., 2010).They utilised a Meyer mother wavelet functions as it has an energy concentrated in time.
The results presented in Figure 2 show the influence of standard deviation σ of noise values at the Percent Root Mean Square Difference (PRD) and the Signal-to-Noise Ratio (SNR).ECG signals are normally compressed with lossy compression algorithms so that they can quantify the difference between the original and the reconstructed signal, often called distortion.The most prominently use of distortion measure is the PRD.The PRD indicates reconstruction fidelity by point wise comparison with the original data.The SNR is an engineering term for the power ratio between a signal and noise.It is expressed in terms of the logarithmic decibel scale (Ruqaiya Khanam, 2013).
They noticed that, when σ values of the noise are small (0.044 mV, 0.09 mV), the best filtration (biggest SNR and smallest PRD) is F1 (the signal is filtered only one time by repeating the system), but when σ values of the noise were big (0.44 mV and 0.9 mV), the best filtration (biggest SNR and smallest PRD) is F3 (the signal is filtered three times by repeating the system).SNR value is biggest when PRD is smallest as a percent of distortion, Figure 2. The presented method showed good results when compared to the existing methods.

Figure 2. PRD and SNR relation
Despite a significant attention in the literature that addresses the problem of preprocessing of ECG signals, evidence that the DWT performs the best and attempts to take into consideration several wavelets, there is no work which takes into consideration a wide range of available wavelets to identify which wavelet will perform the best.In the following section we will define the measures and methods used to identify which wavelet performs the best on the ECG signals and should be applied in the process of the preprocessing stage.

Performance Analysis
In this section we describe in detail how the study was conducted and provide a complete description of the methods used.It enables the reader to evaluate the appropriateness of methods and the reliability and the validity of results.We provided sufficient information so experienced investigators should be able to replicate the study.
In order to correctly detect the abnormality within the ECG signal it needs to be preprocessed.At first there is the need to eliminate the offset, normalise to the value of one, smooth the signal and remove the baseline drift.
As it can be been in Figure 3 the Actual signal can have a significant baseline drift, which is usually caused by artifact.In this work we listed DWT as it has been shown that it performs better than other methods (Ercelebi, 2004).

Dataset
In line with most studies in this field, we utilised signals from the MIT-BIH database and specifically concentrated to signals which represented a challenge as mentioned in the literature (Mourad Talbi and Cherif, 2012).One of them is signal 234, which apart of having an Arrhythmia also has artifact.Figure 3, taken from our application, shows signal 234 from the MIT-BIH database and Actual signal represents an extreme part with the artifact.The following ECG signal records from the MIT-BIH database have been taken into consideration 100, 101, 102, 105, 109, 200, 203, 215, 222, and 234.The database is sampled at 360Hz and the resolution of each sample is 11 bits/sample over a 10mV range.
The MIT-BIH Arrhythmia Database was the first generally available set of standard test material for evaluation of arrhythmia detectors, and it has been used for that purpose as well as for basic research into cardiac dynamics at about 500 sites worldwide since 1980 (Moody & Mark, 2001b).The wavelet analysis of the ECG signal is performed using the MATLAB software.To make sure we removed the baseline drift and smoothed it as best as possible, we investigated which particular wavelet and which parameters should be used.Another important task in compression of signals and their reconstruction is to define the error criterion, which needs to be defined so that it will measure the ability of the reconstructed signal to preserve the relevant information.A way of quantifying the difference between the original and the reconstructed signal is often called distortion.The most prominent method to measure the distortion is the Percent Root mean square Difference (PRD) which can be defined by: PRD = To decide what are the best parameters we also calculated the Integral, which basically represent the area under the ECG signal, represented with grey in Figure 3, which is obtained from the actual application developed as part of this work.It can be calculated as:

Results
We investigated which particular wavelet would achieve the best performance with regard to the smoothing and baseline drift removal.We have taken into consideration all available wavelets within the MatLab environment: Daubechies wavelets db2 to db45, Biorthogonal wavelets bior1.1 to bior6.8,Reverse Biorthogonal wavelets rbior1.1 to rbior6.8,Symlets wavelets sym2 to sym36, and Coiflets wavelets coif1 to coif5.We have also varied the decomposition level from 4 to 12.
At first we investigated which decomposition level achieves the highest signal to noise ratio (SNR).In Figure 4 we show SNR for decomposition level of 4, 8, and 12. Presented data are for Daubechies wavelets and the mean value of all selected signals from the MIT-BIH database, mentioned in section 4.1, we also randomly selected the region within the signals.It is obvious that with the increase of decomposition level the SNR is lower as the signal is cleaned more, however along with removing the noise also some important features from the signal are removed.Therefore, we identified that the decomposition level of 4 performs the best as it sufficiently removes the noise and at the same time retains the features important for classification.Therefore, further experiments we performed with a decomposition level of 4.      With further experiments we conducted on the best performing representatives of particular wavelets, which are identified in the experiments explained above.We calculated the PRD, SNR, and Mean Square Error (MSE) on a diversity of ECG signals from normal to abnormal, mentioned in section 4.1.In Table 1, for brevity, we only show the mean values of all the considered signals of the best representatives of the particular wavelet types.All details for the SNR can be found in Figures 5 to 9. In Figure 10 we show the SNR for earlier identified best performing wavelets.
Figure 10.SNR for specific wavelets Additionally, in order to identify the best span (floating window), which can contribute to the best baseline wander removal, we investigated different span values from 40 to 140.We calculated the integral value of the signal after the smoothing and baseline drift removal, which basically represents the area under the curve, as shown Figure 3 and it is calculated using the equation 4. In this experiment we have considered only Biorthogonal wavelet bior3.9, as mentioned above in the experiments we identified that the bior3.9performs the best with regard to the SNR.We have chosen the signal 234 and specifically looked into a part of the signal that has a significant baseline wander and also contains noise as well as artifact, as it can be seen in Figure 12.
As it can be seen on Figure 11 on the left hand side we show the Integral value as a factor of span and on the right hand side SNR as a factor of span.It can be seen that a lower span has a higher SNR, which indicates that the signal is cleaned too much and some arrhythmia might be removed.However, with the increase of span the baseline drift is removed more and at the span of 100 the SNR flattens as the Integral achieves a lower value.For that reason we identified that the span value of 100 performs the best and in Figure 3 it can be seen in the middle graph titled 'drift' how well span 100 identifies and removes the drift.

Discussion
First part of our experiments was devoted to identifying the decomposition level.As indicated above previous works utilised different decomposition levels most often without any justification.We investigated decomposition level of 4, 8, and 12. On the Figure 4 can be seen that with the increase of decomposition level the SNR is lower.This is because with higher decomposition level signal is cleaned more, however, overcleaning of noise can also remove some important features from the ECG signal, which are important for identification of arrhythmias.With too low decomposition level SNR is too high as too low level of noise is removed.Therefore, there is the need to find a balance between how much to remove the noise and at the same time not to remove the important features.By analysing the results presented in Figure 4 as well as looking into how the important features have been preserved in the ECG signals, we concluded that the decomposition level of 4 performs the best as it sufficiently removes the noise and retains the features important for classification.
In relation to identify the best representatives for particular wavelets, we run experiment with decomposition level of 4 on ten typical samples of ECG signals from the MIT-BIH database.Within the signal we randomly allocated a region and for all wavelets the same region was taken into consideration.Based on the SNR we identified several top performing wavelets for each particular wavelet type, as explained in section 4.  9: Symlets 4 to 9 that the performance of particular wavelet was uniform across different signals.
To identify which wavelet performs the best, out of all the best representatives of particular wavelet, we conducted a comprehensive study and apart of the SNR we also evaluated Percent Root mean square Difference (PRD) and Mean Square Error (MSE).From the results shown in Table 1 it is evident that the Biorthogonal wavelet bior3.9performs the best, as it archives the highest SNR as well as lowest PRD and MSE.Finally, we also looked into the optimal span (floating window), which could guarantee the best removal of baseline wonder.Specifically, we have taken into consideration Biorthogonal wavelet bior3.9 as well as decomposition level of 4, as we previously reported above that those parameters are best and should be used for ECG signal processing.We have considered ECG signal 234 as that signal in certain areas has significant baseline wander, noise as well as artifact, as it can be seen in Figure 12.When deciding about the floating window it is important to take into consideration two factors, one that the baseline wander is removed, which can be measured by calculating the INT of the cleaned signal and also what is the SNR.This is important as indicated above; overcleaning of the signal can remove significant features within the ECG signal and can have influence on the analysis.Based on the results shown in Figure 11 it is obvious that the span of 100 has comparative value of SNR while it flattens with regard to the INT value and therefore we consider span of 100 as optimal.Quality of identifying the baseline wander drift with the span of 100 can be seen in Figure 12.It is evident how well baseline drift can be identified and therefore the signal can be cleaned with the baseline wander removed.To ensure that the above mentioned results are not just dependent on random selection of signal, we conducted additional experiments with other parts of signal 23 as well as other signals, which do not have a significant baseline wander as signal 234 as well as have different heartbeat rate.We concluded that the identified span value of 100 holds and therefore we consider it as optimal value.

Conclusion
In this study, we investigated the optimal parameters for ECG signal processing.Despite the significant attention in the literature directed toward the ECG processing and despite that it has been shown that the DWT is the best option in ECG signal processing, literature does not address the issue in which wavelet performs the best and should be used.There is ambiguity in the literature and also there is a lack of grounds for recommendations or usage of specific wavelet.Different works considered or recommended different wavelets as well as different decomposition levels, most often without any justification.Therefore, we decided to conduct a comprehensive study and take into consideration all available wavelets within the Matlab environment as well as consider a number of different signals from the MIT-BIH database to cover different types of artifacts and arrhythmias.We concluded that the decomposition level of 4 should be used and that the Biorthogonal wavelet bior3.9performs the best.We also investigated optimal parameters for floating window which achieves the best base line wander removal.We concluded that the optimal value for span is 100.

Figure 3 .
Figure 3. Drift Removal and Integral x[n]  and xˆ[n]  are the original and reconstructed signals of length N, respectively.The PRD indicates reconstruction fidelity by point wise comparison with the original data.Additionally, we calculated the Mean Square Error (MSE), which can quantify the difference between original signal and cleaned signal without the noise.It can be calculated by:

Figure 5 .
Figure 5. SNR for Daubecies Wavelets for decomposition level of 4 for all signals and mean values

Figure 6 .
Figure 6.SNR for Biorthogonal Wavelets for decomposition level of 4 for all signals and mean values

Figure 7 .
Figure 7. SNR for Reverse Biorthogonal Wavelets for decomposition level of 4 for all signals and mean values

Figure 8 .
Figure 8. SNR for Cofficient Wavelets for decomposition level of 4 for all signals and mean values

Figure 9 .
Figure 9. SNR for Symlet Wavelets for decomposition level of 4 for all signals and mean values

Figure 11 .
Figure 11.Optimal span 1. Results have been shown in Figures5 to 9. It is evident that the SNR significantly varies between different wavelets depending on the level of noise or arrhythmias.The SNR also varies depending on the ECG signal, as some signals have significant level of noise while other has less.Conclusion on which wavelet performs the best we made on mean value over all signals as we have chosen ECG signals that cover diversity of noises as well as arrhythmias.However, as it can be seen in Figure