ECG Signal Denoising Using Adaptive Unscented Kalman Filter
ECG Signal Denoising Using Adaptive Unscented Kalman Filter
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.
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
0.6
TABLE I
0.4
-0.2
-0.4
III. SIMULATION RESULTS 0 200 400 600 800 1000 1200 1400 1600 1800 2000
0.06
As, we can see from the figure 4 the proposed AR-UKF 0.04
0.02
-0.02
-0.06
0 200 400 600 800 1000 1200 1400 1600 1800 2000
containing output SNR and output MSE. These 4 set of plots -0.02
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
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.