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

ECG Signal Denoising Using Adaptive Unscented Kalman Filter

Copyright
© © All Rights Reserved
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)
91 views6 pages

ECG Signal Denoising Using Adaptive Unscented Kalman Filter

Copyright
© © All Rights Reserved
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

ECG Signal Denoising using Adaptive Unscented

2022 IEEE Conference on Interdisciplinary Approaches in Technology and Management for Social Innovation (IATMSI) | 978-1-6654-7719-2/22/$31.00 ©2022 IEEE | DOI: 10.1109/IATMSI56455.2022.10119404

Kalman Filter
Agniva Dutta Dr. Manasi Das
School of Mechatronics and Robotics School of Mechatronics and Robotics
IIEST Shibpur IIEST Shibpur
Kolkata, West Bengal, India Kolkata, West Bengal, India
[email protected] [email protected]

Abstract—Electrocardiography (ECG) is the most popular framework suffer from two main drawback i.e. choosing the
non-invasive method for generating an Electrocardiogram which right mother wavelet for different types of ECGs is a time
contains some very interesting information about the electrical consuming and non-accurate method, and also computing
and myographic activities of the heart. It is a graph of voltage
vs. time of the electrical activity of the heart using electrodes the wavelet detail and approximate coefficients is a highly
connected on the skin in various configurations. Due to the computation intensive job with high time complexity and the
noninvasive nature of ECG and also due to capacitive or inductive community is requiring faster denoising methods. In the paper
coupling in this electrical circuit for ECG acquisition or electro- [2] a denoising framework based on digital hanning filter along
myographic noises due to muscles adjacent to heart there is with R peak detection using Discrete Wavelet Transform is
usually significant noises present in a typical ECG which makes
it harder to analyze. There are many methods for denoising proposed, but the problem with this method is that digital
ECGs. In this paper an adaptive unscented Kalman filter, where filters could not perform well based on improvement of SNR,
the measurement noise covariance matrix is varied adaptively, is especially if the EMG noises are more in the ECGs. The other
used for denoising acquired discrete ECG signals. The filtered issue with this method is that the Discrete Wavelet Transform
output as well as the improvement of SNR is compared with other is a high computation intensive task, as we have to compute the
existing denoising frameworks like discrete wavelet transform
and digital filters and extended Kalman filter, and unscented wavelet coefficient in each decomposition level, in the paper
Kalman filter. The Adaptive Unscented Kalman Filter performed they used 4 decomposition layers of Undecimated Wavelet
better than the aforementioned existing filtering algorithms in Transform, where the 4 detailed coefficients are computed
terms of maximum output SNR and MSE computed using Monte along with an approximation coefficient in the last stage.
Carlo simulation. This has significantly high time complexity compared to other
Index Terms—ECG denoising, Adaptive Kalman Filter, Un-
scented Kalman Filter, Adaptive Unscented Kalman Filter, Ex- algorithms like Bayesian Filters. The bayesian filters like
tended Kalman Filter, Discrete Wavelet Transform extended kalman filters [3] and Marginalized Particle Extended
Kalman Filter [4] can be used for denoising ecgs, which uses a
I. I NTRODUCTION state space model of ECGs which was proposed by McSharry
et. al. [5] and Semani et. al. [3] and filter the noisy ECGs
ECG Denoising techniques are the most popular method
by estimating the state vector using previous state values. To
since ECG is a non-invasive method and this sort of non-
represent the ecgs Mc.Sharry et. al. [5] used 3 states where the
invasive methods picks up several types of noises [1], for
first two states represent the position around a limit cycle in (x,
example Baseline Wandering due to respiration activity of
y) plane and the third state represents the actual amplitude of
the patient during the ECG acquiring process, Power Line
the ecg. Semani et. al. [3] modified this model by using polar
Interference(PL) due to the Power Frequency (50Hz noise for
instead of cartesian coordinates, so instead of (x, y) only is
India or 60Hz for USA), Electrode Motion Artifact (EM) due
used. Using the ECG Dynamic Model [5] with 3 states as
to the movement or respiration of the patient, Muscle Artifact
shown below.
(MA) or EMG noise due to contraction of muscles near the
human heart that occurs during the diastolic pressure. For any
heart disease we first rely on ECG, because it does not harm ẋ = αx − ωy (1)
the patient as compared to other invasive methods. Simple ẏ = αy + ωx (2)
digital filters can remove electrical noises from ECG but most X Ai
 2
∆θi
of the noises are electromyography (EMG) noise especially ż = − ∆θi exp − − (z − z0 ) (3)
b2 2b2i
Muscle artifact, which changes the morphology of ECG thus i∈{P,Q,R,S,T } i
distorting the ECG. Simple digital filters fail to remove such p
Where α = 1 − x2 + y 2 , ∆θi = (θ − θi )mod(2π),
types of noises. Also the Wavelet Transform based denoising
θ = (y, x) (the four quadrant arctangent of the real parts
of elements x and y) , with −π ≤ (y, x) ≤ π , and ω is
the angular velocity of the trajectory around the limit cycle.

978-1-6654-7719-2/22/$31.00 ©2022 IEEE


Authorized licensed use limited to: De La Salle University. Downloaded on June 10,2024 at 12:49:25 UTC from IEEE Xplore. Restrictions apply.
The angular velocity is computed using a time series that is In the next part we will study the choosing scheme for the
called RR process. The RR process denotes the velocity around sigma points.
the limit cycle as shown in the Figure 1. In the paper [?]
they implemented an EKF which uses the Mc.Sharry model A. Sigma Points
described in equations (1-3) after discretising and linearizing We first need to select some points based on significance
these equations. But they have some limitations. As ECG from the input distribution [?]. There is a set of equations that
signal is a nonlinear signal and EKF requires a linearized the sigma points and their weights must satify in order to get
approximation of the nonlinear model, we need to linearize the the algorithm working. According to the theorem[] we have
ecg dynamic model using 1st order taylor series approxima- to choose Xi , Wi suchthat
tion. This process is very computation intensive as it requires
the computation of the Jacobian matrices in each iteration of X
the filter algorithm. Also EKF does not perform well if the Wi = 1 (4)
∀i
nonlinearity in the system is more, especially in each of ecgs. X
We can skip the linearization step by utilising the unscented µ= Wi Xi (5)
transform on some carefully selected points called sigma ∀i
X X
points, using the nonlinear transformation function itself. = Wi (Xi − µ)(Xi − µ)T (6)
This is shown in Methodology section. In the paper [?] they ∀i
used a UKF for denoising ECGs. But this denoising model also Solving the equations 4-6 we have to choose Xi and Wi .
has some issues, As the process noise covariance matrix does We see that these 3 equations are not bounded, hence they
not adaptively change based on the ECG being processed there don’t have a unique solution. Thus there is no unique choice
is a significant peak distortion near the R peaks, which changes of sigma points either. There are many schemes for choosing
the peak amplitude at the R peak. Also the measurement noise sigma points, one of which having a total of 2N sigma points
covariance matrix is fixed, thus it cannot perform equally well are used here.
for all different types of noises. 1) Choosing sigma points: Considering the state dimen-
Hence, we simulated an adaptive unscented kalman Filter tionality as N we can choose 2N+1 sigma points as
where the measurement noise covariance will vary depending
on squared error. We used the adaptive estimation method X0 = µ (7)
for measurement noise covariance from the paper [?]. The
q X
textitmethodology section the process is stated elaborately. All Xi = µ ± (n + λ) (8)
i
the results with filtered output and comparison of SNR with
previous methods are written in the simulation results section. Where i ∈ 1, · · · , n , µ is the mean of the input distribution, λ
The conclusion section has the sumamry of the simulation is a scaling parameter, i is the column vector, and the √ square
results along with scope of improvement in this algorithm. root here is the cholesky square root(If A = SS T then √A =
S) as the diagonalized square root(If A = S · · · S then A =
II. METHODOLOGY S) is unstable. Here we chose the mean as one sigma point
In this section the filter algorithm and the structure of and chose N sigma points at either side of the mean. Now we
the filter is stated. As discussed before, the filter is based also need to calculate the weights associated with these sigma
on Unscented Kalman Filter. First we discuss the Unscented points.
Transform, and then the UKF structure and the adaptive 2) Choosing weights: There are two set of weights, for
estimation part. the mean and the covariance computation we need to set of
As the linearization using Taylor series approximation is weights denoted by Wi,m and Wi,c . They are computed as
a tedious job, where offline computation of the structure of
the Jacobian matrices and online computation of the matrices λ
during each iteration of the filter algorithm is required. We W0,m = (9)
n+λ
can eliminate this linearization process by applying a better 1
method for denoising, the unscented kalman filter. The un- Wi,m = i ∈ 1, · · · , 2n (10)
2(n + λ)
scented kalman filter uses a technique called unscented trans- W0,c = W0,m + (1 − α2 + β) (11)
form where we apply the nonlinear state transition function
1
on some points from the input distribution which are chosen Wi,c = i ∈ 1, · · · , 2n (12)
carefully. The propagation is called Unscented Transform and 2(n + λ)
the chosen points are called Sigma points Where,
Hence The unscented transformation (UT) is a method for κ ≥ 0 (κ is the scaling parameter)
calculating the statistics of a random variable which under- α ∈ (0, 1] (Spread around x̄)
goes a nonlinear transformation [?]. The transformation is a λ = α2 (n + κ) − n κ, α, λ togather decides the spread of the
weighted transformation that means all the points does not sigma points from the mean of the Gaussian.
have equal weightage. The weights also need to be computed. β = 2 is optimal for Gaussian distributions

Authorized licensed use limited to: De La Salle University. Downloaded on June 10,2024 at 12:49:25 UTC from IEEE Xplore. Restrictions apply.
B. Unscented Kalman Filter formed sigma points in equation 15, Using these transformed
After computing the sigma points and the weights the UKF points again we recompute the Gaussian for measurement
algorithm [?] is implemented where the predict step is the model in equation 16. Now using the weights for covariance
computaion of the mean and then computation of sigma points we compute the innovation in equation 17. In equation 18
and weights and then computing the covariance matrix. The we compute the cross covariance between the two gaussians,
update step consists of propagating the sigma points through for the state model and the measurement model with mean
measurement function and computing the estimated output, the at µ̄t and z¯t . After that we compute the kalman gain and the
innovation, the cross covariance matrix, the kalman gain and aposteriori mean and aposteriori covariance. Using this we can
the estimated state and covariance matrices. The algorithm is get a filtered output as shown in the Figure 3
stated in two stages as below.
After computing the sigma points and the weights the C. Adaptive Unscented Kalman Filter
UKF algorithm is implemented where the predict step is the
From the plot it is perfectly clear that there is a peak
computaion of the mean and then computation of sigma points
distortion at the R peaks in the filtered ECGs. Because of
and weights and then computing the covariance matrix. The
this the peak to peak amplitude of ECG is reduced after
update step consists of propagating the sigma points through
filtration. Also we can see there is still some noise present
measurement function and computing the estimated output, the
in the ECG [?]. We ran monte carlo simulation using UKF
innovation, the cross covariance matrix, the kalman gain and
which is decribed in the simulation results section and obtained
the estimated state and covariance matrices. The algorithm is
maximum output SNR of 45.3716 db. Now, we are trying to
stated in two stages as below.
improvise the situation. The process noise covariance matrix
1) Predict step:
Q is a diagonal matrix which represents the covariance of
2n
X the 3 states of the ECGs. We assumed the elements of the
µ̄t = wi,m f (Xt−1,i , ut ) (13) diagonal are same, that is the covariance of all the states
i=0
are same. We also assumed in UKF that the covariance is
X0 =µ constant throughout the estimation process. Here lets make
q X the covariance adaptive, so that at each iteration, based on the
Xi =µ± (n + λ)
i overall error in estimation in a time window, the covariance
X2n adapts itself. Thus we assume a window size, and compute
T
Σ̄t = wi,c (f (Xt−1,i , ut ) − µ̄t ) (f (Xt−1,i , ut ) − µ̄t ) + Qt the total error in estimation in that time window as
t=0
(14)
n
X
First the sigma points from the previous iteration is prop- e= (ECGnoisy (k − i) − ECGestimated (k − i)) (22)
agated through the state transition function f () which is i=1
nonlinear function. Then we recompute the Gaussian using 1
the weights and the transformed sigma points and compute hk = (e ∗ e) (23)
N
the mean of the output Gaussian. After that we compute the
new set of 2N+1 sigma points for the current iteration and then Here, a window size is needed in equation 22 as the value of
recompute the covariance using covariance weights which are n. We ran an optimization on this parameter found an optimal
also computed in this step. value of window size as 20, which gives best results in terms
2) Update step: of output SNR and MSE. The measurement noise covariance
matrix is adjusted using equation 25 in the update stage.
Zt = g(Xt , 0) (15)
2n
X
zˆt = wi,m Zi,i (16) Qk = Kk ∗ Hk ∗ KkT (24)
i=0 −
2n Rk = hk − Ck ∗ P ∗ CkT
X T
St = wi,c (Zt,i − zˆt ) (Zt,i − zˆt ) + Rt (17) => Rk = |hk − S| (25)
i=0
X2n As ECG is a nonlinear signal containing both low frequency
T
Σ̄t,xz = wi,c (Xt,i − µ̂t ) (Zt,i − zˆt ) (18) and high frequency segments, improper selection of process
i=0 noise covariance matrix, which is fixed, may lead to distortion
Kt = Σ̄t,xz St−1 (19) in the filtered signal. Hence, we calculated the optimal value
µt = µ̄t + Kt (zt − z̄t ) (20) for the process noise covariance matrix, by experiment. Using
this value of process noise covariance matrix, we varied
Σt = Σ̄t + Kt St KtT (21)
measurement noise covariance matrix at each step, to filter
In this step we propagate the the sigma points of the current ECG with different measurement noises and added synthetic
iteration using the measurement function g() to get trans- measurement noises.

Authorized licensed use limited to: De La Salle University. Downloaded on June 10,2024 at 12:49:25 UTC from IEEE Xplore. Restrictions apply.
SIG SN R M SE
DWT 24.8094 3.2728x10−6
EKF 25.5657 1.3586x10−6 1.2

UKF 27.3067 2.8025x10−6 1

AUKF 29.6039 4.0628x10−7 0.8

0.6

TABLE I
0.4

SNR AND MSE OBTAINED FROM M ONTE C ARLO S IMULATION


0.2

-0.2

-0.4

III. SIMULATION RESULTS 0 200 400 600 800 1000 1200 1400 1600 1800 2000

In this section, simulation of Digital Filter, EKF, UKF, and


Adaptive UKF are carried out to compare the results and find Fig. 1. Limit cycle and Synthetic ECG
out the performance improvement in the adaptive UKF. In the
figure below we can see the images as pure ecg database, ecg
with added measurement noise, filtered output of digital filter,
ekf, ukf and adaptive ukf respectively. 0.08

0.06

As, we can see from the figure 4 the proposed AR-UKF 0.04

0.02

outperforms all the previous denoising models. We also run a 0

-0.02

Monte Carlo simulation with 50 epoches to obtain the output -0.04

-0.06
0 200 400 600 800 1000 1200 1400 1600 1800 2000

SNR and calculated average SNR at a specific sample with 0.06

different Additive White Gaussian Noise, to generate a output 0.04

SNR plot as shown in Figure 5. There are 4 set of plots 0.02

containing output SNR and output MSE. These 4 set of plots -0.02

are shown in figure 5. Here, we generated different AWGN -0.04


0 200 400 600 800 1000 1200 1400 1600 1800 2000

noises for 100 iteration and used all the 100 filtered outputs
to calculate the SNR and MSE. As there are some dips in the
SNR and MSE plot, we considered the maximum SNR and Fig. 2. Noisy ECG and Filtered ECG with UKF
the minimum MSE.
The maximum SNR, average SNR, minimum MSE and
average MSE for this Monte Carlo simulation is shown in
the Table 1. As we can see from the table the Adaptive UKF
performs better that all the previous denoising methods.
From the table1 it is clear that the maximum SNR and
Minimum MSE is reached by the AUKF among the other
methods. We can plot the SNR and MSE obtained by Monte
Carlo simulation as shown in Figure 5.
We ran monte carlo simulation for 100 iteration for 2000
samples of ECGs. The equations used to calculate SNR and
MSE are stated in equations 26-27. As discussed before the
optimal value of process noise covariance is also required,
we calculated it by experimenting with different values of Fig. 3. Noisy ECG
covariances and the process noise covariance vs SNR plot
is shown in Figure 8. The optimal value of process noise
covariance obtained was 0.018 and used this value in the AR-
UKF model.

(i) Pecg
SN Rout = 10 ∗ log10 P  2
100 (i,j)
j=1 ECG(i) − ECGf iltered
(26)
P100  2
(i,j)
j=1 ECG(i) − ECGf iltered
(i)
M SEout = (27)
N
In this figure we can see that for a value of 0.018 of process Fig. 4. Noisy ECG
noise covariance, we obtained the maximum SNR. In Figure

Authorized licensed use limited to: De La Salle University. Downloaded on June 10,2024 at 12:49:25 UTC from IEEE Xplore. Restrictions apply.
Fig. 5. Noisy ECG

Fig. 9. SNR comparison

9 we can see that our Adaptive UKF performs better than that
of the other models discussed.
IV. CONCLUSIONS
The model mainly focuses on resolving some problems
with previous models. The computation extensive step for
linearzing and computing jacobian matrices for EKF is not
required in this model. Also the model performs better with
different types of ECGs especially abnormal ECGs like Car-
Fig. 6. Noisy ECG
diac Arrhythmia. The results we obtained are with ECG having
Cardiac Arrhythmia, which is a irregular ECG, that does not
fully resemble pure ECG Dynamic Model. The advantage
of using R adaptation is that it deals with measurement
uncertainties, by estimating R using past samples within a time
window of a specified size. We chose window size of 20 as
optimal to obtain best results. This model R estimation helps
in denoising various measurement noises, especially EMG
noises.
R EFERENCES
[1] M. V. D. Mr. Hrishikesh Limaye, “ECG Noise Sources and Various
Noise Removal Techniques: A Survey”, International Journal of Ap-
plication or Innovation in Engineering Management (IJAIEM), vol. 5,
February 2016.
Fig. 7. Noisy ECG [2] V. S. N. Rashmi, Ghousia Begum, “ECG Denoising using Wavelet
Transform and Filters”, IEEE WiSPNET 2017 conference, 2017.
[3] C. J. R. Semani, M.-B. Shamsollahi, M. Babaie-Zadeh, “Filtering noisy
ecg signals using the extended kalman filter based on a modified
dynamic ecg model”, In Computers in Cardiology, pp. 1017–1020, 2005.
[4] H. Hesar, M. Mohebbi, “ECG Denoising Using Marginalized Particle
Extended Kalman Filter with an Automatic Particle Weighting Strategy”,
IEEE Journal of Biomedical and Health Informatics,vol.21,pp.635– 644,
2016.
[5] L. T. P. E. McSharry, G. D. Clifford, L. A. Smith, “A dynamical model
for generating synthetic electrocardiogram signals”, IEEE Transactions
on Biomedical Engineering, vol. 50, no. 3, pp. 289–294, 2003.
[6] C. J. G. D. C. Reza Sameni, Mohammad B. Shamsollahi, “A Nonlinear
Bayesian Filtering Framework for ECG Denoising”, IEEE Transactions
on Biomedical Engineering, vol. 54, December 2012.
[7] S. U. Cory T. Fraser, “Adaptive Extended Kalman Filtering
strategies for spacecraft formation relative navigation”,
https://doiorg/101016/jactaastro202010016 , Received 21 July 2020;
Accepted 8 October 2020, 21 July, 8 October 2020.
[8] G. A. Terejanu, “Unscented Kalman Filter Tutorial”, Department of
Fig. 8. SNR vs Process noise covariance
Computer Science and Engineering University at Buffalo, Buffalo, NY
14260 terejanu@buffaloedu, 2005.

Authorized licensed use limited to: De La Salle University. Downloaded on June 10,2024 at 12:49:25 UTC from IEEE Xplore. Restrictions apply.
[9] E. A. Wan, R. van der Merwe, “The Unscented Kalman Filter for Non-
linear Estimation”, Oregon Graduate Institute of Science Technology
20000 NW Walker Rd, Beaverton, Oregon 97006 ericwan@eceogiedu,
rvdmerwe@eceogiedu, This work was sponsored by the NSF under grant
grant IRI-9712346, 2016.

Authorized licensed use limited to: De La Salle University. Downloaded on June 10,2024 at 12:49:25 UTC from IEEE Xplore. Restrictions apply.

You might also like