Tuning of Kalman Filter Parameters via Genetic Algorithm for State-of-Charge Estimation in Battery Management System

In this work, a state-space battery model is derived mathematically to estimate the state-of-charge (SoC) of a battery system. Subsequently, Kalman filter (KF) is applied to predict the dynamical behavior of the battery model. Results show an accurate prediction as the accumulated error, in terms of root-mean-square (RMS), is a very small value. From this work, it is found that different sets of Q and R values (KF's parameters) can be applied for better performance and hence lower RMS error. This is the motivation for the application of a metaheuristic algorithm. Hence, the result is further improved by applying a genetic algorithm (GA) to tune Q and R parameters of the KF. In an online application, a GA can be applied to obtain the optimal parameters of the KF before its application to a real plant (system). This simply means that the instantaneous response of the KF is not affected by the time consuming GA as this approach is applied only once to obtain the optimal parameters. The relevant workable MATLAB source codes are given in the appendix to ease future work and analysis in this area.


Introduction
Battery Management System (BMS) [1][2][3] comprises of mechanism that monitors and controls the normal operation of a battery system so as to ensure its safety while maintaining its State-of-Health (SoH). The BMS, in essence, measures the voltage, current, and temperature of each cell in a battery pack. These data are then analyzed by a management system that guarantees safe and reliable operations. A common example of an independent battery pack is portrayed in Figure 1. The battery is an essential component and should be accurately modeled in order to design an efficient management system [4]. Hence, a generic tool to describe the battery performance under a wide variety of conditions and applications is highly desirable [4]. As such, electrical modeling is necessary to provide such a tool that enables visualization of the processes occurring inside rechargeable batteries. These generic models are necessary for the development of battery management algorithms. These algorithms control the operation and maintain the performance of battery packs. In short, the ultimate aim of BMS is to prolong battery life, while ensuring reliable operation alongside many applications, especially in photovoltaic systems [5][6][7].
Battery modeling is performed in many ways depending on the types of battery. In general, the resulting battery model is a mathematical model comprising numerous mathematical descriptions [8]. Ultimately, battery models aim to determine the state-of-charge (SoC) of the battery system. However, the complexity of the nonlinear electrochemical processes has been a great barrier to modeling this dynamic process accurately. The accurate determination of the SoC will enable utilization of the battery for optimal performance and longlife and prevent irreversible physical damage to the battery [9]. The solution to the SoC via neural networks [10] and fuzzy logic [11] has been difficult and costly for online implementation due to the large computation required, causing the battery pack controller to be heavily loaded. This may 2 The Scientific World Journal however be a good alternative in the near future as the computational power of processing chips increase alongside their declining cost.
The state-estimation process usually leads to some state variables in a dynamical system. The SoC is a measure of a battery's available power and thus it is important to calculate this value accurately from BMS by the cell voltage, temperature, and polarization effect caused by the electrolyte concentration gradient during high rate charging/discharging cycle [12]. Recently, the battery state-of-charge (SoC) is one of the significant elements attracting significant attention [13,14]. By definition, SoC is the ratio of remaining capacity to the nominal capacity of the battery. Here, the remaining capacity is the number of ampere-hours (Ah) that can be extracted at normal operating temperature. The mathematical expression for the SoC is given in [13,14], which is where is time, ( ) is battery SoC, in amphere-hours (Ah), is current flowing through the battery (passing through bk ), illustrated in Figure 2, and is nominal battery capacity. For charging, > 0 and for discharging, < 0. From this mathematical expression, it is noted that the SoC cannot be explicitly measured. In the literature, there is a myriad of methods dealing with predicting and estimating of SoC. The most popular of these methods are described in the following paragraphs.
At present, Coulomb-counting [15], also known as charge counting, or current integration is the most commonly used technique; it requires dynamic measurement of battery current. This is an open-loop method; however, it suffers from a reliance on the mathematical integration, and errors (noise, resolution, and rounding) are cumulative, which can lead to large SoC errors at the end of the integration process in (1). On the positive side, if an accurate current sensor is incorporated, the implementation will be much easier.
Another prominent SoC estimator is the well-known Kalman filter (KF), invented by Kalman in 1960. Although his popular work was published almost 54 years ago in [16], it remains as an important citation source in the literature. Readers who are new to this method can refer to an excellent KF tutorial by Faragher in [17]. The KF method is a wellknown technique for dynamic state estimation of systems such as target tracking, navigation, and also battery systems [18,19]. The state-of-the-art method provides recursive solution to linear filtering for state observation and prediction problems. The key advantage of the KF is that it accurately estimates states affected by external disturbances such as noises governed by Gaussian distribution. On the contrary, the disadvantage of KF is that it requires highly complex mathematical calculations. This can be realized by a statespace model, as shown in previous work by the author in [20,21]. The modeling is a heavy duty task and is also presented in this work to ease the understanding of readers. As such, there exist some possibilities of divergence due to an inaccurate model and complex calculation. In the case of a slow processor, the calculation results may be delayed and exceed the sampling interval, thereby result in an inaccurate tracking. Various artificial intelligence (AI) methods, mainly the neural networks and fuzzy logic, are being applied in the estimation of battery's SoC [10,22]. Neural networks are computationally expensive, which can overload the BMS and thus this approach, though theoretically feasible, may not be suitable for online implementation that requires instantaneous feedback and action. Also, neural networks require huge datasets in the time-consuming training process. Other techniques for SoC, include the sliding mode observer, are reported in [12].
In this work, a mathematical derivation leading to a state-space model is presented. The basic schematic model is adopted from [18,20]. A thorough analysis in the form of state variables with the application of the Kalman filter is presented. The rest of the paper is organized as follows. The mathematical model is derived in Section 2, resulting in a state-space model. Further, in Section 3, the KF is applied to estimate the SoC of a battery system. This is followed by the tuning of KF's parameter by adopting a metaheuristic approach, namely, a genetic algorithm in Section 4. Relevant results are presented in Section 5, and finally the conclusions are derived in Section 6.
The Scientific World Journal 3

Battery Modeling
Many model-based state-estimations have been proposed in [18,20,21,23]. In [18,21], the well-known Kalman filter [16] had been applied successfully for both state observation and prediction of the SoC. Work in [24] utilized manufacturers' data in modeling the dynamic behavior of the battery. Several battery models exist from many works over the past few years. Each of these models varies in terms of its complexity and applications. In this work, a dynamical battery model is adopted, consisting of state variable equations, from [20,21]. The schematic representation of this model is shown in Figure 2. In this model, there exists a bulk capacitor bk that acts as an energy storage component in the form of the charge, a capacitor that models the surface capacitance and diffusion effects within the cell surface , a terminal resistance , a surface resistance , and an end resistance . The voltages across both capacitors are denoted as and , respectively.

Mathematical Derivations of Battery Model.
In this derivation, we aim to form a state-space model consisting of the state variables , , and 0 . State variables are mathematical descriptions of the "state" of a dynamic system. In practice, the state of a system is used to determine its future behavior. Models that consist of a paired first-order differential equations are in the state-variable form.
Following the voltages and currents illustrated in Figure 2, the terminal voltage 0 can be expressed as which is similar to By (2) and (3), and following straightforward algebraic manipulation, 0 can be written as From Kirchoff 's current law, = + , Thus, substituting (5) into (4) yields By assuming a slow varying bk , that is, = bk̇( from basic formula of = ( / )), and then substituting it into (6), and after rearranging results iṅ By applying a similar derivation, the rate of change of the surface capacitor voltagė, derived also from (2) and (3), giveṡ= Further, by assuming = 1/ bk ( + ) and = 1/ surface ( + ), (7) and (8) can be written aṡ respectively. Further, (9) and (10) can be combined to form a state variable relating voltages and and current flow , which is Next, the output voltage is derived from (2) and (3). By adding both equations, we obtain Then by substituting = /( + ) ⋅ and = /( + ) ⋅ into (11), it is further simplified as Taking the time derivative of the output voltage and assuming / ≈ 0 (this simply means that the change rate of terminal current can be ignored when implemented digitally), we obtaiṅ0
Substituting the formulae obtained in (9) and (10) into (13) results in Then, solving for from (12) we obtain and after substituting it into (14), it yieldṡ Finally, the complete state variable network is obtained by substituting (16) into (10), represented in matrix form as  ] .
This completes the initial derivation of the battery model. .

Numerical
By defining matrix A, . (21) Again by substituting the values from Table 1  ] .
As such (17) can be rewritten as

State-Space
Modeling. Based on control theories, a lumped linear network can be written in the forṁ where in this work, the state variable( ) iṡ Obviously, with ( ) = .
Therefore, by restating the previous calculation values in (21) and (23) respectively. As such, with (32), the output ( ) is in fact This means that the output of the system is the open terminal voltage 0 , as expected. Note that this is an important observation from this state-space modeling. Further, the above state-space variables are transformed to a transfer function, ( ). This is done by using 2 function in MATLAB, which after factorization yields The plot of the unit step response for the gain in (35) is given in Figure 3.

Observability of the RC Battery Model.
In control theory, observability is the degree to which the internal states of a system can be predicted via its external outputs. As such, for an observable system, the behavior of the entire system can be predicted via the system's outputs. On the other hand, if a system is not observable, the current values of some of its states cannot be estimated through the output signal. This means the controller does not know the states' values. In theory, the observability of a system can be determined by constructing an observability matrix .
and a system is observable if the row rank of is equal to (this is also known as a full rank matrix). The ultimate rationale of such a test is that if rows are linearly independent, then each of the states is viewable through linear combinations of the output ( ).
Further, substituting A and C values from (30)  . (37) Clearly, in this case is a full rank matrix, which concludes that this system is observable.

Kalman Filter for SoC Estimation
A continuous time-invariant linear system can be described in the state variable form aṡ where ( ) is the input vector, ( ) is the state vector, ( ) is the output vector, A is the time invariant dynamic matrix, B is the time invariant input matrix, and C is the time invariant measurement matrix. If we assume that the applied input is constant during each sampling interval, a discrete-time equivalent model of the system will now be where whereby I is the identity matrix and is the sampling period. As for this system, two independent process noises are present which are additive Gaussian noise, w vector representing system disturbances and model inaccuracies and V vector representing the effects of measurement noise.
Both w and k have a mean value of zero and the following covariance matrices: where denotes the expectation (or mean) operator and superscript means the transpose of the respective vectors. In usual case, Q and R are normally set to a constant before simulation; in our case both are set to one (see Section 5). Further, a genetic algorithm (GA) is applied in order to obtain a better set of Q and R values resulting in lower RMS error from the KF's output.
By inclusion of these noises, the resulting system can now be described by which is illustrated in Figure 4,

Property of Kalman
Filter. An important property of the KF is that it minimizes the sum-of-squared errors between the actual value and estimated stateŝ, given as To understand the operations of the KF, the meaning of the notation̂( | ) is crucial. Simply stated, it means that the estimate of at event takes into account all discrete events up to event . As such, (43) can include such information, now expanded as In recursive implementation of the KF, the current estimatê ( | ), together with the input ( ) and measurement 6 The Scientific World Journal x(n + 1) x(n) y(n) y(n + 1) Delay unit u(n) signals , is used for further estimatinĝ( + 1 | + 1). This means that in this discrete system, the input for each sample step will be 1 , 2 , 3 , . . . , +1 with respect to the output of 3.2. KF Online Implementation. For the case of a battery, it is well understood that only the terminal quantities can be measured (terminal voltage 0 and current ). Assuming that battery parameters are time-invariant quantities, the recursive KF algorithm is applied. By applying (40) into (30)-(32), we obtain the following values of updated matrices, with = 1: Note that B d and C d remain similar to their previous values, as given in (31) and (32). By utilizing MATLAB's control toolbox, the KF is placed in parallel to the state-space model, hereby represented by plant in Figure 5. The complete source code is given in the Appendix.

Genetic Algorithm
The genetic algorithm (GA), introduced by John Holland, is an approach based on biological evolution [25]. The algorithm is developed based on Charles Darwin's theory of survival of the fittest. The GA has a very powerful encoding mechanism that enables the representation of a solution vector as either a real coded or binary string. Both encodings serve a different purpose in the context of different problem space. GAs are regarded as the global optimizer that often spot or locate the potential area or even accurately obtain the best solution, known as the global minimum [26][27][28]. Underneath this popular algorithm are the three operators that contribute to its success in performing optimization task.
(i) Selection. In selection, offsprings with higher fitness have better chance for survival to the following generation in the evolutionary process. This basically is based on the theory of "survival of the fittest. " (ii) Crossover. The crossover increases and maintains the diversity of the entire population over the entire run. This is due to the fact that a population with higher diversity has the ability to explore a wider range of search space.
(iii) Mutation. This enables chromosomes (potential solutions) to jump to a wider range than crossover. Again, mutation also increases the diversity of the entire population.
The Scientific World Journal  The pseudocode of the GA is presented in Algorithm 1, and relevant figure depicting the algorithm flow is illustrated in Figure 6. To avoid extended discussions on GA, we include here a complete workable source code in the appendix. All parameter settings for the GA are available in the source code.
In the context of Kalman filter, GA is applied to tune the Q and R parameters, which was explained in detail in Section 3.

Results
The program, implemented in MATLAB, is given in the appendix to clarify the results obtained in this work. Take note that the Q and R mentioned in (41) are both set to a numerical value of one (Q = R = 1) in the first simulation. The results obtained are tabulated in Table 2. From these results, RMS of the estimated error, which is the error from KF, is far smaller in comparison to the measured error, with values of 1.0013 V and 1.92 × 10 −4 V, respectively. This RMS error is further minimized by utilizing Q = 0.012697316315642 and R = 2.303940992875865, found using the GA approach. A graph depicting the convergence characteristic is shown in Figure 7. The time plot of the estimated error from 0 s to 60000 s is shown in Figure 8, depicting a very small amplitude, in blue color (≈ ± 0.04 V) along the timeline. This is observed through the zoomed display of the MATLAB graph. On the contrary, the measurement error, portrayed by green color noise in Figure 8, has an absolute magnitude of ≈ ± 2 V.

Charging Behaviour.
The charging characteristic is illustrated in Figure 9 whereby the initial terminal voltage 0 starts from 0 V and rises up to approximately 0.5 V within 60000 seconds (which is 100 minutes). Charging impulses of 1.53 A are applied in this case as shown in Figure 9. As expected, this is a time consuming process as in general case it may take hours for a car battery (lead acid) to be completely charged.

Discharging.
For the discharging process, the initial value of terminal voltage, 0 = 0 , is set to 2.2 V in the MATLAB program. Again, in this case, impulses of 1.53 A are applied, but now in negative form. The dynamic behavior of the discharging characteristic is shown in Figure 10. From this figure, it is observed that the discharging process is similar to the charging process, but now with a linearly decreasing terminal voltage slope. The open terminal voltage 0 drops from 2.2 V to 1.7 V in 60000 seconds (100 minutes); this is similar to the charging process as it takes 100 minutes to reach 0 = 0.5 V from zero potential.

Conclusion
In this work, we successfully obtained the state variables of the RC model representing a battery in terms of mathematical derivations. The derivations lead to the conclusion that there exist three state variables relevant to a battery's statespace model. With this state-estimation model, a prominent technique known as the Kalman filter is applied in the aim of estimating state-of-charge for a Battery Management System. From numerical results, the KF is shown to be accurate in predicting the dynamic behavior of the system. This is shown by a very small RMS error of the estimation in comparison to its measurement. The estimated error is further reduced after incorporating the optimized values of Q and R through the offline GA approach. As such, the efficacy of such an approach is, thus, validated.