Iterative Nonlinear Fuzzy Modeling of Lithium-Ion Batteries

: Electric vehicles (EVs), in their pure and hybrid variants, have become the main alternative to ensure the decarbonization of the current vehicle ﬂeet. Due to its excellent performance, EV technology is closely linked to lithium-ion battery (LIB) technology. A LIB is a complex dynamic system with extraordinary nonlinear behavior deﬁned by electrical, thermal and electrochemical dynamics. To ensure the proper management of a LIB in such demanding applications as EVs, it is crucial to have an accurate mathematical model that can adequately predict its dynamic behavior. Furthermore, this model must be able to iteratively adapt its parameters to accommodate system disturbances during its operation as well as performance loss in terms of efﬁciency and nominal capacity during its life cycle. To this end, a methodology that employs the extended Kalman ﬁlter to iteratively improve a fuzzy model applied to a real LIB is presented in this paper. This algorithm allows to improve the classical Takagi–Sugeno fuzzy model (TSFM) with each new set of data obtained, adapting the model to the variations of the battery characteristics throughout its operating cycle. Data for modeling and subsequent validation were collected during experimental tests on a real LIB under EVs driving cycle conditions according to the “worldwide harmonised light vehicle test procedure” (WLTP) standard. The TSFM results allow the creation of an accurate nonlinear dynamic model of the LIB, even under ﬂuctuating operating conditions, demonstrating its suitability for modeling and design of model-based control systems for LIBs used in EVs applications.


Introduction
The growing popularity in recent decades of devices that require reliable and efficient storage of electrical energy, such as portable devices (phones, laptops, etc.) and electric vehicles (EVs) [1], logically entails a development of battery technology and the devices that manage them.
Currently, the decarbonization of the transport industry involves the use of lithium-ion batteries (LIBs) [2].The need to know precisely and in real time the autonomy of EVs requires not only reliable models but also control systems to increase this autonomy [3,4].To design an efficient control system, it is desirable to have an accurate model at all times, regardless of conditions in which the battery is working.The model must provide reliable predictions about the state of the battery, available energy and remaining operating time for given conditions and power requirements.However, the behavior of batteries changes with time, charge and discharge cycles, temperature, degradation and even depending on the instantaneous power required from them [5,6].Therefore, it is necessary to develop modeling solutions that allow the dynamic model to be adapted or modified to provide a computationally cost-effective, efficient and robust solution to the modeling problem for any instantaneous battery operating condition.
Thus, many models have been suggested in the specialized scientific literature, with their corresponding modifications and subsequent improvements, which try to describe the behavior of the different battery technologies [7].However, given that what underlies the operation of these energy accumulators are chemical reactions, more or less complex, that depend on various factors and variables, and that show highly nonlinear behavior, obtaining accurate models is not an easy task.Therefore, it is currently a scientific field in full activity.
In summary, most of the models developed to date can be grouped as follows [8,9], (summarized in a simple way in Figure 1): (a) Electrochemical models: These models are built from the physics of electrochemical processes that occur at the battery cell level.They are quite accurate at this level [10][11][12][13][14][15][16], although they present significant errors at larger scales.In view of the above, its usefulness is justified to optimize the physical design of the cells [17].These models are highly complex to define and implement, requiring a large computational burden, since they are usually described by nonlinear differential equations [10,18,19] that model microscopic transport phenomena or the chemical kinetics of the reactions involved [20,21].However, recent research seeks to obtain low-order models for use in real-time applications [22].The most common are usually single particle models [23], porous electrodes [24] and pseudo-two-dimensional models [9].(b) Electrical models: They are implemented by means of electrical circuits (resistors, capacitors and sources), to describe the behavior of a battery.They are usually intuitive models, and by their nature, they are directly applicable to the use of simulators where it is easy to integrate them with the rest of the participating systems.That is why their uses, in their different versions, are widespread.Most of these models can be grouped into a few categories: -Thevenin-based models [25][26][27][28].These models basically consist of a real voltage source followed by a concatenation of n RC cells in series.The voltage source represents the open circuit voltage, V OC , related to the state of charge (SOC) of the battery [29].This model has a relatively uncomplicated design and demonstrates good accuracy in simulations [30].In addition, it does not consider nonlinear behavior and temperature effects in batteries, although recent works are making improvements in this aspect [31].A Thevenin-based model of n-RC order is shown in Figure 2, and its transfer function is shown in (1).-RC-based models [32][33][34].These are simpler electronics models that basically consist of a network formed by two capacitors and several resistors.Generally, a large capacitor models the energy storage capacity of the battery, and another, smaller than the previous one, models its transient effects.-Impedance-based models [35][36][37].These types of models change the RC cells of the Thevenin model by impedances determined by electrochemical impedance spectroscopy methods.They are usually suitable models for slow discharges but not for high currents.
Obviously, in the scientific literature, there are models that, trying to obtain better performance, hybridize the previous ones and introduce controlled sources and nonlinear elements [38,39] and even operators or mathematical blocks such as integrators and filters [40], obtaining general and robust models, although due to their complexity, they may require a lot of computational burden to adjust their parameters.
We should also mention the so-called intermediate models, which are located between purely electrochemical and equivalent circuit models, although they are basically formulated with electrical variables [32].The simplest is the Peukert model from 1897 [41], and among the most famous is the Shepherd model from 1965 [42], which is still widely used today, as well as their respective improvements in the Unnewehr, Nertst and Plett models [32,[43][44][45].Plett's model can be considered an improved compendium of the previous ones; however, its improvement comes at the cost of increasing its complexity and requiring several parameters to be experimentally determined.(c) Mathematical and empirical models: There are multiple techniques in the literature, most of them employing artificial intelligence techniques, that allow obtaining nonlinear models of dynamic systems with high accuracy, such as neural networks [46][47][48], neuro-fuzzy models [49], particle swarm optimization [50], or the most recent hybrid models [51,52], among others [53].Many of these models (algorithms) have been used to estimate the LIB performance from operating data [50,[54][55][56][57].The goodness of these algorithms is more than proved, especially when they are based on a large set of data, but they do not allow these models to adapt to subsequent LIB changes.
The previous methodologies allow obtaining more or less accurate models, but they are unable to adapt to the changes in the dynamics that a LIB undergoes during its life cycle.The main objective of this work is to present an iterative modeling methodology, capable of improving an initial model with each new set of data obtained and, therefore, capable of adapting to such changes.In order to respond to these problems, the main novelty of the paper is the use of an iterative modeling technique, which allows a balanced solution in terms of modeling error and computational cost, as well as adaptability to changes in battery performance in demanding applications such as the one studied.In this paper, we propose the use of an extended Kalman filter (EKF) algorithm [58] as an iterative modeling algorithm to adapt a Takagi-Sugeno fuzzy model (TSFM) [59].This combination provides the accuracy and interpretability of a fuzzy model, together with the adaptability and computational efficiency of the EKF [60], so that it is possible to maintain model accuracy in the face of dynamic variations experienced by the batteries during their operating cycle.In addition, it should also be noted that the EKF is particularly suitable for systems where noise or inaccuracies are present, making it ideal for real-world applications [61].
Following this introduction, in Section 2, the materials and methods used during the experiments are presented.The iterative battery modeling process is described in Section 3, and the results obtained are discussed in Section 4. Finally, some conclusions are presented.

Materials and Methods
To evaluate and validate the adaptive capacity of the developed algorithm to model the LIB, two experimental tests (charging and discharging tests) were carried out on a 59.2 VDC and 120 Ah LIB ( The battery used has the following characteristics: Pack lithium ion Samsung 50 59.2V 120 Ah + BMS 80 A + aluminum box).Specifications of lithium Ion battery 59.2 V 120 Ah-Samsung 50E.Technology: NMC.Battery pack nominal voltage: 59.2 V. Battery pack charging voltage: 67.2 V. Capacity: 120 Ah (7.10 kWh).Continuous maximum discharge current: 240 A. In this case, the setting is 16 cells of 3.7 V in series, and 24 cells of 5 Ah in parallel to obtain the 120 Ah., specially designed and manufactured from Samsung, model INR21700-50S cells by Batesur © .For this purpose, simulations results of the proposed algorithm were compared with the experimental data obtained on the real battery.The model simulations were performed in the MATLAB © environment.The sampling time during all tests was set at 1 s.
To evaluate the battery performance, in particular its voltage, with respect to its operating temperature, a temperature-controlled high-capacity thermal chamber was used.Specifically, during the two tests, different heating cycles were programmed up to a maximum internal temperature of 60 • C, and a subsequent forced cooling of the battery, always taking into account the safety temperature limits established by the manufacturer.The cooling stage was carried out using a high-flow axial fan.The objective of the temperature control was never to reach a target temperature but to provoke substantial temperature variations in a short period of time, essential to appreciate the effect of the temperature on the voltage both in the training and validation phases of the model.
For the experimental tests, a 32 kW programmable source and sink of the Regatron © TC.GSS series were used.This device allows operation in the first (source) and fourth (load) quadrant depending on the voltage set point and the current or power limits established.The electrical connection between the battery and the programmable source was made by direct connection using fuses.Due to the internal protections of the device, it was not necessary to add additional elements such as antireverse diodes.The charge and discharge profiles (current and power profiles, respectively) were previously defined in the software that includes the programmable source and executed directly on the final assembly.The measurement of the variables of interest, voltage, current and operating temperature of the battery was performed by means of specific sensors and a signal conditioning circuit designed ad hoc.For voltage and current measurements, Hall Effect sensors model LV25-P and LA25-P from LEM © , respectively, were used.For temperature measurement, an NTC type thermoresistance and a conditioning circuit based on a resistive divider and zero correction circuit were used.To ensure an optimal and homogeneous measurement, the temperature sensor was placed in the center of the side face of the battery, at the opposite end of the thermal chamber heat source.The measurement obtained was compared at all times with a reference contact thermometer.The acquisition of the variables was carried out by means of a 12-bit resolution data acquisition card (DAQ) NI-USB-6008 from National Instruments © .Their storage, processing and representation was carried out by means of a data acquisition and control system (SCADA) designed ad hoc and programmed in LabVIEW © .The experimental setup carried out can be seen in Figure 3.

Takagi-Sugeno Fuzzy Model
Fuzzy logic, unlike bi-evaluated logic, is able to work with infinite possible values, not only with 'TRUE' and 'FALSE'.It is therefore very close to human reasoning, able to infer by vague predicates, i.e., able to logically integrate the infinite shades of gray that exist between absolute black and white.Fuzzy models are based on IF-THEN rules.The condition that must be fulfilled (the 'IF'), is called the antecedent, and the one that is activated if the antecedent is fulfilled (the 'THEN'), is the consequent.Between the different fuzzy models that exist, TSFM are those whose consequent is a linear polynomial [59,62], see ( 2)).
where n and m are respectively the number of input (x j ) and output (y i ) variables of a system to be modeled; l = 1, . . ., M i represent the index of the rule and M i the total number of rules for the i-th output (y i (k), i = 1, . . ., m).On the other hand, a l ij , j = 0, . . ., n is the parameters of the consequents, and k is the sampling time.A l ji are the fuzzy sets that define the antecedents of the fuzzy rules [63].
Obtaining an accurate model is a fundamental step to control any system.TSFM are universal approximators [64], allowing approximate reasoning [65], and have proven to be very accurate in modeling nonlinear systems [66][67][68][69].Usually, the number of rules increases if the modeling error is to be reduced [70]; therefore, this process is crucial to obtain a good, accurate and manageable model for both analysis [71][72][73] and control system design [74,75].
To work with a more compact expression, the input vector x = (x 1 , x 2 , . . ., x n ) T could be extend [67,74] by the coordinate x0 = 1: x = ( x0 , x1 , . . . ,xn ) T = (1, x 1 , . . . ,x n ).T  (3) Thus, the output y i can be calculated by [76]: where a ji (x) are variables coefficients [77] a ji (x) = and w l i (x) is the degree of activation of the fuzzy rules: is the jth membership function in the l rule, for the ith output (A l ji fuzzy set).The σ l ji are the parameters of this membership functions.So, the modeling process consists of determining σ l ji and a l ji parameters to obtain a TSFM.

Extended Kalman Filter and Its Application to Takagi-Sugeno Fuzzy Modeling
The EKF allows to construct a pseudo-optimum observer for nonlinear systems [58,78,79] (pseudo because it is based on a linear approximation).The filter is based on the assumption that the noises (uncertainties in the model and inaccuracies of the sensors) are zero mean white Gaussian noise, although there are also variants that allow working with other types of noise.It has shown that the EKF is an excellent algorithm for iteratively modeling complex systems based on data [60,61,[80][81][82][83][84].Therefore, in this work, it is used as an iterative adjustment method for the TSFM.
Be a nonlinear dynamical system in discrete time: where x(k) is the state vector, u(k) is the input vector, and v(k) and e(k) are white noise vectors.The system's Jacobian matrices are: and The EKF is considered as the execution of a prediction phase followed by an update phase.The prediction phase uses the state model and past data, while the update phase adds sensor information to the prediction-all this taking into account the quality of this information known through its covariance matrices.To solve the EKF, the following set of equations must be used iteratively: Prediction (a priori estimation): Update (a posteriori estimation): x(k|k) = x(k|k − 1) + K(k)(y(k) − ŷ(k)) ( 14) From ( 11) to (15), x(k|k − 1) represents the priori estimations of the true state x, and x(k|k) represents the posteriori one.
P(k|k − 1) and P(k|k) are, respectively, the a priori and the a posteriori estimate covari- ance matrices.ŷ(k) are the estimated output vector, R v , R ve and R e , are the noise covariance matrices, and K(k) is the Kalman gain.
Starting from an initial prediction x(0), and its corresponding covariance matrix, P(0), the algorithm evolves iteratively, minimizing the estimation error and its covariance matrix for the linearization obtained at each instant.
As shown in [60,61], the EKF algorithm allows to estimate the parameters of a TSFM.To do it, it is necessary to define a new model whose states are the parameters to be estimated [85], p(k) in ( 16), which will be adjusted iteratively to reduce the estimation error on the output to be modeled, y(k).e(k) represents the uncertainty of the output measurements of the system, which are assumed to be a zero mean Gaussian white noise with R e covariance.So, Equations ( 11) to ( 15) can be iteratively applied to estimate the model's parameters, p(k).

p(k + 1) = p(k) y(k) = h(x(k), p(k)) + e(k).
Applying ( 8), ( 9) and ( 10) on ( 16): In the above expressions, p(k) is the current estimation of p(k), which includes all the TSFM parameters, both antecedent (σ l ji ) and consequent (a l ji ).C(p(k)) is the derivative of the TSFM with respect to its parameters, which was obtained in [60], and its calculation was implemented in the Fuzzy Logic Tools library (FLT) [86].

Iterative Modeling of a Lithium-Ion Batteries
A LIB is a system whose parameters change over time due to degradation of its components or internal chemical processes, so a good prediction of its behavior requires the constant adjustment of the model.The conjunction of the Kalman algorithm with TSFM has demonstrated the ability to obtain good models while allowing to improve and adapt these models with each new data obtained from the operation of the system [60,61].The use of such an algorithm for modeling the consequents of a TSFM based on operating data from a real LIB is presented below.It has been decided not to also adapt the antecedents of the TSFM in order to obtain a more efficient algorithm that can be executed iteratively at run time without requiring particularly fast hardware.Of course, if a more accurate model is required, it is possible to adapt the model antecedents as well [87].
The modeling process consisted of 4 phases:

Phase 1. Obtaining Discharge and Charge Data of a Real Battery
The first step is to obtain a sufficiently large and representative dataset of the LIB, taking that the data must be obtained in an operating environment as close as possible to that of a real EV into account.For this purpose, using the test bench presented in section 2, the battery was discharged from its maximum capacity until it was completely discharged, and then it was subjected to a charging process.To do that, the "Worldwide Harmonised Light Vehicle Test Procedure" [88,89] (WLTP) was used for the discharge test.This procedure is used as a global standard to determine the CO 2 emissions, fuel consumption and pollutant levels of traditional and hybrid cars, as well as the range of fully EVs.Specifically, based on the performance of the LIB, the WLTP standard was used assuming a low-power class 2 electric vehicle (with a power-to-mass ratio between 22 and 34 W/kg and a upper speed of less than 90 km/h).This driving profile is characterized by a speed and acceleration profile composed of three phases associated with low, medium, and high-speed driving, each with a defined duration, Figure 4.The associated discharge power profile was calculated from the acceleration profile, assuming a direct relationship between power and acceleration, matching the peak acceleration with the maximum allowable discharge power of the LIB.Due to the type of electric vehicle under study, in this test, only the discharge of the LIB has been considered.In Figure 4b, the negative accelerations present in the acceleration profile will not have any effect, as the battery recharging by means of regenerative systems is not considered.To evaluate the performance of the model, this power profile was evaluated over the entire operating range of the battery (0% ≤ SOC ≤ 100%).The described power profile is shown in Figure 5.In accordance with the application and with the aim of evaluating the response of the modeling algorithm throughout the battery's operating range, the LIB charging process was carried out by simulating the use of a commercial type 2 semifast charger.For this purpose, a charging test was performed for a maximum current of 35 A, according to the well-known two-phase charging protocol, constant current (Bulk Phase) and constant voltage (Absorption Phase).
In this first phase, a set of 86508 data sampled every second was obtained from the battery voltage, current, temperature and SOC (The battery SOC was estimated by integration of the current according to the Coulomb counting method [90].).These data are shown in Figure 6.

Phase 2. Initial TSFM
To obtain an initial structure of the dynamic model for the LIB similar to (7), a series of tests were performed on a reduced dataset consisting of the first 1000 data.Through these tests, it was determined to perform a third-order discrete dynamic model, i.e., including as inputs three memories of the previous outputs, together with the inputs (current, temperature, and SOC), and a memory of the current.That is, the discrete dynamic model of the system will have the form: where k is the discrete time, v(k + 1) is the estimate future voltage, v(k . . .k − 2) are the previous voltages, i(k) and i(k − 1) are the current and its previous value, T(k) is the temperature, and SOC(k) is the estimated SOC. f is the TSFM to be fitted.
Once the model structure was determined, the dataset was used to obtain an initial TSFM using the well-known subtractive clustering algorithm of Chiu [91].Using a Cluster center's range of influence (RADII) of 0.6, six rules with Gaussian antecedents were obtained.

Phase 3. Iterative Modeling
This is the most relevant phase of the experiment, since the objective of the present work is to demonstrate that it is possible to perform an iterative modeling that allows readjusting an existing model based on the new data obtained.
With the initial model obtained in the previous phase, the EKF was applied to improve the estimation of the parameters with each of the data, i.e., iteratively as it would be improved in a working system.The initial covariance matrix of the EKF, P(0), was initialized as 2I, this is α = 2, being I an identity matrix.The fitting process is shown in Algorithm 1, where α is a value indicating the reliability on the initial parameters of the model.Algorithm 1 EKF algorithm for the adaptation of consequents.Calculate P(k|k − 1) by (12) 5: Estimate ỹ(k) using the fuzzy model 6: Calculate C(k) by (17) 7: Get K(k) by (13) 8: Update p(k|k) by ( 14) The prediction of the model at each iteration can be seen in Figure 7, and the error obtained at each instant can be seen in Figure 8.The model improves as new data appears.When a new behavior not yet modeled occurs, an error is raised, as can be seen in Figure 8.However, the algorithm will learn from this error and will improve the model.
The fuzzy model obtained after running through all the experimental data is reflected by the following rules, where GAUSS(c, σ) is the Gauss function (this antecedents can be seen in Figure 9): (2.317; 25.41) and i(k − 1) is GAUSS (3.925; 25.41) and T(k) is GAUSS (24.8; 5.94)   This model allows us to interpret the relationships between the variables linguistically within each rule.In this case, the initial model was not considered to be easily interpretable as a whole, so the antecedents appear overlapped, but there are algorithms that allow this to be done [92][93][94].

Phase 4. Validation Data
Using the same philosophy as previous modeling data, a new charge/discharge cycle was performed to obtain another dataset to validate the resulting TSFM.On this occasion, 14746 data were obtained with the same sample time of 1 s, which are shown in Figure 10.The final TSFM obtained in the previous phase was validated to check the performance of the iterative algorithm.

Analysis of the Results
Finally, once all the data were run through, it was checked that the model obtained adequately represented the dynamic behavior of the battery under study.Note that the proposed algorithm does not perform the modeling with all the data, but iteratively adjusts the model with each new data obtained.Therefore, the main objective is not focused on obtaining a lower error rate than those obtained by other techniques presented in the scientific literature, but to demonstrate that the algorithm is able to perform the iterative adjustment, with good performance considering the model error, against diverse and highly fluctuating power profiles, regardless of the battery temperature, SOC or operating condition (charge or discharge).Obviously, the performance of the modeling process will be highly dependent on the initial model.In this case, for the test performed, the initial model was obtained from the clustering, without any additional tuning.Despite this, the model validation obtained a MAE of 69.90 mV, and a RMSE of 21.20 mV.The model output during the validation process is shown in Figure 11, and the error in Figure 12.From the results obtained, it is verified that the EKF works properly, and that it allows modeling iteratively a real LIB with a reduced error.This will allow continuous improvement and adaptation of the TSFM to the variations that the LIB may undergo.

Conclusions and Future Works
The modeling process of a LIB is a complex task that requires a deep knowledge of the laws of electrochemistry but is essential for its efficient use and proper management.For EVs application, the high fluctuation of the power profile means that the dynamic behavior of the LIB is strongly influenced by intrinsic nonlinearities.The main proposals found in the scientific literature for these applications are based on equivalent electrical models that present reduced performance in terms of dynamic behavior and in many cases, for the sake of simplicity, ignore the dependence on certain parameters such as temperature.
To address to the shortcomings found in terms of modeling, this research has applied an iterative fuzzy modeling methodology based on the EKF to a real LIB for use in EVs.The proposed method is not a closed algorithm and can be easily applied to other types of batteries or applications.The model parameters were fitted iteratively from an initial unfitted model, using a 59.2 VDC and 120 Ah commercial LIB on a profile under WLTP standard conditions for a class 2 driving cycle.Experimental results for both charging and discharging, for the entire useful operating range of the LIB and different operating SOC and temperatures, validate the effectiveness of the model in a WLTP test resulting a MAE below 70 mV (about 21 mV RMSE) and taking into account that the starting model was unadjusted.
Based on the results, it is found that the designed algorithm and the obtained dynamic model are sufficiently accurate to iteratively model nonlinear LIBs even under such demanding operating profiles.Similarly, thanks to the iterative run-time fuzzy modeling methodology proposed in this work, the model can adapt to changes in the LIB's performance or rated capacity due to usage time.This will contribute to the design and development of model-based energy management strategies and controllers for the proper operation of LIBs in EVs applications throughout their lifetime.
Further experiments and verifications will be carried out in the future to test the effectiveness of the proposed method for different driving cycle profiles and operating conditions, as well as its application for the design of iterative model-based SOC estimators.Finally, as a natural outcome of the research process, these models will be applied in the design of new model-based energy management and control strategies for use in hybrid

Figure 1 .
Figure 1.Brief classification of battery models.

Figure 2 .
Figure 2. Thevenin-based model of nth order RC cells.

9 :
Update P(k|k) by (15) 10: end for k A Mean Absolute Error (MAE) of 31.40 mV, or the equivalent Root Mean Square Error (RMSE) of 53.00 mV, was obtained during the modeling phase.