# Lithium Battery SoC Estimation Based on Improved Iterated Extended Kalman Filter
## 3 IEKF Algorithm Based on LM  
### Extended Kalman Filter  
The Kalman filter (KF) algorithm was proposed in 1958. The algorithm is mainly used to predict the state quantities in a discrete control process. KF combines the prediction value derived from the previous moment and the real-time measurements to predict the system state in the next moment [32]. Kalman filtering requires the relationship between system variables and state quantities to be linear; however, lithium-ion batteries, as complex nonlinear systems, do not satisfy the condition of linearity. Therefore, the extended Kalman Filter (EKF) is used to estimate the SoC of the battery.  
The EKF algorithm is based on KF. It approximates the nonlinear system to a linear system with the help of Taylor expansion, followed by Kalman filtering to predict the state quantities of the system. According to the battery equivalent model, the state space equation of the battery system can be listed as follows:  
\[\left\{\begin{aligned} x_{k}&=f(x_{k-1},u_{k-1})+w_{k} \\ z_{k}&=h(x_{k},u_{k})+v_{k}\end{aligned}\right. \tag{9}\]  
where \(f(x_{k-1},u_{k-1})\) is the state transfer function; \(x_{k-1}\) and \(u_{k-1}\) represent the state quantity and input quantity of the system at moment \(k-1\), respectively; \(w_{k}\) represents the process noise of the system, whose distribution conforms to the normal distribution and obeys the covariance matrix \(Q_{k};h(x_{k})\) is the observation function; \(z_{k}\) represents the output of the system; and \(v_{k}\) represents the observation noise, whose distribution conforms to the normal distribution and obeys the covariance matrix \(R_{k}\).  
Based on the above conditions, the steps of EKF can be obtained as follows:  
1. Set the initial values of the system's state quantity \(x_{k}\) and error covariance matrix \(P_{k}\): \[\left\{\begin{aligned} \dot{x}_{0}&=E(x_{0})\\ P_{0}&=E\bigg{[}\bigg{(}\dot{x_{0}}-x_{0}\bigg{)} \bigg{(}\dot{x_{0}}-x_{0}\bigg{)}^{\text{T}}\bigg{]}\end{aligned}\right.\] (10) where \(\dot{x_{0}}\) is the set value of the initial state and \(P_{0}\) is the error covariance matrix in the initial state. Since the set value of the initial quantity of the system may have a certain error, the error in the estimation result may be larger in the beginning stage of the EKF estimation. However, with the excellent correction ability of EKF in the process of many iterations, the estimation error will gradually decrease with the increase in the number of iterations.
2. Calculate the a priori estimate \(\dot{x}_{k|k-1}\) and the a priori error covariance \(P_{k|k-1}\): \[\dot{x}_{k|k-1}=f\bigg{(}\dot{x}_{k-1|k-1},u_{k-1}\bigg{)}\] (11) \[P_{k|k-1}=A_{k-1}P_{k-1|k-1}A_{k-1}^{\text{T}}+Q_{k-1}\] (12)  
EKF approximately linearizes the nonlinear battery system via Taylor expansion and ignores the high-order terms. The value of matrix \(A_{k-1}\) is the Jacobian matrix obtained using the state transition function \(f(x_{k-1},u_{k-1})\) for the state quantity \(x_{k-1}\) at time \(k-1\), and \(P_{k|k-1}\) is the prior value at time \(k-1\) calculated from the error covariance matrix \(P_{k-1|k-1}\) at time \(k\).
3. Calculate the Kalman gain matrix \(K_{k}\): \[K_{k}=\frac{P_{k|k-1}H_{k}^{\mathrm{T}}}{H_{k}P_{k|k-1}H_{k}^{\mathrm{T}}+R_{k}}\] (13) Similarly, in order to satisfy the requirement of approximating the battery system as a nonlinear system, the matrix \(H_{k}\) is set to the Jacobian matrix obtained by the observation function \(h(x_{k})\) on the state quantity \(x_{k}\) at time \(k\).
4. Compute the posterior estimator \(\hat{x_{k|k}}\) and update the error covariance matrix as follows: \[\hat{x_{k|k}}=\hat{x_{k|k-1}}+K_{k}\bigg{[}z_{k}-h(\hat{x_{k|k-1}},u_{k}) \bigg{]}\] (14) \[P_{k|k}=(I-K_{k}H_{k})P_{k|k-1}\] (15)