0% found this document useful (0 votes)
102 views6 pages

ECG Denoising

This document introduces a method for denoising ECG signals using discrete wavelet transforms. It first reviews classical denoising methods and proposes using wavelet decomposition and thresholding to minimize signal distortion and resource usage. It then applies these wavelet-based methods to remove baseline wandering and high-frequency noise from acquired ECG signals. Simulations using pre-recorded ECG data and experimental results from a developed data acquisition system illustrate the effectiveness of the proposed signal processing techniques.

Uploaded by

Áron Fehér
Copyright
© Attribution Non-Commercial ShareAlike (BY-NC-SA)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views6 pages

ECG Denoising

This document introduces a method for denoising ECG signals using discrete wavelet transforms. It first reviews classical denoising methods and proposes using wavelet decomposition and thresholding to minimize signal distortion and resource usage. It then applies these wavelet-based methods to remove baseline wandering and high-frequency noise from acquired ECG signals. Simulations using pre-recorded ECG data and experimental results from a developed data acquisition system illustrate the effectiveness of the proposed signal processing techniques.

Uploaded by

Áron Fehér
Copyright
© Attribution Non-Commercial ShareAlike (BY-NC-SA)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Denoising ECG Signals by Applying

Discrete Wavelet Transform


Áron Fehér
Department of Electrical Engineering
Sapientia Hungarian University of Transylvania
Targu Mures, Romania
Email: [email protected]

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 (a)
SoC based data acquisition system, are also shown to illustrate
the applicability of the proposed signal processing methods. 600
Amplitude(1)

Keywords— Digital Signal Processing, Filtering Algo- 500 ECG spectrum


rithms, Discrete Wavelet Transforms, Signal Denoising, Elec- 400

trocardiography
300

I. I NTRODUCTION 200

100

Nowadays, where nearly anybody can have at least one 0


10-1 100 101 102

smart device, the amount of physical exercise a man makes is


steadily decreasing, while the consumption of sugary and fatty Frequency (Hz)
food is, at best, constant, or increasing. As a consequence, the
(b)
amount of people with heart diseases increases rapidly. While
the best way to avoid such conditions is to change the way of Fig. 1. An ideal ECG signal in time (a) and frequency (b) domain.
one’s living completely, the easiest, fastest way is to monitor
one’s health status at least periodically.
of PLI, while in [2] the removal of the baseline wondering
To successfully diagnose the health condition, specialized
was studied.
equipment and data processing are needed. Electrocardiogra-
phy is the process of monitoring the heart’s electrical activity II. N OISES CONTAMINATING THE ECG SIGNAL
over a period by placing electrodes on the skin. A single cycle
of the electrocardiogram represents the successive atrial and A. Power Line Interference
ventricular depolarisation and repolarisation. An ideal ECG The PLI of 50 Hz (and harmonics) is the source of inference.
signal is shown in Fig 1, where the first graph shows the ECG This inference is caused by poorly shielded nearby machin-
signal in the time domain with its characteristic intervals, while ery’s electromagnetic field, the stray effect of alternating
the second graph shows the same ECG signal in the frequency current fields due to cable loops and/or trace loops on the
domain using the discrete Fourier-transform. On the frequency ECG circuit, improper grounding of ECG machine or patient,
graph, we can see the complexity of a clean ECG signal. The etc.
ECG signals being very sensitive and weak in nature are highly As it is shown in Fig 1, the ideal ECG signal has important
prone to even small noise, some of the typical interferences information at 50 Hz and above, so leaving the PLI or cutting
are baseline wander (BLW), power line interference (PLI), out the frequency band above 50 Hz will distort the signal
electromyographic noise and electrosurgical noise. (especially the QRS complex).
Filtering is the way of removing undesired signals (noises)
from the primary signal. For every well distinguishable noise, B. Base line wondering
a filter has to be designed to remove or attenuate it. For In BLW the isoelectric line of the ECG signal changes
example in [1] a new algorithm was devised for the removal its position. There are multiple causes for this artifact, like
Amplitude (mV)

3 1

2.5

noisy ECG data Ricker waveler

Amplitude (1)
0.8

0.6
1.5

1
0.4

0.5

0.2
0

-0.5 0

-1
-0.2

-1.5
0 2 4 6 8 10 12 14 16 18 20

-0.4

Time (s) -5 -4 -3 -2 -1 0 1 2 3 4 5

Time (1)
Fig. 2. ECG signal contaminated with PLI and BLW noises. (a)

Amplitude (1)
1

moving cables, patient movement, loose electrodes, or the 0.8

0.6 Morlet wavelet


change of skin impedance due to sweating [3], etc. This artifact 0.4

0.2

is manifested as a low-frequency additive noise. 0

-0.2

-0.4

III. WAVELET TRANSFORM BASED FILTERING -0.6

-0.8

A. The wavelet transform -1


-5 -4 -3 -2 -1 0 1 2 3 4 5

The classic operation to transform a stationary signal from Time (1)


time domain to frequency domain was the Fourier transform (b)
shown in (1). Fig. 3. Ricker (Mexican hat) and Morlet continuous wavelets.
Z ∞
X(f ) = x(t)e−2πjf t dt (1)
−∞
wavelet filter coefficients are given by the chosen mother
The downside of the Fourier transform is the loss of the wavelet, the scaling and wavelet filters (LPF and HPF) are
time domain properties; another downside is that the transform related by equation 3, where LPF is the wavelet or lowpass
gives reliable results only if it is applied to stationary signals. filter vector, HPF is the scaling or highpass filter vector, L is
The short-time Fourier transform (STFT) was developed to the length of the vector, while k is the numeral of elements
show accurate time-frequency representation, see [4]. The time k = 0..(L − 1). Besides the filtering, downsampling is used
resolution must be increased with the central frequency of the (by the factor of 2). When a signal has passed through the
analysis filter to counter the resolution limitation of the STFT. two filters and down-sampled, the result is called one level
This resolution change at different frequencies is obtained by wavelet transform. The results are the detail coefficients (d)
Wavelet packets. The continuous wavelet transform (CWT) and average coefficient (a). These coefficients are used for
is a linear operation that follows the mentioned ideas, while signal filtering and compressing [8].
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 HP F [k] = (−1)k LP F [L − k] (3)
the mother wavelet 3, with wavelets delayed τ , and dilated a. If the data rate of the input signal is Ts, then the data rate
Some of the wavelets used for the CWT are Poisson, Morlet, of the coefficients will be as it is shown in Table I, in the case
Ricker, and Meyer wavelets, see for example in [5], [6], [7]. of a level 3 decomposition see (Fig 4).
Z ∞
1 t−τ
CW Tx (τ, α) = √ x(t)h( )dt (2) TABLE I
α −∞ α
D ATA RATE OF THE OUTPUT COEFFICIENTS OF THE THREE - LEVEL DWT
B. The discrete wavelet transform DECOMPOSITION .

The discrete wavelet transform (DWT) uses filter banks Levels Level 0 Level 1 Level 2 Level 3 Level 3
for the construction of the multiresolution analysis, which x[n] d1[n] d2[n] d3[n] a3[n]
Rates Ts Ts/2 Ts/4 Ts/8 Ts/8
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- The discrete wavelet reconstruction or inverse wavelet trans-
plies the scaling function. This scaling function, implemented form (IDWT) has the same structure, but the down-sampling
with filter coefficients LPF (the scaling function behaves as is replaced by up-sampling.
a low-pass filter), provides the approximation of the signal,
while the wavelet function (HPF - behaves as a high-pass C. Wavelet thresholding
filter) gives the detail coefficients. The cut-off frequency of If orthogonal wavelets with periodic boundary were used
the filters is the half bandwidth of the input signal I. The in the DWT, then the white noise would be unaltered after
1

0.8

Output (1)
0.6

0.4

0.2

-0.2

-0.4
original signal
-0.6 hard threshold
-0.8 soft threshold
Fig. 4. Wavelet tree (Mallat’s algorithm) of DWT for a three-level decom- -1
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1

position.
Input (1)
Fig. 6. Hard and soft threshold representation on a linear input signal.
Amplitude (1)

1.5

1
Haar wavelet
0.5 (
x[k], if |x[k]| > λ
θλ0 (x[k]) =
0

(4)
-0.5
0, otherwise
-1
 
λ
θλ1 (x[k]) = max 0, 1 −
-1.5
0 0.2 0.4 0.6 0.8 1 1.2
(5)
Time (1) |x[k]|
(a) 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
Amplitude (1)

1.5

1
Daubechies' wavelet was proposed in [10], the scheme was based on the explicit
0.5
form of Stein’s unbiased risk estimate (SURE) - (6), where
0
Crd denotes cardinality. The threshold λ should be chosen by
-0.5
minimizing SURE (7).
-1
0 1 2 3 4 5 6 7

n
Time (1) SU RE(λ, x) = n +
X
[min(|x[i]|, λ)]2
(b) i=1
− 2 ∗ Crd(i : |x[i]| < λ) (6)
Amplitude (1)

1.5

1 Coiflet wavelet
0.5
λ∗ = argmin0≤λ≤√2log(n) SU RE(λ, x) (7)
0

According to [10] the final form of the threshold should be


-0.5
chosen as shown in (9), where νs (x) is the sparsity of the
-1
0 5 10 15 20 25 coefficients shown in (8).
Time (1)
(p
(c) 2log(n), if νs (x) ≤ 1
λShureShrink (x) = ∗
(8)
Fig. 5. In this figure some discrete wavelets are shown: The basic Haar λ , otherwise
wavelet(a), Daubechies’ wavelet (b), and Coiflet wavelet
Pn
1 (x2 [i] − 1)
νs (x) = s− 2 i=1 3 (9)
log22 n
transformation, and it will be present in every wavelet co- IV. T HE APPLICATION OF DWT TO ECG FILTERING
efficient. The wavelet coefficients of a signal are sparse, so The DWT based filtering of a signal is done with the
most of the coefficients of a noiseless signal are close to signals detail and average coefficients, so the first step is to
zero. Therefore the problem of recovering the noiseless signal generate the wavelet coefficients. The second step is to scale
can be reformulated as one of recovering the coefficients that the coefficients based on the thresholding methods mentioned
are stronger than the noise background. This can be done by above. The final step is to recreate the signal from the
thresholding. coefficients with IDWT.
Thresholding is a nonlinear, diagonal operator, which only • To generate the wavelet coefficients the DWT is applied
passes through the input signal if the amplitude is greater than conform Mallat’s algorithm shown in Fig 4. The HPF
a given value (threshold). The most important thresholding op- and LPF kernels can be generated while choosing the
erators are hard (4) and soft thresholding (5). Soft thresholding appropriate mother wavelet. The Haar wavelet (Fig 5,
gives smoother results, while hard thresholding provides better a), is the simplest orthogonal wavelet basis. It’s exactly
edge preservation. reversible without the edge effects of other wavelets,
Amplitude (mV)

2.5

2
noisy ECG data
1.5

0.5

-0.5

-1

-1.5
0 2 4 6 8 10 12 14 16 18 20

Time (s)
Fig. 7. ECG signal with BLW, PLI, and HF noises added. Fig. 8. Complete ECG signal filtering system with cascaded filter blocks.

memory efficient. It uses only two scaling and wavelet P 


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

1.6
TABLE II
1.4 original ECG SNR OF THE ECG SIGNAL WITH THE DIFFERENT FILTERING METHODS .
1.2

1 filtered ECG
0.8 Filter Algorithm SNR MSE
0.6

0.4
algorithm complexity (dB) (mV)
0.2 Raw signal - 6.8134 -
O(N ) = N lg(N )
0

-0.2
All FIR 24.1539 0.0847
-0.4
filters 2000, 1114, 245 taps
0 1 2 3 4 5 6 7 8 9 10
All IIR O(N ) = N lg(N ) 20.4868 0.0249
Time (s) filters 3, 24, 31 order
Wavelet O(N ) = N lg(N ) 30.5355 9.42 ∗ 10−4
Fig. 9. ECG signal filtered with FIR high-pass, band-stop, and low-pass filter thresholding 10,10
stages.

Amplitude (mV)
3

Raw ECG signal


Amplitude (mV)

2.5

2 2

1.5 Original ECG 1.5 BLW residual signal


1

1 Filtered ECG 0.5

0
0.5
-0.5

0 -1

-1.5
-0.5 0 1 2 3 4 5 6 7 8 9 10

-1
0 1 2 3 4 5 6 7 8 9 10 Time (s)
Time (s) (a)
Amplitude (mV)
Fig. 10. ECG signal filtered with IIR high-pass, band-stop, and low-pass filter 0.6

stages.
0.4 Denoised ECG signal
0.2
Amplitude (mV)

0
2.5

2
Noisy ECG -0.2

1.5

1
a10 Wavelet approximation -0.4

-0.6
0.5 0 1 2 3 4 5 6 7 8 9 10

-0.5
Time (s)
-1
(b)
-1.5
0 10 20 30 40 50 60

Fig. 12. In figure (a) The raw ECG signal sampled with the SoC is shown,
Time (s) and the BLW residual signal from the first part of the filtering algorithm,while
(a) in figure (b) the filtered signal is shown.
Amplitude (mV)

1.5 original ECG VI. E XPERIMENTAL RESULTS


filtered ECG
1
The proposed method was implemented in a ZYNQ7 SoC
0.5

(System on Chip) form Xilinx. This SoC has a Programmable


0

-0.5
Logic section (PL) and a Processing System Section (PS)
-1
embedded together. An IP core was generated with HDL
0 1 2 3 4 5 6 7 8 9 10

coder based on the wavelet filtering method mentioned above


Time (s) (written in C++). The IP Core was then exported to Vivado
(b) and tested on real-time data. The hardware was designed as
Fig. 11. In figure (a) the noisy ECG signal is shown with the 10th order follows (shown in Fig 13):
wavelet approximation, while in figure - the artificial BLW sine function is
reconstructed (b) the original ECG signal is compared with the filtered ECG 1) The PS acquires data from the SPI ADC (Analog to
signal. 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
average coefficient a10 are calculated). The average coefficient remove the BLW, then applies the second DWT/IDWT
contains only the BLW as shown in Fig 11 (a), so it will with thresholding to remove the PLI and HF noises.
be set to 0, while the detail coefficients will be thresholded After the filtering is done, the data is sent back to the
with the soft SURE method. After thresholding, a wavelet PS.
reconstruction is used to generate the filtered data. The result 3) The PS sends both the clean and noisy data to the
can be seen in Fig 11 (a), and the SNR was 30.5355 dB, PC through UART communication, where it can be
which is better than the SNR achieved with the classic filtering evaluated.
methods. 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 [7] V. J. Samar, H. Begleiter, J. O. Chapa, M. R. Raghuveer, M. Orlando,
different mother wavelet properties and thresholding methods. and D. Chorlian, “Matched meyer neural wavelets for clinical and
experimental analysis of auditory and visual evoked potentials,” in 1996
The implemented IP core manages to filter the signal under 8 8th European Signal Processing Conference (EUSIPCO 1996), Sept
ns, with 200 MHz PL clock source, but the processing time 1996, pp. 1–1.
can further be improved by pipelining the algorithm, unrolling [8] B. A. Rajoub, “An efficient coding algorithm for the compression of ecg
signals using the wavelet transform,” IEEE Transactions on Biomedical
loops, and using Stream interface with DMA (Direct Memory Engineering, vol. 49, no. 4, pp. 355–362, April 2002.
Access) instead of AXI Lite interface. [9] D. L. Donoho and I. M. Johnstone, “Ideal spatial adaptation by wavelet
shrinkage,” Biometrika, vol. 81, pp. 425–455, 1994.
VII. C ONCLUSION [10] ——, “Adapting to unknown smoothness via wavelet shrinkage,” JOUR-
NAL OF THE AMERICAN STATISTICAL ASSOCIATION, pp. 1200–
The proposed Wavelet thresholding method not only suc- 1224, 1995.
cessfully removed the BLW, PLI, and HF noises from the [11] A. L. Goldberger, L. A. N. Amaral, L. Glass, J. M. Hausdorff, P. C.
sampled ECG signals. A SoC hardware implementation was Ivanov, R. G. Mark, J. E. Mietus, G. B. Moody, C.-K. Peng, and H. E.
Stanley, “PhysioBank, PhysioToolkit, and PhysioNet: Components of a
proposed to verify the usability of the algorithm, based on new research resource for complex physiologic signals,” Circulation, vol.
which the favorable conclusion is drawn, the algorithm can be 101, no. 23, pp. e215–e220, 2000 (June 13), circulation Electronic Pages:
implemented in hardware and can be used in real time, requires http://circ.ahajournals.org/content/101/23/e215.full PMID:1085218; doi:
10.1161/01.CIR.101.23.e215.
less computation than conventional FIR and IIR filters and the
same attenuation can be achieved with less filtering stages.
R EFERENCES
[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.

You might also like