Abstract
Cardiac diseases constitute a major root of global mortality and they are likely to persist. Electrocardiogram (ECG) is widely opted in clinics to detect countless heart illnesses. Numerous artifacts interfere with the ECG signal, and their elimination is vital to allow medical specialists to acquire valuable statistics from the ECG. The utmost artifact that is added to the ECG signal is power line interference (PLI). Numerous filtering methods have been employed in the literature to eliminate PLI from noisy ECG. This article proposes an extended Kalman filter (EKF)-based adaptive noise canceller (ANC) that comprises PLI frequency as a distinct model parameter. Thus, it is capable of tracking PLI with drifting frequency. The proposed canceller's performance is compared with state-space recursive least squares (SSRLSs) filter-based PLI canceling. The evaluation is carried out for four cases of PLI, that is, PLI with known amplitude and frequency, PLI with unknown amplitude and frequency, PLI with drifting amplitude and frequency, and PLI removal from a real-time ECG recording. The samples of the Massachusetts Institude of Technology (MIT)-Boston's Beth Israel Hospital (BIH) arrhythmia database are considered for the first three cases, whereas, for the fourth case, real ECG signal is taken from armed forces institude of cardiology, the national institude of heart diseases (AFIC/NIHD), Pakistan. Mean square error, frequency spectrum, and noise reduction are selected as performance metrics for comparison. Simulation results depict that the presented EKF-based ANC system outperforms the SSRLS-based ANC system and effectively eliminates PLI from ECG under all four investigated scenarios.
Introduction
Physicians consider an electrocardiogram (ECG) to diagnose numerous cardiovascular maladies for checking the heartbeat's electric activity. The individual cycle of this electrical activity entails T wave, Q, R, and S waves (QRS) complex, and P wave. Any variation in these quantities designates abnormal working of the myocardium.
Signal processing is considered to be the utmost precarious tool in biomedical engineering. Development in this field has been directed to proficient noninvasive diagnosis and virtual nursing of patients. Some artifacts that corrupt the ECG include baseline wander (BW), power line interference (PLI), and electromyography noise (EMG). Among all the most disturbing is PLI, which is the focus of research in this article. The spectral band of ECG signal (between 0.5 and 100 Hz) includes the frequency spectrum of PLI, that is, between 48 and 52 Hz, thus making PLI abolition from ECG critical. The ambition is to extract the degraded ECG signal without upsetting the spectrum/useful ECG signal statistics.
Many filtering techniques are reported in the past to eradicate these noises. 1 Finite impulse response (FIR) and infinite impulse response (IIR) filters are applied to ECG signals for eliminating PLI. 2 Butterworth filter is deployed to reduce PLI from a degraded ECG signal. 3 The IIR notch filter was used to remove PLI from ECG. 4 It was found that a notch filter can successfully remove PLI for a fixed frequency and fails for drifting frequency. However, these filters' performance is restrained in the presence of drifting frequency of PLI. 5
In the nonstationary environment, adaptive filters are utilized due to their ability to recursively upgrade their parameters. 6 Therefore, adaptive filters are used for overcoming this problem. Dhillon et al. 6 suggested an IIR adaptive notch filter (ANF) for removing noise from the real-time ECG signal. Different PLI mitigation algorithms are compared and result in improved algorithms' superior performance than notch filters and spectral interpolations. 7 Designing an optimal iterative learning solution is a big task for linear and nonlinear complex systems.8,9 For noise eradication from an ECG signal, adaptive noise annulment has become the utmost effective approach.
Therefore, in this research article, we have suggested an extended Kalman filter (EKF)-based adaptive noise canceller (ANC) system that incorporates PLI frequency as a distinct model parameter. Thus, it is capable of tracking PLI with drifting frequency as well. The cases under consideration are as follows: PLI with known amplitude and known frequency, PLI with unknown amplitude and unknown frequency, PLI with unknown drifting amplitude and unknown drifting frequency, and real-time PLI corrupted ECG. The comparison of the proposed solution with state-space recursive least square (SSRLS) algorithm-based ANC for the four different cases of PLI in terms of mean square error (MSE), noise reduction (NR), and the frequency spectrum is presented.
In the first three cases, both SSRLS and EKF are employed to remove MATLAB generated PLI from PLI corrupted ECG. In the fourth case, the real ECG signal is acquired from the Armed Forces Institute of Cardiology, the National Institute of Heart Diseases (AFIC/NIHD), Pakistan, and the earlier-mentioned adaptive algorithm is used to suppress PLI. Simulation results depict that the presented EKF-based ANC system outperforms the SSRLS-based ANC system and effectively eliminates PLI from the ECG signal against the earlier-mentioned four investigated scenarios.
This article is structured as follows: The Related Work section briefly describes the literature review of related work carried out. The Methods and Materials section explains the proposed mathematical model for PLI, the basic working mechanism of an ANC system, a mathematical model of literature-reported SSRLS-based ANC system, and a proposed EKF-based ANC system for PLI cancellation. The Simulation Results section suggests the PLI cancellation performance of the proposed EKF-based ANC system and its performance comparison with the SSRLS-based ANC system for all four PLI cases in terms of MSE, NR, and frequency spectrum. Finally, the Conclusion section concludes the article.
Related Work
When the PLI parameters are known, notch filters are the most appropriate solution. The IIR-based notch filters are preferred compared with other FIR and Butterworth notch filters due to their small filter order. However, the notch filters suffer from their impulse response's ringing effect due to narrow bandwidth and distorted frequency spectrum. 10 Further, a tunable notch filter was introduced, which could tune its frequency but could not trial variable frequency. 11 Thus, an ANF was designed to modify the tunable notch filter. 12 The least mean square (LMS) algorithm fits to this group.13,14
Another ANF of sharp resolution is reported for mitigating PLI from ECG signal. 15 The fast Fourier transform is done on the input signal in the proposed method. This proposed ANF method preserves the QRS complex features in filtered signals better than the conventional notch filter. The LMS algorithm is widely used but exhibits low convergence and wider bandwidth. Recursive least square (RLS) algorithm performs better than LMS and notch filters but at the cost of high computational complexity.
A novel method for ECG denoising using adaptive filters is designed for real-time application and relies on the upcoming ECG signal without the need for a reference noise signal. 16 The proposed solution's verification is done using three adaptive algorithms, that is, LMS, normalized NLMS, and Leaky LMS.
Another method, ANC was reported to eradicate PLI from the ECG. 17 Researchers found that ANC works efficiently in the case of fixed PLI parameters but behaves like a conventional notch filter when the PLI parameter was unknown. That is, ANC converges to some arbitrary PLI frequency. Maniruzzaman et al. 18 presented the LMS algorithm-based ANC for eradicating PLI from the ECG signal. Different variants of the LMS algorithm are investigated and compared.19–22 Further, Mugdha et al. 23 successfully suppressed PLI by testing and comparing the RLS algorithm with LMS. Biswas and Maniruzzaman 24 compared the NLMS adaptive filter performance and RLS adaptive filter with notch filter in both the time and frequency domain for PLI removal from ECG. The RLS exhibited better tracking than NLMS, but the signal-to-noise ratio (SNR) of NLMS was better.
Another technique was proposed by combining the moving average and conventional notch filtering. 2 This technique exhibited less complexity, small filter order, and ringing effect. However, important ECG data were lost in the buffering stage before filtering. Tong et al. introduced an ANC based on a lock-in amplifier. 25 In this technique, ECG was smoothened by the Hanning window method and then filtered by FIR notch filter. Further, this technique was modified and used to remove PLI noise from ECG. 26 The modification was the replacement of the FIR notch filter with wavelet transform, which produced better results while removing PLI from ECG.
Another technique was introduced, 27 which utilized averaging for ECG smoothening, and then the Kalman algorithm was used to confiscate PLI from ECG. A parabolic filter was implemented for denoising ECG. 28 The performance analysis exhibited good performance of parabolic filters in comparison to investigated filters.
Another technique proposed based on discrete wavelet transform and adaptive filtering is compared in the time and frequency domain with the existing notch filter for removing PL from the ECG signal. 29
Singhal et al. 30 proposed another less complex method based on the Fourier decomposition method (FDM) to separate both BW and PLI concurrently from the recorded ECG and acquire clean ECG data. The proposed method identifies the coefficients of discrete Fourier transform or discrete cosine transform regarding BW and PLI and then suppressed from optimally designed FDM based on a zero-phase filtering approach. The simulations verify the improved performance of the suggested method compared with other techniques at various SNR values. A hybrid method comprising median, Savitzky–Golay, and wavelet transform is proposed for NR from the ECG signal. 31 The simulations performed on different records from the standard Massachusetts Institute of Technology (MIT)-Boston's Beth Israel Hospital (BIH) arrhythmia database depicted an improved SNR by a proposed hybrid method compared with other reported techniques.
A nonlinear adaptive filter with less complexity was reported for removing PLI from ECG without an external reference signal. 32 Adaptive sinusoidal interference canceller is proposed, 33 where the frequency of sinusoidal noise is known. The Kalman filter (KF) was opted to eradicate PLI from ECG. 34 KF is designed for linear state transitions. Therefore, results achieved by KF for varying PLI frequency cases were not comparable with the existing adaptive filters.
Keshavamurthy and Eshwarappa 35 removed various artifacts from ECG by using an EKF and singular value decomposition. The reference noise affects the filtering performance of LMS and RLS algorithms. Mostly, it is difficult to procure extremely correlated original noise. However, state-space adaptive filters are independent of reference noise input.36,37 Researchers mitigated impulsive, BW, and PLI from degraded ECG by opting SSRLS.38–44 It is very effective in mitigating 50 Hz sinusoidal noise irrespective of information about adaptive filter parameters but at a cost of high complexity.
An EKF and genetic algorithm-based PLI elimination method from corrupted ECG is presented. 45 A genetic algorithm tunes the EKF parameters, and then the EKF algorithm is used to track two different cases of PLI, one with varying amplitude and the other with varying frequency. However, the research presented by Li et al. 27 only tested the proposal for two simulated PLI cases and provided no comments about its behavior on the signal acquired from a real ECG source.
A fixed lag EKF smoother (KS) is used to eradicate PLI from ECG. 46 The reported work is tested on simulated PLI as well as real ECG data having PLI, and a comparison with IIR Notch, LMS, and EKF algorithms is performed. However, the presented KS fails to track PLI with drifting frequency. We quote from, “Instead of assuming a fixed PLI frequency, for future work, it might be interesting to develop a KS for a model that includes the PLI frequency as a separate model parameter. Note, however, that in this case, the expression in Eq. (2) would no longer be valid, and the model becomes nonlinear.” 28
Methods and Materials
Noise modeling
To eliminate noise, adaptive filters require a mathematical model of the noise. This section explains the developed mathematical model for PLI. PLI may be modeled in continuous time as
where
Our proposed ANC uses two PLI models in series: first to compute the PLI frequency
PLI model for frequency
estimation
To track the frequency of PLI, we have modeled PLI frequency as a separate model parameter. Thus, the developed frequency estimation model is a 3rd-order model with three states in state space defined as:
The first-order differential equations of these states are calculated by taking the derivative of Eqs. (2.1–2.3):
These differential equations can be written in matrix form by taking Jacobian of the process model described by Eqs. (3.1–3.3).
From Eq. (4), the system state matrix of the PLI model is:
This system state matrix is used to calculate the state transition matrix using the following equation:
where
where A13 and A23 are:
PLI model for amplitude (
) estimation
To estimate the amplitude of PLI, the 2nd-order PLI model is developed, and the two states in state space are defined in continuous time as:
where fL is the frequency estimated from the frequency estimation model presented in the previous subsection. According to trigonometric identities, we know that:
Using trigonometric identities, considering
At time t = 0, Eq. (10) can be written as:
Using the results of Eq. (11), we can write Eq. (1) in matrix form as:ø
From Eq. (11), we can rewrite Eq. (12) as:
Converting Eq. (13) from continuous form to discrete form by replacing t with k on the left side and replacing t with kT on the right side of the equation, we may rewrite Eq. (13) as:
where k is the discrete-time index, and T is the sampling time.
For k = 1, Eq. (14) gives:
For k = 2, states can be calculated recursively by using Eq. (15).
Using Eqs. (9.1–9.2), we get
From Eq. (15), we can write Eq. (18) as:
For k = 3, we write Eq. (14) as:
Using Eqs. (9.1–9.2), we get
Using Eq. (16), Eq. (22) becomes:
From Eqs. (15–23), we can generalize the model as:
Hence, from Eq. (24), the state transition matrix for amplitude estimation will be:
Adaptive noise canceller
ANC is widely employed in biomedical signal processing. It removes various artefacts based on their adaptive algorithm. Figure 1 displays the elementary working of our proposed EKF-based ANC.

ANC block diagram. ANC, adaptive noise canceller.
As defined in Eq. (1), we must estimate
The ANC entails primary signal
SSRLS algorithm
The SSRLS algorithm-based ANC is reported in literature to eliminate PLI from ECG. The SSRLS algorithm computes PLI by using its sinusoidal state-space model.38–44 In this research work, performance comparison of the SSRLS-based ANC is carried out with our proposed EKF-based ANC for all four cases of PLI. The SSRLS is implemented in series; first, the frequency and then the amplitude of PLI is estimated. The sinusoidal model is provided to the SSRLS algorithm for frequency, and amplitude estimation is represented by Eqs. (7) and (24), respectively.
The PLI disturbance is modeled in state space as:
where A is calculated from Eq. (6) and C =
Form II of the SSRLS algorithm is precisely presented in Eqs. (28–33), and Table 1 depicts the description of variables involved in it. 32
Variables used in state-space recursive least square and extended Kalman filter
Extended Kalman filter
The EKF engages a sequence of measurements and considers that process and measurement to guess and approximate the states of the system. It has been considered as the most favorable solution to many estimation problems.
47
The EKF algorithm comprises two steps: prediction and correction. In the prediction step, states are propagated forward by using the nonlinear system model. The state prediction
where A is the state transition matrix, and QK is a positive definite matrix representing the covariance of the process noise.
In the correction step, the expected measurement is calculated by using the predicted states in the measurement model
The covariance matrices for EKF are calculated by using the following expressions:
where RK is the measurement noise that is equal to the variance of the corrupted ECG data that are collected from the sensor, QK is the process noise in the model used for state estimation,
The working of EKF is summarized. 37 The samples of the MIT-BIH database with a sampling frequency of 360 Hz are considered for the first three cases, whereas, for the fourth case, the sampling frequency is 820 Hz. The variables used in investigated algorithms in this article are listed in Table 1.
Simulation Results
The performance of EKF algorithm is tested and also compared with SSRLS for all four cases of PLI, which are:
Case 1: Known constant amplitude and frequency of PLI Case 2: Unknown constant amplitude and frequency of PLI Case 3: Unknown drifting amplitude and frequency of PLI Case 4: Real ECG signal taken from AFIC/NIHD Pakistan
The ECG data acquired for the first three cases from the MIT database are shown in Figure 2a after its amplitude normalization, 48 and its frequency spectrum is illustrated in Figure 2b. The parameter values used for simulations are tabulated in Table 2.

Simulation parameters of power line interference
All simulations are carried at the MATLAB platform. The performance metrics considered are NR, MSE, and frequency spectrum plots. The NR is calculated as:
where
Case 1: PLI of known constant amplitude and frequency
In this case, PLI noise of known and constant amplitude of 0.1 and a frequency of 50 Hz is added to the ECG signal. Figure 3a and b illustrate the simulated PLI and the corrupted ECG. The estimated ECG by EKF and SSRLS are depicted in Figure 3c.

The frequency spectrum of simulated PLI, noisy ECG, and recovered ECG after employing SSRLS and EKF for PLI reduction is shown in Appendix Figure A1. It is clear from Appendix Fig. A1 that EKF and SSRLS filter remove PLI from ECG with an approximately similar performance.
Numerous simulations are done to understand the behavior of governing parameters of pondered algorithms. From the simulation results, the chosen value of SSRLS forgetting factor (λ) is 0.99. The parameters of EKF algorithm are calculated by using Eqs. (39–40). It is clear from Figure 4a that the EKF performs slightly better than SSRLS as the SSRLS curve shows small oscillations for case 1. Moreover, Figure 4b depicts the MSE of both the investigated algorithms.

Comparison of
From Figures 3 and 4, it can be concluded that the estimation performance of EKF and SSRLS filter is almost the same for PLI with known constant amplitude and frequency. The SSRLS and EKF have estimated the ECG signal with minimal spectral distortion. However, owing to the higher computational complexity of EKF, SSRLS can be a preferred choice in this case. The amplitude and frequency estimation of PLI will be carried out for case 2 and onward.
Case 2: PLI of unknown amplitude and frequency
For case 2, PLI of unknown amplitude and frequency is added to the ECG. The PLI generated in MATLAB is further added to the pure ECG to obtain the degraded ECG in Figure 5.

The amplitude and frequency estimation of PLI considered in case 2 are depicted in Figure 5c and d. From Figure 5c, it can be verified that the amplitude estimation of EKF is better than SSRLS, but the frequency estimation of PLI is approximately the same for both SSRLS and EKF algorithms. The PLI-free ECG is acquired by deducting estimated PLI for case 2 from the noisy ECG, as depicted in Figure 5e.
It can be seen from the comparison of Figures 2 and 5e that EKF has a better amplitude approximation than that of SSRLS. The amplitude of estimated ECG using SSRLS is around 0.8, whereas the EKF-estimated ECG is nearly 1. Moreover, for case 2, the frequency spectrum of generated PLI and its estimation using SSRLS and EKF is depicted in Appendix Figure A2. It can be concluded that both algorithms for case 2 have estimated PLI to be approximately equal to the PLI that corrupts the ECG. Hence, both algorithms have removed the 49 Hz PLI from the degraded ECG. The frequency spectrum of noisy and estimated ECG using SSRLS and EKF algorithms for case 2 is illustrated in Appendix Figure A3.
From the simulation results for different forgetting factors of the SSRLS algorithm, the chosen value of the SSRLS forgetting factor (λ) for frequency and amplitude estimator is 0.99; covariance matrices of the EKF algorithm are calculated by using Eqs. (39–40). Under these conditions, both SSRLS and EKF algorithms are implemented and their NR and MSE curves comparison is shown in Figure 6.

Comparison of
Figure 6a depicts that EKF exhibits better performance by reducing noise to approximately zero with fewer oscillations as compared with SSRLS, which, however, reduces noise to zero but with high oscillations. Figure 6b shows that EKF has less MSE than that of SSRLS.
Case 3: PLI with drifting amplitude and frequency
In case 3, ECG is corrupted by PLI of varying frequency and amplitude. This drifting PLI is generated in MATLAB by concatenating two sinusoids of different frequencies (49 and 51 Hz), and amplitude (0.5 and 0.3) is depicted in Figure 7a. This simulated PLI is then added to the ECG to obtain the corrupted ECG and illustrated in Figure 7b.

Figure 7c and d shows the amplitude and frequency estimate of PLI considered for case 3 through SSRLS and EKF. It can be concluded from Figure 7c that the amplitude of estimated ECG using SSRLS is around 0.82, whereas the EKF-estimated ECG is around 0.9.
Moreover, for case 3, the frequency spectrum of generated PLI and its estimation using SSRLS and EKF is depicted in Appendix Figure A4. The PLI free ECG is obtained by subtracting estimated PLI from the noisy ECG, as illustrated in Figure 7e. Appendix Figure A5 shows the frequency spectrum of noisy ECG and its estimated signal through SSRLS and EKF algorithms, respectively, for case 3.
After performing extensive simulations, the chosen value of forgetting factor for frequency and amplitude estimator is 0.99 for the SSRLS algorithm. Using this value and the calculated values of EKF parameters from Eqs. (39–40), both SSRLS and EKF are utilized to suppress the drifting PLI from the noisy ECG. Figure 8 depicts the obtained NR curve and MSE for case 3. The NR curve in Figure 8a illustrates that the EKF algorithm outperforms the SSRLS filter, as it completely removes PLI noise from the corrupted ECG, unlike SSRLS. Similarly, MSE plots in Figure 8b depict that EKF has less MSE as compared with SSRLS.

Comparison of
Figures 7 and 8 conclude that both SSRLS and EKF have removed drifting PLI from the noisy ECG. However, EKF performs better than SSRLS, as EKF has estimated both frequency and amplitude of the drifting PLI more accurately and with less MSE than SSRLS.
Case 4: real ECG signal
In the fourth case, a real-time ECG recording is obtained from a device, and this signal serves as corrupted ECG input for our proposed ANC and is depicted in Figure 9a.

Rigorous simulations are carried out to obtain the best pair of SSRLS forgetting factors for both frequency and amplitude estimators. From the results, the chosen value of SSRLS for frequency and amplitude estimation is 0.99. The EKF parameters are calculated by using Eqs. (39–40). After estimating these parameters, SSRLS and EKF are implemented to remove the PLI that has corrupted the real-time ECG signal. The results of the amplitude and frequency estimator are shown in Figure 9b and c. The PLI free ECG is acquired by deducting approximated PLI from the noisy ECG, as revealed in Figure 9d. From Figure 9d, it is concluded that both SSRLS and EKF have removed approximately the entire PLI noise that has corrupted the real-time ECG signal. Appendix Figure A6 shows the frequency spectrum of noisy ECG and its estimate through SSRLS and EKF algorithms, respectively, for case 4.
The MSE of both filters is also shown in Figure 10 for case 4. It is noted from Figure 10 that the residual of PLI by SSRLS filter is more than that of EKF. Hence, EKF proves to be better than SSRLS for PLI elimination from ECG signal.

Comparison of MSE plots for case 4.
Discussion
It has been observed that both proposed extended Kalman-based ANC and SSRLS-based ANC have performed well in our four simulation cases, that is, PLI with known amplitude and frequency, PLI with unknown amplitude and frequency, PLI with drifting amplitude and frequency, and PLI removal from a real-time ECG recording. Simulation results revealed that both investigated methods/algorithms are capable of tracking drifting PLI noise and can successfully remove PLI noise from the ECG without distorting the important ECG data.
From NR curves, that is, Figures 4a, 6a, and 8a, it can be seen that EKF-based ANC gives fewer oscillations as compared with SSRLS-based ANC, showing that EKF can comparatively track PLI in a better way. Similarly, MSE curves, that is, Figures 4b, 6b, 8b, and 10 and frequency spectrum, that is, Appendix Figures A1, A3, A5, and A6, illustrate that EKF-based ANC can more accurately remove fixed as well as drifting frequency of PLI noise from ECG as compared with SSRLS-based ANC.
The better tracking and noise removal capability achieved by EKF is due to the additional information of measurement and process noise (Eqs. 39–40) used by the EKF to track noise. The EKF is more demanding in terms of additional information about measurement and process noise, as compared with SSRLS. In applications where the provision of accurate measurement and process noise covariances is not possible, the SSRLS algorithm's performance is comparable to that of EKF. 36
Conclusion
In this article, an EKF-based ANC for PLI cancellation from an ECG signal has been presented. The suggested model for EKF-based PLI canceller incorporated the frequency of PLI as a separate parameter. Hence, our proposed ANC possessed the capability to track PLI with both unknown and drifting frequency and amplitude. Performance comparison is presented with the SSRLS filter-based ANC system for simulated PLI with (1) known, (2) unknown but constant, and (3) unknown and drifting amplitude and frequency. Real ECG signal acquired from AFIC/NIHD Pakistan was also used to investigate the presented ANC system's performance. Simulation results depicted enhanced PLI removal capability of EKF compared with SSRLS filter but at the price of more computational complexity. In the future, it would be attention-grabbing for researchers to explore the performance of the proposed EKF-based ANC system for PLI removal from other biomedical signals, for example, electromyography noise (EMG) and electroencephalogram. Moreover, efforts should be undertaken to develop fewer complex solutions for PLI removal from ECG signals.
Footnotes
Author Disclosure Statement
No competing financial interests exist.
Funding Information
The authors are obliged to the National University of Sciences and Technology for funding this work through the Researchers Supporting Grant, National University of Sciences and Technology, Islamabad, Pakistan.
