Denoising ECG Signals by Applying [615046]

Denoising ECG Signals by Applying
Discrete Wavelet Transform
Abstract —This work introduces an ECG signal denoising
method using discrete wavelet transforms. In the first part
of the study, classical denoising methods were revised, tested
and analyzed. To minimize signal distortion and resource usage
the wavelet decomposition and thresholding was proposed. In
the second part of the study, the methods mentioned above
were used to remove the baseline wondering and high-frequency
noise components of the acquired ECG signal. Simulations are
presented in Matlab based on professional pre-recorded raw
EKG signals. Experimental results, using a self-developed ZYNQ
SoC based data acquisition system, are also shown to illustrate
the applicability of the proposed signal processing methods.
Keywords— Digital Signal Processing, Filtering Algo-
rithms, Discrete Wavelet Transforms, Signal Denoising, Elec-
trocardiography
I. I NTRODUCTION
Nowadays, where nearly anybody can have at least one
smart device, the amount of physical exercise a man makes is
steadily decreasing, while the consumption of sugary and fatty
food is, at best, constant, or increasing. As a consequence, the
amount of people with heart diseases increases rapidly. While
the best way to avoid such conditions is to change the way of
one’s living completely, the easiest, fastest way is to monitor
one’s health status at least periodically.
To successfully diagnose the health condition, specialized
equipment and data processing are needed. Electrocardiogra-
phy is the process of monitoring the heart’s electrical activity
over a period by placing electrodes on the skin. A single cycle
of the electrocardiogram represents the successive atrial and
ventricular depolarisation and repolarisation. An ideal ECG
signal is shown in Fig 1, where the first graph shows the ECG
signal in the time domain with its characteristic intervals, while
the second graph shows the same ECG signal in the frequency
domain using the discrete Fourier-transform. On the frequency
graph, we can see the complexity of a clean ECG signal. The
ECG signals being very sensitive and weak in nature are highly
prone to even small noise, some of the typical interferences
are baseline wander (BLW), power line interference (PLI),
electromyographic noise and electrosurgical noise.
Filtering is the way of removing undesired signals (noises)
from the primary signal. For every well distinguishable noise,
a filter has to be designed to remove or attenuate it. For
example in [1] a new algorithm was devised for the removal
of PLI, while in [2] the removal of the baseline wondering
was studied.
(&*VLJQDO
456FRPSOH[
4
5
6
35LQWHUYDO
7
8
67
V
H
J
P
H
Q
W
47LQWHUYDO
3
35
V
H
J
P
H
Q
W
$PSOLWXG H  P 9  [   
7LPH V
(a)
10-1100101102
Frequency (Hz)0100200300400500600 Amplitude(1)ECG spectrum
(b)
Fig. 1. An ideal ECG signal in time (a) and frequency (b) domain.
II. N OISES CONTAMINATING THE ECG SIGNAL
A. Power Line Interference
The PLI of 50 Hz (and harmonics) is the source of inference.
This inference is caused by poorly shielded nearby machin-
ery’s electromagnetic field, the stray effect of alternating
current fields due to cable loops and/or trace loops on the
ECG circuit, improper grounding of ECG machine or patient,
etc.
As it is shown in Fig 1, the ideal ECG signal has important
information at 50 Hz and above, so leaving the PLI or cutting
out the frequency band above 50 Hz will distort the signal
(especially the QRS complex).
B. Base line wondering
In BLW the isoelectric line of the ECG signal changes
its position. There are multiple causes for this artifact, like
moving cables, patient movement, loose electrodes, or the
change of skin impedance due to sweating [3], etc. This artifact
is manifested as a low-frequency additive noise.

0 2 4 6 8 10 12 14 16 18 20
Time (s)-1.5-1-0.500.511.522.53Amplitude (mV)noisy ECG dataFig. 2. ECG signal contaminated with PLI and BLW noises.
III. W AVELET TRANSFORM BASED FILTERING
A. The wavelet transform
The classic operation to transform a stationary signal from
time domain to frequency domain was the Fourier transform
shown in (1).
X(f) =Z1
1x(t)e2jftdt (1)
The downside of the Fourier transform is the loss of the
time domain properties; another downside is that the transform
gives reliable results only if it is applied to stationary signals.
The short-time Fourier transform (STFT) was developed to
show accurate time-frequency representation, see [4]. The time
resolution must be increased with the central frequency of the
analysis filter to counter the resolution limitation of the STFT.
This resolution change at different frequencies is obtained by
Wavelet packets . The continuous wavelet transform (CWT)
is a linear operation that follows the mentioned ideas, while
all impulse responses of the filter bank are defined as scaled
versions of the prototype. The equation (2) shows the CWT
operation, where x(t)is the signal in time domain, while h(t)is
the mother wavelet 3, with wavelets delayed , and dilated a.
Some of the wavelets used for the CWT are Poisson, Morlet,
Ricker, and Meyer wavelets, see for example in [5], [6], [7].
CWTx(; ) =1p Z1
1x(t)h(t
)dt (2)
B. The discrete wavelet transform
The discrete wavelet transform (DWT) uses filter banks
for the construction of the multiresolution analysis, which
improves computation efficiency. As shown in Fig 4, the
wavelet transform computation requires a pair of filters. One of
the pairs calculates the wavelet coefficients, and the other ap-
plies the scaling function. This scaling function, implemented
with filter coefficients LPF (the scaling function behaves as
a low-pass filter), provides the approximation of the signal,
while the wavelet function (HPF – behaves as a high-pass
filter) gives the detail coefficients. The cut-off frequency of
the filters is the half bandwidth of the input signal I. The
wavelet filter coefficients are given by the chosen mother
wavelet, the scaling and wavelet filters (LPF and HPF) are
related by equation 3, where LPF is the wavelet or lowpass
-5 -4 -3 -2 -1 0 1 2 3 4 5
Time (1)-0.4-0.200.20.40.60.81Amplitude (1)Ricker waveler(a)
-5 -4 -3 -2 -1 0 1 2 3 4 5
Time (1)-1-0.8-0.6-0.4-0.200.20.40.60.81Amplitude (1)Morlet wavelet
(b)
Fig. 3. Ricker (Mexican hat) and Morlet continuous wavelets.
filter vector, HPF is the scaling or highpass filter vector, Lis
the length of the vector, while kis the numeral of elements
k=0::(L1). Besides the filtering, downsampling is used
(by the factor of 2). When a signal has passed through the
two filters and down-sampled, the result is called one level
wavelet transform. The results are the detail coefficients (d)
and average coefficient (a). These coefficients are used for
signal filtering and compressing [8].
HPF [k] = (1)kLPF [Lk] (3)
If the data rate of the input signal is Ts, then the data rate
of the coefficients will be as it is shown in Table I, in the case
of a level 3 decomposition see (Fig 4).
TABLE I
DATA RATE OF THE OUTPUT COEFFICIENTS OF THE THREE -LEVEL DWT
DECOMPOSITION .
Levels Level 0 Level 1 Level 2 Level 3 Level 3
x[n] d1[n] d2[n] d3[n] a3[n]
Rates Ts Ts/2 Ts/4 Ts/8 Ts/8
The discrete wavelet reconstruction or inverse wavelet trans-
form (IDWT) has the same structure, but the down-sampling
is replaced by up-sampling.
C. Wavelet thresholding
If orthogonal wavelets with periodic boundary were used
in the DWT, then the white noise would be transformed into
white noise. The wavelet coefficients of a signal are sparse,
so most of the coefficients of a noiseless signal are close to
zero. Therefore the problem of recovering the noiseless signal
can be reformulated as one of recovering the coefficients that

X[n]LPFHPF 2
2 HPF
LPF 2
2 HPF
LPFd1
d2
d3
a3 2
2Fig. 4. Wavelet tree (Mallat’s algorithm) of DWT for a three-level decom-
position.
0 0.2 0.4 0.6 0.8 1 1.2
Time (1)-1.5-1-0.500.511.5Amplitude (1)Haar wavelet
(a)
0 1 2 3 4 5 6 7
Time (1)-1-0.500.511.5Amplitude (1)Daubechies' wavelet
(b)
0 5 10 15 20 25
Time (1)-1-0.500.511.5Amplitude (1)Coiflet wavelet
(c)
Fig. 5. In this figure some discrete wavelets are shown: The basic Haar
wavelet(a), Daubechies’ wavelet (b), and Coiflet wavelet
are stronger than the noise background. This can be done by
thresholding .
Thresholding is a nonlinear, diagonal operator, which only
passes through the input signal if the amplitude is greater than
a given value (threshold). The most important thresholding op-
erators are hard (4) and soft thresholding (5). Soft thresholding
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
Input (1)-1-0.8-0.6-0.4-0.200.20.40.60.81Output (1)original signal
hard threshold
soft thresholdFig. 6. Hard and soft threshold representation on a linear input signal.
gives smoother results, while hard thresholding provides better
edge preservation.
0
(x[k]) =(
x[k];ifjx[k]j>
0; otherwise(4)
1
(x[k]) =max
0;1
jx[k]j
(5)
Most of the algorithms try to estimate the optimal value
of(Minimax algorithm [9]), with the help of the noise
level. Another method for determining the threshold level
was proposed in [10], the scheme was based on the explicit
form of Stein’s unbiased risk estimate (SURE) – (6), where
Crddenotes cardinality. The threshold should be chosen by
minimizing SURE (7).
SURE (;x) =n+nX
i=1[min(jx[i]j;)]2
2Crd(i:jx[i]j<)(6)
=argmin0p
2log(n)SURE (;x) (7)
According to [10] the final form of the threshold should be
chosen as shown in (9), where s(x)is the sparsity of the
coefficients shown in (8).
ShureShrink (x) =(p
2log(n);ifs(x)1
; otherwise(8)
s(x) =s1
2Pn
i=1(x2[i]1)
log3
2
2n(9)
IV. T HE APPLICATION OF DWT TOECG FILTERING
The DWT based filtering of a signal is done with the
signals detail and average coefficients, so the first step is to
generate the wavelet coefficients. The second step is to scale
the coefficients based on the thresholding methods mentioned
above. The final step is to recreate the signal from the
coefficients with IDWT.
To generate the wavelet coefficients the DWT is applied
conform Mallat’s algorithm shown in Fig 4. The HPF
and LPF kernels can be generated while choosing the
appropriate mother wavelet. The Haar wavelet (Fig 5,

a), is the simplest orthogonal wavelet basis. It’s exactly
reversible without the edge effects of other wavelets,
memory efficient. It uses only two scaling and wavelet
coefficients, thus calculate pairwise averages and differ-
ences, in other words, it only reflects changes in adjacent
data pairs. The Daubechies (Fig 5,b) wavelet is orthogo-
nal and has compact support characteristics. The wavelet
uses an overlapping window, the average and difference
are generated from more than 2 data points making it
smoother than the Haar wavelet. The Symlet or Coiflet
(Fig 5,c) wavelets differ from the Daubechies wavelet by
increased computational overhead. These wavelets are the
least asymmetric wavelets.
After generating the average and detail coefficients, the
scaling algorithm is applied based on the noise present
in the system (Minimax or SURE algorithms).
The scaled coefficients can be used to create the filtered
signal by applying the IDWT with MALLAT’s algorithm
based on the mother wavelet chosen in the first step.
To denoise an ECG signal, the upper mentioned steps can
be used in the following form:
1) Store the raw data(the storage size should be the power
of 2).
2) Choose a mother wavelet.
3) Generate the wavelet coefficients with DWT.
4) Remove the BLW noise by scaling the average coeffi-
cient.
5) Remove the PLI and HF noises by applying SURE
algorithm to the detail coefficients.
6) Generate the filtered data from the coefficients with
IDWT.
V. T HE COMPARISON OF DIFFERENT FILTERING METHODS
To test the classic and modern filtering algorithm, a custom
made signal and a pre-filtered ECG signal was used from
Physio Bank ATM [11] and imported into Matlab. The ideal
ECG signal was combined with additive noises: a sine wave
of 15 mHz for BLW, a sine wave of 50 Hz for PLI, and a
uniformly distributed noise with a frequency band of 300 Hz
to 500 Hz for HF noise as shown in Fig 7. To compare the
filters, the Mean Squared Error (MSE) and the Signal to Noise
Ratio (SNR) was used as shown in (10), where !is the noise,
xis the ideal signal, and FFT() is the fast Fourier transform.
The SNR of the noisy signal was 6.8134 dB.
SNR (x;!) = 10lgPkFFT (x)kPkFFT (!)k
(10)
A. Classic filtering
When classic filters are used, each response type from to
one filter: The BLW noise has to be removed with a high-pass
filter, The PLI noise has to be removed with a bandstop filter,
while the high-frequency noises have to be removed with a
low-pass filter as shown in Fig 8.
The first tested filtering structure was a FIR approach. The
BLW removal was achieved with a 2000th order Equiripple
0 2 4 6 8 10 12 14 16 18 20
Time (s)-1.5-1-0.500.511.522.53Amplitude (mV)noisy ECG dataFig. 7. ECG signal with BLW, PLI, and HF noises added.
Fig. 8. Complete ECG signal filtering system with cascaded filter blocks.
filter with a density factor of 20, stop frequency of 0.01 Hz
and pass frequency of 0.5 Hz. The PLI was removed with
an 1114th order Equiripple filter with a density of 20 Hz,
passbands from DC to 48 Hz and from 52 Hz to the Nyquist
frequency (or fs/2, where fsis the sampling frequency), and
a stopband from 49 Hz to 51 Hz. The high-frequency noises
were removed with a 254th order Nuttall low-pass filter with
cut-off frequency of 250 Hz.
As shown in Fig 9, the filters removed the noise artifacts,
but they induce a small delay, and a distortion until the FIR
convolution registers are full with data ( approx. 2s). The SNR
increased to 24.1539 dB.
The second applied filtering structure was a complete IIR
approach. The BLW removal was achieved with a 3rd order
Butterworth high-pass filter. The PLI was removed with a
24th order bandstop Butterworth filter, and the high-frequency
noises were removed with a 31st order Butterworth filter. The
stop and pass frequencies were the same as in the case of FIR
filters.
As shown in Fig 10, the filters removed the BLW, and
high-frequency noises, but had some residual noise from the
PLI, but the distortion and delay was minimized due to the
small convolution registers. The SNR of the filtered signal
was 20.4868.
B. DWT based ECG filtering
To filter the signal, a mother wavelet must be chosen.
For this research, the symlet 8 wavelet was used. Since the
sampling frequency is 1 kHz, to remove the BLW, a 10th
order decomposition was necessary. The filtering is done as
follows: The signal is decomposed to wavelet coefficients with

0 1 2 3 4 5 6 7 8 9 10
Time (s)-0.4-0.200.20.40.60.811.21.41.6Amplitude (mV)original ECG
filtered ECGFig. 9. ECG signal filtered with FIR high-pass, band-stop, and low-pass filter
stages.
0 1 2 3 4 5 6 7 8 9 10
Time (s)-1-0.500.511.52Amplitude (mV)Original ECG
Filtered ECG
Fig. 10. ECG signal filtered with IIR high-pass, band-stop, and low-pass filter
stages.
0 10 20 30 40 50 60
Time (s)-1.5-1-0.500.511.522.5Amplitude (mV)Noisy ECG
a10 Wavelet approximation
(a)
0 1 2 3 4 5 6 7 8 9 10
Time (s)-1-0.500.511.52Amplitude (mV)original ECG
filtered ECG
(b)
Fig. 11. In figure (a) the noisy ECG signal is shown with the 10th order
wavelet approximation, while in figure – the artificial BLW sine function is
reconstructed (b) the original ECG signal is compared with the filtered ECG
signal.
the wavelet transforms (The detail coefficients d1…d10 and the
average coefficient a10 are calculated). The average coefficient
contains only the BLW as shown in Fig 11 (a), so it will
be set to 0, while the detail coefficients will be thresholded
with the soft SURE method. After thresholding, a wavelet
reconstruction is used to generate the filtered data. The result
can be seen in Fig 11 (a), and the SNR was 30.5355 dB,
which is better than the SNR achieved with the classic filtering
methods.TABLE II
SNR OF THE ECG SIGNAL WITH THE DIFFERENT FILTERING METHODS .
Filter Algorithm SNR MSE
algorithm complexity (dB) (mV)
Raw signal – 6.8134 –
All FIR O(N) =Nlg(N) 24.1539 0.0847
filters 2000, 1114, 245 taps
All IIR O(N) =Nlg(N) 20.4868 0.0249
filters 3, 24, 31 order
Wavelet O(N) =Nlg(N) 30.5355 9:42104
thresholding 10,10
0 1 2 3 4 5 6 7 8 9 10
Time (s)-1.5-1-0.500.511.522.53Amplitude (mV)Raw ECG signal
BLW residual signal
(a)
0 1 2 3 4 5 6 7 8 9 10
Time (s)-0.6-0.4-0.200.20.40.6Amplitude (mV)Denoised ECG signal
(b)
Fig. 12. In figure (a) The raw ECG signal sampled with the SoC is shown,
and the BLW residual signal from the first part of the filtering algorithm,while
in figure (b) the filtered signal is shown.
VI. E XPERIMENTAL RESULTS
The proposed method was implemented in a ZYNQ7 SoC
(System on Chip) form Xilinx. This SoC has a Programmable
Logic section (PL) and a Processing System Section (PS)
embedded together. An IP core was generated with HDL
coder based on the wavelet filtering method mentioned above
(written in C++). The IP Core was then exported to Vivado
and tested on real-time data. The hardware was designed as
follows (shown in Fig 13):
1) The PS acquires data from the SPI ADC (Analog to
Digital Converter) and sends the data to the filtering IP.
2) The filtering IP in the PL pushes the data into a 2048
element register, applies the first DWT/IDWT pair to
remove the BLW, then applies the second DWT/IDWT
with thresholding to remove the PLI and HF noises.
After the filtering is done, the data is sent back to the
PS.
3) The PS sends both the clean and noisy data to the
PC through UART communication, where it can be
evaluated.
As shown in Fig 12, the IP core filtering works as intended.

Fig. 13. The hardware implementation of the Wavelet denoising algorithm. The Zynq PS receives the ECG data on the SPI bus and uses the PL IP as a
hardware accelerator.
The SNR, MSE can be further improved with further studying
different mother wavelet properties and thresholding methods.
The implemented IP core manages to filter the signal under 8
ns, with 200 MHz PL clock source, but the processing time
can further be improved by pipelining the algorithm, unrolling
loops, and using Stream interface with DMA (Direct Memory
Access) instead of AXI Lite interface.
VII. C ONCLUSION
The proposed Wavelet thresholding method not only suc-
cessfully removed the BLW, PLI, and HF noises from the
sampled ECG signals. A SoC hardware implementation was
proposed to verify the usability of the algorithm, based on
which the favorable conclusion is drawn, the algorithm can be
implemented in hardware and can be used in real time, requires
less computation than conventional FIR and IIR filters and the
same attenuation can be achieved with less filtering stages.
REFERENCES
[1] M. Meidani and B. Mashoufi, “Introducing new algorithms for realising
an fir filter with less hardware in order to eliminate power line inter-
ference from the ecg signal,” IET Signal Processing , vol. 10, no. 7, pp.
709–716, 2016.
[2] T. Singh, P. Agarwal, and V . K. Pandey, “Ecg baseline noise removal
techniques using window based fir filters,” in Medical Imaging, m-Health
and Emerging Communication Systems (MedCom), 2014 International
Conference on , Nov 2014, pp. 131–136.
[3] B. Taji, S. Shirmohammadi, V . Groza, and I. Batkin, “Impact of skin
electrode interface on electrocardiogram measurements using conductive
textile electrodes,” IEEE Transactions on Instrumentation and Measure-
ment , vol. 63, no. 6, pp. 1412–1422, June 2014.
[4] O. Rioul and M. Vetterli, “Wavelets and signal processing,” IEEE Signal
Processing Magazine , vol. 8, no. 4, pp. 14–38, Oct 1991.
[5] S. Mustafa, A. Abbosh, B. Henin, and D. Ireland, “Brain stroke detection
using continuous wavelets transform matching filters,” in 2012 Cairo
International Biomedical Engineering Conference (CIBEC) , Dec 2012,
pp. 194–197.
[6] A. N. Saatlo and S. Ozoguz, “Cmos implementation of scalable morlet
wavelet for application in signal processing,” in 2015 38th International
Conference on Telecommunications and Signal Processing (TSP) , July
2015, pp. 1–4.[7] V . J. Samar, H. Begleiter, J. O. Chapa, M. R. Raghuveer, M. Orlando,
and D. Chorlian, “Matched meyer neural wavelets for clinical and
experimental analysis of auditory and visual evoked potentials,” in 1996
8th European Signal Processing Conference (EUSIPCO 1996) , Sept
1996, pp. 1–1.
[8] B. A. Rajoub, “An efficient coding algorithm for the compression of ecg
signals using the wavelet transform,” IEEE Transactions on Biomedical
Engineering , vol. 49, no. 4, pp. 355–362, April 2002.
[9] D. L. Donoho and I. M. Johnstone, “Ideal spatial adaptation by wavelet
shrinkage,” Biometrika , vol. 81, pp. 425–455, 1994.
[10] ——, “Adapting to unknown smoothness via wavelet shrinkage,” JOUR-
NAL OF THE AMERICAN STATISTICAL ASSOCIATION , pp. 1200–
1224, 1995.
[11] A. L. Goldberger, L. A. N. Amaral, L. Glass, J. M. Hausdorff, P. C.
Ivanov, R. G. Mark, J. E. Mietus, G. B. Moody, C.-K. Peng, and H. E.
Stanley, “PhysioBank, PhysioToolkit, and PhysioNet: Components of a
new research resource for complex physiologic signals,” Circulation , vol.
101, no. 23, pp. e215–e220, 2000 (June 13), circulation Electronic Pages:
http://circ.ahajournals.org/content/101/23/e215.full PMID:1085218; doi:
10.1161/01.CIR.101.23.e215.

Similar Posts