Code Monkey home page Code Monkey logo

battery_soc_estimation's Introduction

Battery State of Charge Estimation Using Kalman Filter

简体中文

This small project comes from the simulation part of my college graduation design which aimed to estimate the state of charge(SoC) of lithium battery. I mainly finished the experiments, parameters identification and simulation of extended kalman filter(EKF). The completion unscented kalman filter(UKF) simulation needs to thank the contribution from my friend, Pengcheng Gu. And the BBDST working condition block is also benefit from the help of my senior, Cong Jiang. 😘🔋thanks angain to my warm friends.🔋❤

General Content

Li-Battery model building, parameters identification and verification, SoC estimation using extended kalman filter(EKF) through two ways:

  1. Simulinks(EKF only)
  2. Scripts(EKF&UKF)

First Try

The inputs of the model include current and voltage comes from battery data in HPPC(Hybrid PulsePower Characteristic) test.

Thevenin equivalent circuit model and extended kalman filter are included in the simulation file "EKFSim_R2016.slx", of which the structure is shown in the snapshot below.

Simulink

The estimated curve has distinct divergences in the current pulse areas and it converges to the true value in the constant current discharge areas.

The estimated SoC and update Up(voltage of RC element in Thevenin ECM) change synchronously due to the same state vector that they are in, that can be seen in the function block 'EKF'.

Kalman filter update of states including SoC and Up, according to the difference between observed values and predicted values of UL(voltage on the load). The code format of this expression is as following.

X_upd = X_pre + K*(UL_obs-UL_pre);

The output results of the simulation are shown in the figures belows.

States Output

UL curves

Improvement

After improvement, the I/O relationship between modules becomes more perspicuous, the corresponding Simulink file is named Improved_EKFSim.slx.

Improvement

The BBDST(Beijing Bus Dynamic Street Test) working condition is used here as the input current.

BBDST

The output results are shown in the figures belows.

Simulink_EKF_AH

Err

Scripts

MATLAB scripts simulate discharge process of lithium-ion battery under the BBDST working condition and constant current working condition with observation noise, and uses EKF/UKF method to estimate SoC of the battery.

function main(Work_modes, SoC_est_init)

The main function requires two arguments:

  • Work_mode: Choice of working condition with 1 representing BBDST working condition and 2 representing constant current.

  • SoC_est_init: The initial value of estimated SoC, it's set to 1 by default, if just one argument is passed.

Type in command window like main()ormain(1)ormain(1,1), the result curves will appear as follows.

States estimation curve

Related Knowledge

1. Thevenin equivalent circuit model

Thevenin equivalent circuit model(ECM) is a first-order RC circuit. The discharge direction is taken as the positive direction of current, as shown in the figure below.

ECM

The voltage on the polarization capacitor is denoted as Up. Then according to KVL and KCL we get the following equations.

UL(t) = UOC - Up(t) - Ro * I(t)              ······(1)
I(t) = Up(t) / Rp - Cp * (dUp(t)/dt)         ······(2)

The solution of the differential equation (2) is as follows.

Up(t) = C * exp(-t/tao) + I(t) * Rp          ······(3)
tao = Rp * Cp                                ······(4)

Here C is an arbitrary constant. The zero input response of the circuit model corresponds to the idle condition of the battery while zero state response corresponds to the working condition. The discretized form of Up in different states can be unified as follows.

Up(k+1) = Up(k) * exp(-Δt/tao) + 
          Rp * I(k) * (1 - exp(-Δt/tao))     ······(5)

Here Δt denotes the sample interval. The parameters in the Thevenin ECM, including UOC, Ro, Rp and Cp, are deemed to be related to the SoC of the battery. The relationships are usually identified through the so call Hybrid Pulse Power Characterization(HPPC) test.

2. Extended Kalman Filter

The basis of Kalman filter is the process of fusing the information from the prediction and the observation, under the hypothesis that the process error and the observation error are both stochastic noises, obeying Gaussian distributions. The EKF mainly consist of three steps: prediction, linearization and update.

_______________________________________________________
|                                                     |
|    |----------|     |-------------|     |------|    |
---->|prediction|---->|linearization|---->|update|-----
     |----------|     |-------------|     |------|

The prediction needs the knowledge of the state transition, expressed as equation (5) and (6), and observation estimate, expressed as equation (7) and (8).

SoC(k) = SoC(k-1) - eta/Qn * I(k-1)          ······(6)
UL(k) = UOC(k-1) - I(k-1) * Ro - Up(k-1)     ······(7)
UOC(k) = f(SoC(k-1))                         ······(8)

Here eta and Qn denote the coulombic efficiency and the rated capacity of the battery respectively. Let X be the state vector [SoC, Up]', A be the state transformation matrix [1, 0; 0, exp(-Δt/tao)] and B be the input control matrix [-eta/Qn, 0; 0, Rp*(1-exp(-Δt/tao))]. Then equation (5) and (6) can be expressed as follows.

X(k) = A * X(k-1) + B * I(k-1)               ······(9)

The Kalman filter makes use of the process noise and observation noise for the state estimation. Then there's an important step of predicting the covariance of process error, expressed as P.

P(k) = A(k-1) * P(k-1) * A'(k-1) + Q        ······(10)

Here Q is a diagonal matrix containing the variances of the process noises. For the state X=[SoC, Up]', Q is a 2x2 diagonal matrix [Qs, 0; 0, Qu], in which Qs is the variances of process noises for SoC and Qu is that for Up.

Note that UOC is a nonlinear function of SoC, which makes the UL=g(X, I) is nonlinear. The linearization step is Taylor expanding g(X, I) around X(k) with first order approximation.

UL = g(X(k), I(k)) + əg/əX(k) * (X - X(k))  ······(11)
C(k) = əg/əX(k)
     = [əg/əSoC(k) əg/əUp(k)]
     = [ə(UoC-Ro*I(k))/əSoC(k) -1]          ······(12)

Hence UL = C(k) * X + (g(X(k), I(k)) - C(k)*X(k)). C(k) is a constant matrix and (g(X(k), I(k)) - C(k)*X(k)) is a constant too. The linearization is completed.

Based on the result of linearization, the update step include updating the state vector and the covariance of process error by using the variance of observation noise R and observation value UL_ob.

K(k) = P(k) * C'(k) * 
       (C(k) * P(k) * C'(k) + R)^(-1)       ······(13)
X(k) = X(k) + K(k) * (UL_ob - UL(k))        ······(14)
P(k) = P(k) - K(k) * C(k) * P(k)            ······(15)

An Intuitive Derivation of the Kalman filter process is Here. An detailed explanation of UKF is Here.

battery_soc_estimation's People

Contributors

alterwl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

battery_soc_estimation's Issues

Battery parameter r0

Hello Mr Walter,

I am currently working on a BMS and therefore find your work very relevant.
While I was working on your work I noticed that you used functions in Improved_EKFSim.slx to describe the battery parameters like r0 or cp.
I would like to know how you came across these functions.
Secondly I tried to plot ro and came across this picture (see appendix). I find it a bit strange that the internal resistance increases with increasing SOC. Because as far as I know, the battery gets a better conductivity with increasing state of charge (SOC).
I would like to take this opportunity to thank you for this great work and would be glad about your feedback.

With kind regards

SOC_r0

关于EKF滤波算法初值设置问题

我想请教一个问题:在我看的文献中,EKF算法会用到SOC的初始值,我研究了您的仿真,我能力很差,没有找到初值的设置在哪,请问可以加一下您的联系方式再详细的沟通一些吗,谢谢!!!

error in EKF_UKF_Thev

when I am running file its showing flowing

Error in EKF_UKF_Thev (line 13)
States_upd = [SoC_upd_init;0]; % Estimated initial state(SoC_upd, Up_upd)

hi AlterWL

how are you
Please give me your full name if possible
And the title of the paper about this work
This is all for the citation
Thank you waiting for your reply

更改simulink采样周期后曲线发生变化

你好!
我在修改Imporved_EKFSim.slx文件时,将模型的采样频率设置为fixed-step,并同时把采样周期改为0.1s和0.01s跑了一下simulink模型(同时也改了模型中的tr参数和一些延迟模块的采样周期以适配),此时我发现采样周期为0.1s和0.01s的实际SOC值相差有些大,想向你请教一下原因:
采样周期0.1s:
image

采样周期0.01s:
image

非常感谢!

亲爱的作者,您好

关于您的,Improved_EKFSim.slx,文件中我想请教一下您的电池模型是Thevenin模型吗?还是其他的电池模型?
希望得到您的解答。

为什么使用状态方程预估得到的soc为SoC_real?

程序中貌似认定通过状态空间方程预估得到的soc为真实值,且在AH、EKF、UKF的Error计算中使用SoC_real作为基准值。
请问这一做法的依据是什么?
如果通过状态空间方程预估得到的soc为真实值,那么为什么需要AH、EKF、UKF一系列方法呢?

2 RC model

Hi, I am trying to make a 2RC equivalent circuit model using your EKF model. What changes do I need to make in order to run the simulation successfully?. Any help would be appreciated. Thank you.

部分操作不理解

1099b2607fcc7ca97bcb5d7b40d29e6
请问为什么要对电流值做*1.5/50的操作呀,50是安时容量,但是为什么要这么处理

SOC initialization

How to change the initial SOC value in simulink model ?....I just want to check the convergence of EKF model

How to get started as a newbie

Hi~Thanks for sharing!
As a beginner, I am just starting to learn about SOC estimation and parameter identification related to it, and I am not yet able to understand the whole model you provided. Can you recommend any tutorials at an introductory level, preferably one where I can build simulink and code from scratch, appreciated! :D

More information on the information you have modelled this on

Hi AlterWL,
Can you share with me from where you have found these equations to model?
Your work is of great information, very clear compared to many other papers.
Please can you share information from where you have taken these equations as well as if you could share the functions you have used in the thevenin model and the EKF model?
I am still not clear on the UKF so if you could give me all the data you can on these would be of great help for me.
I have about 21 errors running my data on this can you help me?

5 Matlab Errors Thevenin plus EKF
4 Matlab Errors Thevenin plus EKF
3 Matlab Errors Thevenin plus EKF
2 Matlab Errors Thevenin plus EKF
1 Matlab Errors Thevenin plus EKF

Looking to hear from you soon.
Thanks in advance,
Nikhil Supreeth

Different Battery Data Implementation

Dear Authors,

Thank you very much for this work. I have seen the other issues however, there were no clear information about the details of the model.

Here are my questions if you may answer:
1-Why do u multiply your current values with some constants? you had 50 Ah battery so I try to see a point however I could not understand well.
I= -(current.data)' *1.5 / 50;

2-If I use battery data for 450 V (respectively higher current values) why the simulation gives wrong values? Here are some snapshots. I updated the capacity value....

image

3-Are the C0, R or other formulations battery dependent? If yes, how can I find my own formulation or parameters?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.