# Kalman Filter for State Estimation

• tommyhakinen
In summary, the conversation revolves around the development and implementation of a Kalman Filter for estimating the State of Discharge (SOD) of a battery during the discharging process. The filter is using a Linearized Discrete Time Kalman Filter and involves various codes, including a coefficient for relating measurements and a Kalman gain computation. There is a discussion about the need for tuning the parameters Q and R, which may not be constant due to the non-linear nature of the system. The conversation also includes a request for help and suggestions on how to improve the filter's performance, as it has shown some unexpected behavior in the simulation.

#### tommyhakinen

Hi,

I am not sure if this is the right forum to post this. I am working on a Kalman Filter for battery state of discharge estimation during discharging process. I am using a Linearized Discrete Time Kalman Filter to estimate the State of Discharge/SOD (how much % of charge has been taken away) of a battery. Below are some of the codes.

Coefficient which relates the measurement (on most books it is a matrix, but since I am only having 1 state variable, it is a coefficient)
Hk=c1+2*c2*SOD+3*c3*pow(SOD,2)+4*c4*pow(SOD,3)+5*c5*pow(SOD,4)+6*c6*pow(SOD,5)+7*c7*pow(SOD,6)+8*c8*pow(SOD,7)+9*c9*pow(SOD,8)+10*c10*pow(SOD,9);

c1-c10 are the battery model coefficients to fit the experimental data well.

Kalman gain computation
Kk = (pkmin*Hk)/(Hk*pkmin*Hk+R);

zk = uk - Hk*xkmin;
xkplus = xkmin + Kk*zk;

SOD = SOD + xkplus;
pkplus=(1-Kk*Hk)*pkmin*(1-Kk*Hk)+Kk*R*Kk;

Prediction Updates for the next iteration
Ak = 1; //it is the transition coefficient
xkmin = Ak*xkplus;
pkmin = Ak*pkplus*Ak + Q
;

The idea is to get measurement of the battery terminal voltage to estimates the state of discharge.
The state of the system xkmin is the change in SOD. uk is the change of battery terminal voltage from the actual measurement. R is measurement noise covariance (assumed to be 1). Q is process noise covariance (assumed to be 0.5).

My problem is in order to get the filter to work at its best, both Q and R must not be constant. This is due to the fact that the system is non-linear system which is linearized and both R and Q may be changing with each time step. I have read some research paper on how to do "tuning" of these two parameters, but always ended up with unsuitable approach. If anyone here have experience with Kalman Filter, your help and suggestions would be really appreciated. Thank you in advanced.

This is the MATLAB m-file of the Kalman Filter and the measurement data. I have a good smooth curve but at some point the curve swing out of quite far from the actual values. I am wondering what has cause such behavior. Anyone has experience on this, could you give me some suggestions or idea of what could have caused this. The filter is implemented in Labview but I thought it might not be common to have labview, so I converted it to MATLAB m-file. The picture is actually taken from the simulation in Labview. Thank you in advance.

#### Attachments

• data.zip
106 KB · Views: 174