Modeling Lithium-Ion Batteries Using Machine Learning Algorithms for Mild-Hybrid Vehicle Applications 1st Daniel Jerouschek 2nd Ömer Tan Department of System Integration and Energy Management IAV GmbH Munich, Germany daniel.jerouschek@iav.de Department of System Integration and Energy Management IAV GmbH Munich, Germany oemer.tan@iav.de 3rd Prof. Dr. Ralph Kennel 4th Dr. Ahmet Taskiran Institute for Electrical Drive Systems and Power Electronics Technical University Munich Munich, Germany ralph.kennel@tum.de Department of System Integration and Energy Management IAV GmbH Munich, Germany ahmet.taskiran@iav.de Abstract—Voltage prediction in an automotive 48V-mildhybrid power supply system is safety relevant and an enabler for a better efficiency. Due to the high power to energy ratio in these power supply systems, an exact voltage prediction is challenging, so a method to model the lithium ion batteries behavior via an recurrent neural network is established. Therefore the raw data is pre-processed with over- and undersampling, normalization and sequentialization algorithms. With this data base the built recurrent neural network models are trained and the hyperparametertuning is carried out by the optimization framework optuna. This training methodology is performed with two battery types. The validation shows a maximum error of 2.34 V for the LTO battery and a maximum error of 3.39 V for the LFP battery. The results demonstrate, that the proposed methodology is performing in an appropriate error range to utilize it as a tool to generate a battery model based on available data. Index Terms—lithium-ion battery (LIB) long short-term memories (LSTM) machine learning (ML) modeling recurrent neural net (RNN) I. I NTRODUCTION The European Union is regulating the CO2 emission for 2021 to a target of 95 g CO2 /km for new passenger cars. [1] This target is quite challenging for the established original equipment manufacturers, so that the electrification of the drive train is mandatory to reach this goal. Beside the battery electric vehicles, with their drawbacks in infrastructure, costs and range a hybridization of internal combustion engine vehicles is a promising approach to reduce CO2 emissions. A mild-hybrid vehicle with a 48 V power supply network is a cheap and effective variant of electrification. [2] An electric machine ensures energy recuperation during breaking, as well a support of the internal combustion engine in acceleration and load point fitting. Furthermore, belt driven consumers can be electrified and run with the generated energy. The recuperated energy has to be stored in an electric energy storage. Adding extra components to the system is only reasonable if the whole capability of each component is realized. Ensuring this, a powerful battery-management system (BMS) with its key functionalities of monitoring and state estimation is crucial. In relation to the battery´s capacity the high applied powers lead to the inference, that the power and voltage prediction is more critical than the pure state-of-charge estimation. The system is capable of remaining more frequently in the unlimited voltage operation range with a better voltage prediction. Modeling battery voltages can be divided into four categories: Analytical models, electrochemical models, equivalent circuit models (ECM) and data-driven models. A previous state-of-charge (SOC) estimation is obligatory for analytical models and electrochemical models require accurate measurements and large computational costs, thus they are typically excluded from industrial applications. For ECM precise measurements and a valid SOC model is required to gain models with high accuracy [3]. Data-driven models are recent fequently discussed in literature. The results show that recurrent neural networks like long short-term memories (LSTM) [4] and gated recurrent units (GRU) [5] are more promising than other approaches like fuzzy logic [6], feedforward neural nets (NN) [7] and deep NN [8]. In an earlier paper the authors demonstrated the feasibility of an accurate voltage prediction for a 48 V battery pack without the utilization of a preceding SOC estimation [9]. Furthermore, the scope of this paper is: First, the proof of the applicability of recurrent neural networks (RNN) models to any battery type and size. Second, to proof that no expert knowledge is necessary due to the automated data pre-processing and hyperparameter tuning. The hereafter article is structured as follows: The process of data preparation and pre-processing as well as the theory of RNN are described in Section II. Section III outlines the application of the previously mentioned pipeline on two different battery samples. Thereafter, Section IV and V is allocated to validation results and the conclusion. II. P IPELINE This section describes the executed data-pipeline for preparing and training a battery model independent of a specific battery type. A. Battery Samples and Data collection The proposed modeling method is applied to two different battery types, an LTO and an LFP Battery. The LTO battery has a Lithium-titanate anode in combination with a nickel manganese cobalt oxide cathode has a capacity of 11 Ah and the maximum current is 350 A in charging as well as in discharging direction. With 450 A maximum current and a capacity of 20 Ah the LFP battery with its graphite anode and lithium iron phosphate cathode is more powerful. The two battery samples were tested in two different mild-hybrid vehicle environments, whereby the impact to the battery is only noticeable by the current profiles. In order to gain a valid battery model with machine learning algorithms an extensive preceding data collection is mandatory. The data used for this approach are obtained from testing vehicle measurements driven in customer-oriented conditions. The data provided by the BMS is logged with a CAN bus measuring device with a sampling rate of 10 Hz. With an overall data magnitude of nearly 2.600 h of measurements for the LFP, and 5.500 h for the LTO battery, respectively a sufficient data set is obtained. The temperature ranges between approximately 23°C and 60°C for both batteries. After pre-processing the LTO data set has a volume of 1.028.918 points and the LFP set has 1.641.058 points. Each set is split into a training and validation data set with a ratio of ten to one. In contrast to this, the test data is collected on a hardware-in-the-loop test bench with a climate chamber, an electric source-sink and the battery sample. Test-bench measurements benefit from the applicable conditions, so that a wide temperature and power range can be validated. The applied current-profiles were taken from the corresponding vehicles. B. Methodology for Data Pre-Processing The logged raw data has to be pre-processed in several steps to be usable to train a NN. These steps are reducing the magnitude of data with a simultaneously approximation of an unbiased feature distribution. Furthermore, the data has to be prepared to be suitable for the NN. 1) Undersmapling: Undersampling is motivated by a reduction of training time per epoche and the possibility to learn the behavior adequately. Large datasets require a lot of time as every single date has to be processed through the entire network. Data sets generated in a customer oriented way are inherently unbalanced with regard to the operation strategy as well to the climate conditions. Undersampling algorithms are targeting to achieve an equal data distribution over the relevant feature ranges by reducing the over-represented data. The algorithm stops before too much data is cut off and a lack of information occurs. 2) Oversampling: Non-generic measurement data typically have a lack of data in extreme feature areas. The oversampling algorithm detects these underrepresented spots and appends generated data there. Generating data is done by adding artificial noise to the multiplied existing data in these spots, without changing the basic correlation. This can be accomplished by using the inertia to small changes of features like temperature and state-of-charge. 3) Normalization: Due to the differences in the input feature ranges a scaling of the ranges and values is carried out. This normalization leads to numerical stability, a better generalization and a faster training progress with higher learning rates. Equation 1 shows the min-max scaler applied to the input data. X̂[:, i] = X[:, i] − min(X[:, i]) max(X[:, i]) − min(X[:, i]) (1) Ioffe et al. [10] introduced the batch normalization, where the normalization is applied to the activations between the neural network layers in order to limit the covariate shift. 4) Sequentializing: Most of the effects influencing the voltage behavior of a battery depends largely on time. Modeling these time dependencies with neural networks is achieved by recurrent layers. Layers like RNN, GRU or LSTM use sequential data as inputs to calculate the outputs. The sequence length determines the past time range transferred to the net. A trade off between short sequence length with the therefore resulting worse prediction and longer sequence length with worse training speed has to be figured out in consideration of the specific application. In automotive 48 V power supply systems largely volatile powers are conducted, so that a sequence length of 12.8 s is sufficient. C. Theory of RNN Utilization in Battery Models The Battery behavior is characterized by its highly nonlinear time-dependency with time constants of several seconds. This time dependency is again dependent of battery states like the temperature and the SOC. A conventional feedforward neural net is not meeting the challenge of modeling these dependencies. For this purpose recurrent neural networks are a good approach. 1) RNN-Layer: Recurrent neural network layers uses sequential data as inputs to calculate the output. The input in form of xt with t as the time step are given in the right order to an RNN cell. Each input is processed in the cell to two outputs: One output is forwarded as the cell state Ct to the next cell and one output is forwarded as the output state ht to the next layer. The functioning of a RNN cell can be seen in figure 1. The hidden layers are forwarding every output step calculated by a single RNN cell to the next layer, whereas the output layer only returns the last value of the sequence as it represents the predicted value. Simple RNNs use in the cell calculation only a tanh activation function to calculate both states. Updating the weights proportional to the partial derivative of the loss function could lead to a vanishing gradient problem [11]. Therefore, long term dependencies can not be modeled with conventional RNNs. 3) Dropout: Overfitting occurs, when a model learns the input data including the noise too accurately. Dropouts prevent NN from overfitting, by randomly dropping neurons during the weight update process in training. The ratio of dropped neurons in each iteration to total neurons is specified by the dropout rate. This regularization method is introduced by Srivastava et. al. [13]. Reducing the probability of overfitting enables the possibility to train with higher learning rates and therefore accelerating the training progress. Fig. 1: Schematic structure of an RNN neuron. 2) LSTM-Layer: LSTM cells show great improvements on modeling longer time dependencies than RNN, due to less suffering from the vanishing gradient problem. LSTMs were first introduced by Hochreiter et al. [12], the principal architecture of an LSTM cell is shown in 2. Inside an LSTM cell an extensive calculation takes place, resulting in two different outputs. The input gate it , the output gate ot and the forget gate ft are calculated with the previous hidden state Ct−1 , the input vector and an activation function. W and U describe the corresponding matrices, b the bias vector and σ the activation function. These inner gates are affecting the cell state Ct directly. The calculation of the hidden state vector ht is performed with an activation function for the cell state and the output gate. This hidden state ensures a storage of information over a longer period of time without encountering the vanishing gradient problem. ft = σsig (Wf xt + Uf ht−1 + bf ) (2) it = σsig (Wi xt + Ui ht−1 + bi ) (3) ot = σsig (Wo xt + Uo ht−1 + bo ) ft = σtanh (WC xt + UC ht−1 + bc ) C ft ct = ft ct−1 + it C (4) ht = ot σtanh (ct ) (7) (5) (6) (a) (b) Fig. 3: Schematic structure of a NN without (a) and with (b) Dropout D. Battery Modeling and RNN Hyperparameter Tuning Fig. 2: Schematic structure of an LSTM cell. Choosing the right input features as well as tuning the hyperparameters have a high influence to training speed and model accuracy. 1) Feature Selection: In literature modeling battery bahavior is performed using the terminal current, battery temperature, actual voltage and the SOC as input for ECMs as well as for NN. The proposed approach uses only physical measurable features as input to train the model. The SOC is not an appropriate feature for input since it is just a predicted state with no deterministic value in behind. The SOC delivers the extra information about the current voltage level of the battery, beside the overvoltages occuring during load. A more direct way to detect the actual voltage level is the calculation of Utrend . It is determined as the average of the last voltages in this sequence and is updated after a certain period of time. The update process is a method to reduce the exposure bias problem in teacher forcing algorithms. The four input features to predict the voltage for the next step are: • • • • Terminal current It Temperature Tt Terminal voltage Ut Voltage trend Utrend 2) Hyperparametertuning: Hyperparameters of neural networks have an effect on training speed and accuracy of the model. To optimize the accuracy of a NN the hyperparameters must be tuned. The grid search algorithms drawback is a computational and time intense method, for what reason the optuna algorithm is applied for hyperparameter tuning. Optuna is a hyperparameter optimization framework based on bayesian optimization algorithms. Optuna minimizes the given objective function. In this approach the objective funciton is set to the maximum absolute error on the test set. This metric shows the modeling accuracy even in very hard to predict areas. The tuneable hyperparameters have to be defined including a range or a list of specific values. Each trial chooses the hyperparameters based on the results of the previous trials in view of the objective function. In case one trial is pretty unpromising optunas successive halving pruner prunes a trial. This pruner is a non-stochastic best arm identification method initially introduced by Jamieson et al. [14]. This leads to an efficient way to optimize the hyerparameters. Tuning every hyperparameter in one single optuna study would be very computational itense, due to the huge variable space. Table I shows hyperparamters, which were tuned previously. This predefinition is reasonable, as these parameters are independent from each other. The usage of LSTM layers and batch normalization is justified in subsection II-C and in II-B, respectively. A sequence length of 128 steps is a trade-off between an extensive training time and a too short timedependency. The large training data set makes it necessary to use bigger batch sizes to avoid overfitting. The learning rate of 0.0002 is determined empirically, as well as the loss function and the optimizer. The hyperparameters of figure TABLE I: Pretuned hyperparameters for the LTO and LFP model. Hyperparameter Type of RNN Learning rate Number of epochs Batch size Optimizer Loss function Sequence length Batch normalization Value LSTM 0.0002 100 1024 Adam MSE 128 On II are tuned via the optuna hyperparamtertuning algortithm. They have to be tuned in parallel, as they are influencing each other directly. More hidden layers respectively neurons demand higher dropout rates to prevent overfitting and vice versa. III. A PPLICATION OF P IPELINE TO BATTERIES AND TARGETS The created pipeline for data preparation and model tuning is easily applicable to measurement data of different battery types. Hereafter two applications were conducted to the battery samples introduced in chapter II-A. 1) Training progress: Fig 4 shows the training progress over epochs for both battery samples. The LTO sample takes 59 s training per epoche, whereas the LFP battery takes 95 s training per epoche, both trained on a NVIDIA RTX 2080 Ti GPU with 11 GB RAM using the TensorFlow backend. The differences in training time arises from the different architectures proposed from the optuna algorithm. Fig. 4: Training progress for loss and validation loss of LTO and LFP models 2) Proposed Model Architecture: The results of the applied optuna algorithm is shown in table II. Comparing the two architectures, the LTO chemistry has a smaller NN size with only two hidden RNN layers and 79 neurons each, compared to 105 neurons in each of the three RNN layers of the LFP chemistry. This could be substantiated by the flat open-circuit voltage (OCV) curve of LFP, where more sampling points were needed. In contrast to the theory, that larger networks need higher dropout rates, the LFP network is optimized to a dropout rate of 0.16, compared to 0.4 at LTO. Two attached dense layers seem to be suitable for both applications. IV. VALIDATION U SING T EST-B ENCH M EASUREMENTS Contrary to the training data set, the validation consists of test bench measurements, with the advantage of the possibility to condition and load the battery samples with extreme values. The climate chamber is capable of temperatures in the whole battery samples´ operating areas. Furthermore, an electrical pre-conditioning is feasible, as well as a wide voltage and TABLE II: Hyperparameters tuned by optuna algorithm for the LTO and LFP model. Hyperparameter Units per layer Number of LSTM layers Number of dense layers Dropout rate LTO 79 2 2 0.4 LFP 105 3 2 0.16 current range coverage with a power supply and an electric load. This ensures, that the models accuracy is also validated in the hard-to-predict areas, where the battery samples has high non-linear behavior of the OCV and the internal resistance. The measurement procedure of a validation profile is as follows: • • • • (a) Electrical conditioning to requested SOC Thermal conditioning for at least 12 h Apply current profile Export measured data The validation set of the LTO sample focuses on real-life driving current profiles by using scaled measured currents to reach the batteries´ current and voltage boundaries. The temperature of the 12 profiles in the set ranges between 20°C and 50°C. The LFP validation set consists of ten profiles and is focused on high-current peaks with extreme voltage drops in both directions. Beside single current peaks of about 1 s, this validation set contains even of short volatile profiles. A temperature range between -10°C and 25°C is reached in this set. During training and inference the prediction takes place only within one sequence, whereas in most applications a prediction for a longer period of time is required. In this section the influence of the actual predicted voltage to the next step is investigated, as there is no teacher forcing algorithm applied in this model. Small errors in the beginning could lead to an instability of prediction. Figure 5 shows one validation of the LTO model at -23°C in a low SOC area. The error is not biased, so a prediction instability due to the prediction feedback procedure is non-existent. The offset in the beginning is to be substantiated in the fact, that the validation is conducted on one single battery sample, whereas the modeling takes place on different batteries with their individual properties due to differences in manufacturing and ageing. The optimization algorithm is aligned to reduce the maximum error in the validation set. This leads to a different voltage drop shape between prediction and ground truth. The electrochemical effects in the battery cell results in an exponential voltage course. The predicted voltage is more angular and has a small overshoot when the load stops. Beside this effect, the biggest errors are occurring during the volatile phase, as the overvoltages are hard to predict. In this validation profile an MSE of 0.59 V² and an MaxError of 2.28 V is reached, respectively an MSE of 0.53 V² and an MaxError of 2.34 V in the whole validation set. Figure 6 shows one validation profile of the LFP model at -10°C in a middle SOC range. The error does not increase (b) Fig. 5: Voltage (a) and Error (b) of a validation profile of the LTO Batttery at -23°C and a low SOC. dramatically after the current peak, so a prediction instability due to the prediction feedback procedure is non-existent in this model either. The LFP shows also a similar behavior like the LTO in the voltage relaxation after the voltage peak. The exponential decrease is not of the same shape as the ground truth, but the extent of the voltage peak is predicted well. Although the biggest error occurs during the voltage peak, it is just an issue of shape and timing. Within the peak the error crosses the zero point line but without reaching more than 0.37 V as a maximum Error. The off-set could be explained similar to the one in the LFP model, as there are differences in every battery sample. An overall MSE of 0.37 V² and an MaxErrror of 3.39 V in the validation set can be determined. A comparison between the two models shows that the LFP model has a better MAE, but a worse MaxError. This may be a result of the flat OCV curve of LFP battery cells in medium SOC ranges. Altogether both models have similar accuracies. V. C ONCLUSION In this paper, a new battery voltage modeling method was proposed, specifically without using the SOC as an input feature. Firstly, the raw data is prepared in a pipeline with under-, oversampling, normalization and sequentialization algorithms. Secondly, the RNN-LSTM model is built considering the selected features. The training algorithm uses the optimization framework optuna to find the optimum in the hyperparameter TABLE III: Validation errors of the test set profiles. Profile LTO LFP MAE [V] 0.56 0.33 MaxError [V] 2.34 3.39 MSE [V2 ] 0.53 0.37 (a) (b) Fig. 6: Voltage (a) and Error (b) of a validation profile of the LFP Batttery at 0°C and a medium SOC. space. All these steps are applicable to every type of lithium-ionbatteries, as the presented implementation for an LFP and an LTO 48 V battery stack shows. The feature selection enables real-time applications, since only physical measurable parameters were used. The modeling accuracy is in the region of 1% or between 0.33 V and 0.56 V. The maximum error is below 7%, validated over a wide temperature and power range. The recommended usage of the proposed algorithm can be understood as a tool to generate a voltage battery model, neither with the need for expert knowledge nor premodeling the SOC. Future work could improve the model accuracy in the edge feature regions as well as building up a transmission from the voltage model to a power prediction model. ACKNOWLEDGMENT R EFERENCES [1] European Comission, “Reducing co2 emissions from passenger cars - before 2020,” 2021. [Online]. Available: https://ec.europa.eu/clima/ policies/transport/vehicles/cars en Mean temp [°C] 15.6 4.7 Mean voltage [V] 44.9 45.5 [2] M. Schudeleit, C. Sieg, and F. Küçükay, “The potential of 48v hev in real driving,” 2015. [3] A. H. Ranjbar, A. Banaei, A. Khoobroo, and B. Fahimi, “Online estimation of state of charge in li-ion batteries using impulse response concept,” IEEE Transactions on Smart Grid, vol. 3, no. 1, pp. 360–367, 2012. [4] A. Khalid, A. Sundararajan, I. Acharya, and A. I. Sarwat, “Prediction of li-ion battery state of charge using multilayer perceptron and long shortterm memory models,” in 2019 IEEE Transportation Electrification Conference and Expo (ITEC). IEEE, 19.06.2019 - 21.06.2019, pp. 1–6. [5] C. Li, F. Xiao, and Y. Fan, “An approach to state of charge estimation of lithium-ion batteries based on recurrent neural networks with gated recurrent unit,” Energies, vol. 12, no. 9, p. 1592, 2019. [6] X. Hu, S. E. Li, and Y. Yang, “Advanced machine learning approach for lithium-ion battery state estimation in electric vehicles,” IEEE Transactions on Transportation Electrification, vol. 2, no. 2, pp. 140– 149, 2016. [7] M. Charkhgard and M. Farrokhi, “State-of-charge estimation for lithiumion batteries using neural networks and ekf,” IEEE Transactions on Industrial Electronics, vol. 57, no. 12, pp. 4178–4187, 2010. [8] E. Chemali, P. J. Kollmeyer, M. Preindl, and A. Emadi, “State-of-charge estimation of li-ion batteries using deep neural networks: A machine learning approach,” Journal of Power Sources, vol. 400, pp. 242–255, 2018. [9] D. Jerouschek, Ö. Tan, R. Kennel, and A. Taskiran, “Data preparation and training methodology for modeling lithium-ion batteries using a long short-term memory neural network for mild-hybrid vehicle applications,” Applied Sciences, vol. 10, no. 21, p. 7880, 2020. [10] S. Ioffe and C. Szegedy, “Batch normalization: Accelerating deep network training by reducing internal covariate shift.” [Online]. Available: http://arxiv.org/pdf/1502.03167v3 [11] I. Goodfellow, Y. Bengio, and A. Courville, Deep learning. Cambridge, Massachusetts and London, England: MIT Press, 2016. [Online]. Available: http://www.deeplearningbook.org/ [12] S. Hochreiter and J. Schmidhuber, “Long short-term memory,” Neural computation, vol. 9, no. 8, pp. 1735–1780, 1997. [13] Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, and Ruslan Salakhutdinov, “Dropout: A simple way to prevent neural networks from overfitting,” Journal of Machine Learning Research, vol. 15, no. 56, pp. 1929–1958, 2014. [Online]. Available: http://jmlr.org/papers/v15/srivastava14a.html [14] K. Jamieson and A. Talwalkar, “Non-stochastic best arm identification and hyperparameter optimization.” [Online]. Available: https://arxiv.org/ pdf/1502.07943