0% found this document useful (0 votes)
17 views67 pages

3.state of Charge Estimation

Uploaded by

cary.avery602
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views67 pages

3.state of Charge Estimation

Uploaded by

cary.avery602
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

3.1.1: Welcome to the course!

Welcome to the course!

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Welcome to Battery State of Charge (SOC) Estimation!


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 This course is the third in a specialization that investigates


the proper management and control of battery packs, usually comprising many cells
 BMS must estimate nonmeasurable quantities that describe battery pack condition

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 1 of 4

3.1.1: Welcome to the course!

What topics will we study in this course?

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

In this course, you will learn:


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Preparatory definitions, math concepts loop once each measurement interval while pack is active

 How to derive the steps of the linear Kalman filter (KF)


 How to think about and implement the linear Kalman filter
 How to derive and implement the extended Kalman filter (EKF)
 How to derive and implement the sigma-point Kalman filter
(a.k.a., unscented Kalman filter, SPKF/UKF)
 How to solve real-world issues via information provided by
Kalman filter (honors)

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 2 of 4

3.1.1: Welcome to the course!

What skills will you gain in this course?

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

After completing the course, you’ll be able to:


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Implement simple voltage- and current- loop once each measurement interval while pack is active

based SOC estimators and understand their limitations


 Explain purpose of each sequential-probabilistic-inference step
 Execute provided Octave script for linear KF, evaluate results
 Execute provided Octave script for SOC estimation using EKF
on lab-test data, evaluate results
 Execute provided Octave script for SOC estimation using SPKF
on lab-test data, evaluate results
 Implement method to detect and discard faulty voltage-sensor
measurements (honors)

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 3 of 4
3.1.1: Welcome to the course!

Prerequisites; for further study

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

Prerequisites:
loop once each measurement interval while pack is active

 Course 1: Intro. to Battery Management Systems


 Basic background in BMS requirements, sensing
 Course 2: Equivalent Circuit Cell Model Simulation
 Specific background in ESC cell model
 Probability theory (esp. Gaussian random variables)
Resource:
 We’ll study Ch. 3 of Battery Management Systems,
Vol. 2, Equivalent-Circuit Methods, Artech House
 For further study, you can confer this optional resource

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 4 of 4
3.1.2: What is the importance of a good SOC estimator?

States versus parameters

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 A BMS must be able to estimate two fundamentally


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

different types of nonmeasurable battery-pack quantity


 States change quickly (e.g., state-of-charge, diffusion voltage, hysteresis voltage)
 Parameters change slowly (e.g., cell capacities, resistances, aging effects)
 SOC estimate for all cells is important input to balancing, energy, power calculations

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 1 of 6

3.1.2: What is the importance of a good SOC estimator?

Simple versus better

key off: store data


key on: initialize
 While we might be interested in estimating entire meas. voltage
current
temperature
estimate
state of
charge (SOC)
estimate
state of
health (SOH)
balance
cells
compute
power
limits

battery-model state, we first focus on estimating SOC only loop once each measurement interval while pack is active

 You will learn some simple methods that lack robustness


 Then, you will learn methods that estimate entire
battery-model state, enabling more advanced applications
 Recall, SOC is something like a dashboard fuel gauge that
reports a value from “Empty” (0 %) to “Full” (100 %)
 But, while there exist sensors to measure a gasoline level in
a tank accurately, there is (presently) no sensor available to
measure SOC
 And, accurate SOC estimates produce additional benefits. . .

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 2 of 6

3.1.2: What is the importance of a good SOC estimator?

Additional benefits (1)

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

Longevity: If a gas tank is over-filled or emptied, tank is fine


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 However, over-charging or over-discharging a battery cell


loop once each measurement interval while pack is active

may cause permanent damage and result in reduced lifetime


 An accurate SOC estimate may be used to avoid harming cells by not permitting
current to be passed that would cause damage

Performance: Without good SOC estimator, one must be overly conservative when
using battery pack to avoid over/undercharge due to trusting poor estimate
 With a good estimate, especially one with known error bounds, one can
aggressively use the entire pack capacity

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 3 of 6
3.1.2: What is the importance of a good SOC estimator?

Additional benefits (2)

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

Reliability: Poor estimators behave differently for different


current state of state of power
temperature charge (SOC) health (SOH) cells limits

usage profiles (e.g., different vehicle drive cycles)


loop once each measurement interval while pack is active

 A good SOC estimator is consistent and dependable for any driving profile,
enhancing overall power-system reliability

Density: Accurate battery state estimates allow battery pack to be used aggressively
within design limits, so pack doesn’t need to be over-engineered
 This allows smaller, lighter battery packs
Economy: Smaller battery systems cost less. Warranty service on reliable systems
costs less

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 4 of 6

3.1.2: What is the importance of a good SOC estimator?

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 BMS must estimate battery-cell states and parameters


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 This course focuses on estimating battery-cell states


loop once each measurement interval while pack is active

 There are simple state estimators and better state estimators


 You will learn how to implement some of each category
 “Better” state estimators can improve battery-system longevity, performance,
reliability, density, and economy
 It is often worth investing some effort to implement a “better” estimator

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 5 of 6

3.1.2: What is the importance of a good SOC estimator?

Credits

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

Credits for photos in this lesson


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 Gauge on slide 2: Pixabay license (https://pixabay.com/en/service/license/),


https://pixabay.com/en/fuel-gauge-gasoline-measure-meter-40193/

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 6 of 6
3.1.3: How do we define SOC carefully?

A careful definition of state of charge

key off: store data


key on: initialize
 Course 1 introduced an electrochemical definition of SOC
meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Defined lithium concentration stoichiometry:  D cs;avg =cs;max ❝s✱♠ ①


loop once each measurement interval while pack is active

 Stoichiometry is intended to remain between 0% and 100% ✦✶✁✂✄

 Then, cell SOC is computed as: ´k D .k 0% /=.100% 0% /


 Issue: there is (presently) no direct way to measure
concentrations that allow calculating SOC
 So, we must infer or estimate the SOC using measurements of
only cell terminal voltage and cell current
 We’ve already noticed that while cell OCV is closely related to ☎✵✆
SOC, the terminal voltage is a poor predictor of OCV unless the
cell is in electrochemical equilibrium (and hysteresis is negligible)

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 1 of 9

3.1.3: How do we define SOC carefully?

“Fully charged”

key off: store data


key on: initialize
 So, how can we know true cell SOC to evaluate estimators?
meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

 How can we know true SOC for any other purpose? loop once each measurement interval while pack is active

KEY POINT : Some definitions can calibrate our lab tests


DEFINITION : A cell is fully charged when its OCV equals vh .T /,
a manufacturer-specified voltage (may be function of T )
 e.g., vh .25  C/ D 4:2 V for LMO; vh .25  C/ D 3:6 V for LFP
 To bring cell to fully charged state: execute CC charge until
terminal voltage reaches vh .T /, followed by CV until charging
current becomes infinitesimal
 We define the SOC of a fully charged cell to be 100 %

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 2 of 9

3.1.3: How do we define SOC carefully?

“Fully discharged”

key off: store data


key on: initialize

Cell is fully discharged when OCV equals vl .T /,


meas. voltage estimate estimate compute

DEFINITION :
balance
current state of state of power
temperature charge (SOC) health (SOH) cells limits

a manufacturer specified voltage (may be function of T ) loop once each measurement interval while pack is active

 e.g., vl .25  C/ D 3:0 V for LMO; vl .25  C/ D 2:0 V for LFP


 To bring cell to fully discharged state: execute CC discharge
until terminal voltage equals vl .T /, followed by CV until
discharge current becomes infinitesimal
 We define the SOC of a fully discharged cell to be 0 %

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 3 of 9
3.1.3: How do we define SOC carefully?

“Total capacity”

key off: store data


key on: initialize
Cell total capacity Q is quantity of charge
meas. voltage estimate estimate compute

DEFINITION :
balance
current state of state of power
temperature charge (SOC) health (SOH) cells limits

removed as cell is brought from fully charged state loop once each measurement interval while pack is active

to fully discharged state


 SI unit for charge is coulombs (C), but more common to
use units of ampere hours (Ah) or milliampere hours
(mAh) to measure the total capacity of a battery cell
 The total capacity of a cell is not a fixed quantity: it
generally decays slowly over time as the cell degrades

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 4 of 9

3.1.3: How do we define SOC carefully?

“Discharge capacity”

key off: store data


key on: initialize
meas. voltage estimate estimate compute

Discharge capacity QŒrate is quantity of charge


balance

DEFINITION :
current state of state of power
temperature charge (SOC) health (SOH) cells limits

removed as cell discharged at constant rate from fully


loop once each measurement interval while pack is active

charged state until terminal voltage v.t/ reaches vl .T /


 Since based on loaded terminal voltage rather Discharge curves at different C rates
1C rate
than OCV, is strongly dependent on cell’s internal
4
2C rate
Terminal voltage (V)

4C rate
resistance, and so also rate and temperature
3.8 8C rate

 Unless i.t/ ! 0, discharge capacity is less than


3.6

3.4
total capacity

3.2
Likewise, cell SOC is nonzero when terminal
3
voltage reaches vl .T / when i.t/ > 0 0 1 2 3 4
Discharge capacity (Ah)
5 6

 The discharge capacity of a cell at a particular rate and temperature is not a fixed
quantity: it also generally decays slowly over time as the cell degrades

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 5 of 9

3.1.3: How do we define SOC carefully?

“Nominal capacity”

key off: store data


key on: initialize

Cell nominal capacity Qnom is manufacturer-


meas. voltage estimate estimate compute

DEFINITION :
balance
current state of state of power
temperature charge (SOC) health (SOH) cells limits

specified quantity intended to be representative of 1C-rate loop once each measurement interval while pack is active

discharge capacity Q1C of a particular manufactured lot of cells


at room temperature, 25  C
 The nominal capacity is a constant value
 Since nominal capacity is representative of a lot of cells and
discharge capacity is representative of a single individual cell,
Qnom ¤ Q1C in general, even at beginning of life
 Also, since Qnom is representative of a discharge capacity and
not a total capacity, Qnom ¤ Q

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 6 of 9
3.1.3: How do we define SOC carefully?

“Residual capacity” and “state of charge”

key off: store data


key on: initialize
meas. voltage estimate estimate compute

DEFINITION : Cell residual capacity is quantity of charge that


balance
current state of state of power
temperature charge (SOC) health (SOH) cells limits

would be removed from cell if it were brought from its loop once each measurement interval while pack is active

present state to a fully discharged state


DEFINITION : Cell state-of-charge is ratio of residual capacity
to total capacity
 These definitions are consistent with the relationships
Z
1 t
´.t/ D ´.0/ .t/i.t/ dt , and ´k C1 D ´k k ik t=Q
Q 0
that you have already seen

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 7 of 9

3.1.3: How do we define SOC carefully?

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Careful definitions of important quantities important for


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

remainder of the specialization


 Have defined what is meant by “fully charged”, “fully discharged”, “total capacity”,
“discharge capacity”, “nominal capacity”, “residual capacity”, and “state of charge”
 In particular, definition of state of charge is consistent with the equations you
learned in course 2 of the specialization
 Can now build on these definitions to build estimators for any of the above

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 8 of 9

3.1.3: How do we define SOC carefully?

Credits

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

Credits for photos in this lesson


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 Gauge on slides 2–3: Pixabay license (https://pixabay.com/en/service/license/),


modified from
https://pixabay.com/en/fuel-gauge-gasoline-measure-meter-40193/
 Coffee on slide 4: Pixabay license (https://pixabay.com/en/service/license/),
modified from https://pixabay.com/en/coffee-espresso-cup-drink-3129995/
 VHBW cell on slide 6: Raimond Spekking (own work) [CC BY-SA 4.0
(http://creativecommons.org/licenses/by-sa/4.0)], via Wikimedia Commons,
https://commons.wikimedia.org/wiki/File:
VHBW_for_HB5V1HV_Replacement_Li-Ion_Battery-7119.jpg
 Glass on slide 7: Pixabay license (https://pixabay.com/en/service/license/),
modified from https://pixabay.com/en/glass-cognac-smoke-full-empty-300558/

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 9 of 9
3.1.4: What are some approaches to estimating battery cell SOC?

Poor, voltage-based method to estimate SOC

key off: store data


key on: initialize
meas. voltage estimate estimate compute

 We begin to consider the question, “how should we


balance
current state of state of power
temperature charge (SOC) health (SOH) cells limits

estimate battery cell state of charge?”


loop once each measurement interval while pack is active

 One method would be to measure cell terminal 100


True SOC and voltage-based estimate

voltage under load, v.t/, and look up on “SOC


SOC estimate
True SOC

SOC and estimate (%)


80

versus OCV” curve 60


 SOCest = SOCfromOCVtemp(v,T,model);
 Ignores effects of i.t/  R0 losses, diffusion
40

20
voltages, and hysteresis on v.t/
0
 Wide flat areas of OCV curve dilute accuracy of 0 100 200
Time (min)
300 400 500

estimate — very noisy

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 1 of 7

3.1.4: What are some approaches to estimating battery cell SOC?

Poor, voltage-based method to estimate SOC

key off: store data


key on: initialize
meas. voltage estimate estimate compute

 A modification of this method assumes a cell model


balance
current state of state of power
temperature charge (SOC) health (SOH) cells limits

v.t/ D OCV.´.t// i.t/R0 and then looks up


loop once each measurement interval while pack is active

v.t/ C i.t/R0 on “SOC versus OCV” curve 100


True SOC and voltage-based estimate

 SOCest = SOCfromOCVtemp(v+i*R0,T,model); 80 SOC and estimate (%)


SOC estimate
True SOC

 Better, but still ignores effects diffusion voltages, 60


hysteresis and so is still noisy
40
 Filtering helps but adds delay, which must be 20
accounted for
0
 Hysteresis is another complicating factor 0 100 200
Time (min)
300 400 500

 Even though its estimates are noisy, we’ll find an application for this modified
method in the next course

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 2 of 7

3.1.4: What are some approaches to estimating battery cell SOC?

Poor, current-based method to estimate SOC

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Coulomb counting keeps track of charge in, out of cells via


current state of state of power
temperature charge (SOC) health (SOH) cells limits

Z
loop once each measurement interval while pack is active

1 t
Ó .t/ D Ó .0/ b ./imeas./ d
Q 0
imeas .t/ D itrue .t/ C inoise .t/ C ibias .t/ C inonlin .t/ C isd .t/ C ileakage .t/
 Okay for short periods of operation when initial conditions are known or can be
frequently “reset”
 Subject to drift due to current sensor’s fluctuations, current-sensor bias, incorrect
capacity estimate, other losses
 Uncertainty/error bounds grow (without limit) over time until estimate is “reset”

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 3 of 7
3.1.4: What are some approaches to estimating battery cell SOC?

Model-based state estimation

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 An alternative to a voltage-only method or a current-only


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

method is somehow to combine the approaches


 Model-based estimators implement Process Noise Sensor Noise
True System
algorithms that use sensed Input
State
Measured Output

measurements to infer internal hidden System Model


state of dynamic system State Est.
Predicted Output

 Mathematical model of system is assumed known (e.g., ESC cell model)


 Same input propagated through true system, model, measured and predicted
outputs compared; error used to update model’s state estimate
 Output error due to: state, measurement, model errors;
 Update must be done carefully to account for all of these.

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 4 of 7

3.1.4: What are some approaches to estimating battery cell SOC?

Linear Kalman filter

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Under specific conditions, Kalman filter (KF, special case of


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

sequential probabilistic inference) gives optimal state estimate


 We study linear KF and some of its variants throughout remainder of course
 We start by assuming a general, possibly nonlinear, state-space model
xk D f .xk 1; uk 1; wk 1/
yk D h.xk ; uk ; vk /,
where uk is known (measured) input signal, wk is a process-noise random input,
and vk is a sensor-noise random input (ESC cell model fits this framework!)
 Functions f ./ and h./ may be time-varying, but we generally omit time
dependency from notation to avoid clutter

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 5 of 7

3.1.4: What are some approaches to estimating battery cell SOC?

Sequential probabilistic inference

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 KF is special case of sequential probabilistic inference (SPI):


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Estimate present state xk of dynamic system using all


loop once each measurement interval while pack is active

measurements Yk D fy0 ; y1 ;    ; yk g
②✝✞✟ ✠✡☛☞ ✌✍
❖❜s❡r✈✦❞ ❢❨❥❳ ✳✎✏ ✑ ✒ ✓ ✴
❯♥♦✧★✩✪✫✬✭
①❦ ✷ ✁ ✂✄✶ ☎✆
✔ ✕✖✗ ✘✙ ✚ ✛✜ ✢✣✤ ✥
 The observations allow us to “peek” at what is happening in true system
 Based on observations and model, we estimate state
 Process- and sensor-noise randomness always cause imperfect estimates
 So, to understand SPI solution, must study vector random processes

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 6 of 7
3.1.4: What are some approaches to estimating battery cell SOC?

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Direct lookup of terminal voltage in OCV versus SOC table


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

gives very poor estimate of cell SOC


 Modifying lookup to account for ohmic resistance helps, but not enough
 Coulomb counting also has many problems we would like to avoid
 Model-based state estimators combine voltage and current measurements, using a
cell model to do so, to yield better state estimates
 Sequential probabilistic inference is the general framework that describes
model-based state estimators of interest
 We will study SPI this week, as preparation for developing KF solution

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 7 of 7
3.1.5: Understanding uncertainty via mean and covariance

Review of probability

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Sequential probabilistic inference (and hence Kalman filters)


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

seek to find best state estimate in the presence of process


and sensor noises on measurements
 By definition, noise is not deterministic—it is random in some sense
 So, to discuss the impact of noise on the system dynamics, we must understand
(vector) “random variables” (RVs)
 Can’t predict exactly what we will get each time we measure the RV, but
 Can characterize likelihood of different possible measurements by RV’s
“probability density function” (pdf)

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 1 of 6

3.1.5: Understanding uncertainty via mean and covariance

Review of random vectors

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 As review, define random vector X , sample vector x0


current state of state of power
temperature charge (SOC) health (SOH) cells limits

2 3 2 3
loop once each measurement interval while pack is active

X1 x1
6
X2 7 6
x2 7
where X1 through Xn are themselves
XD 6
6 ::
7
7, x0 D 6
6 ::
7
7,
scalar RVs, and x1 through xn are scalar
4 : 5 4 : 5

Xn xn constant values these RVs can take on


 Random vector X described by (scalar function) joint pdf fX .x/ of vector X
 fX .x0 / means fX .X1 D x1 ; X2 D x2 ;    ; Xn D xn /
 fX .x0 / dx1 dx2    dxn is probability that X is between x0 and x0 C dx
 fX .x0 / is scaled probability or “likelihood” of measuring sample vector x0

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 2 of 6

3.1.5: Understanding uncertainty via mean and covariance

Key properties of joint pdf of random vector

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

fZX .x/  0 Z8 x
current state of state of power
cells

1.
temperature charge (SOC) health (SOH) limits

Z 1 1 1
loop once each measurement interval while pack is active

2.  fX .x/ dx1 dx2    dxn D 1


1 1 1 Z
Z 1 1 Z 1
3. xN D EŒX D  xfX .x/ dx1 dx2    dxn
1 1 1
4. Correlation matrix (note outer product, not inner product):
Z 1Z 1 Z 1
†X D EŒXX T  D ::: xx T fX .x/ dx1 dx2    dxn
1 1 1
D X xN . Then,
5. Covariance matrix: Define X
e
1Z 1 Z 1 Z

X D EŒ.X x/.X
†e N N D
x/    .x x/.x
N N T fX .x/ dx1 dx2    dxn
x/
T
1 1 1

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 3 of 6
3.1.5: Understanding uncertainty via mean and covariance

Properties of correlation and covariance

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 †e
current state of state of power

X is symmetric and positive-semi-definite (psd). This means


temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

Xy  0 8 y
y †eT

 Notice that correlation D covariance for zero-mean random vectors


 The covariance entries have specific meaning:
X /i i D X
.†e 2
i

X /ij D ij X X D .†e


.†e i X /j i
j

 The diagonal entries are the variances of each vector component


 Correlation coefficient ij is a measure of linear dependence between Xi and
Xj ; jij j  1

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 4 of 6

3.1.5: Understanding uncertainty via mean and covariance

The multivariable Gaussian pdf

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 There are infinite variety in pdfs; however, we assume only


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

(multivariable) Gaussian pdf in KF


 All noises and the state vector itself are assumed to be Gaussian random vectors
 Gaussian or normal pdf is (we say “X  N .x; N †eX /”)
 
1 1
fX .x/ D exp N T †eX1.x x/
.x x/ N
.2/n=2 †e 1=2 2
X
j†eX j D det.†eX /; †eX1 requires positive-definite †e
X

 Contours of constant fX .x/ are hyper-ellipsoids, centered at xN , rotated via †e


X
 Good news. . . We won’t need to work directly with this equation very much!

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 5 of 6

3.1.5: Understanding uncertainty via mean and covariance

Summary

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 To develop sequential-probabilistic-inference solution, must


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

have background understanding of random variables (RVs)


 RVs are described by probability density functions (pdfs)
 These pdfs have important properties, which we have reviewed
 In particular, we will be making use of mean and covariance a lot
 The pdf we will assume for all RVs is multivariable Gaussian (or normal) distribution
 While this seems complicated at first, it turns out to simplify the math a lot later on

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 6 of 6
3.1.6: Understanding joint uncertainty of two unknown quantities

Independence and uncorrelation

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

INDEPENDENCE : Iff jointly-distributed RVs are independent, then


current state of state of power
temperature charge (SOC) health (SOH) cells limits

fX .x1 ; x2 ; : : : ; xn / D fX1 .x1 /fX2 .x2 /    fXn .xn /


loop once each measurement interval while pack is active

 Means that joint pdf factors into product of marginal pdfs (not generally true)
 “The particular value of the random variable X1 has no impact on what value we
would obtain for the random variable X2 ”. . . no nonlinear or linear relationship
UNCORRELATED : Two jointly-distributed RVs X1 and X2 are uncorrelated iff
cov.X1 ; X2 / D EŒ.X1 xN 1 /.X2 xN 2 /T  D 0
 Can show that this implies that EŒX1 X2T  D EŒX1 EŒX2T : Means that expectation
of a product factors into product of expectations (not generally true)
 Implies 12 D 0; uncorrelated means there is no linear relationship between RVs

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 1 of 7

3.1.6: Understanding joint uncertainty of two unknown quantities

Independence versus uncorrelation

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 In general, condition for RVs to be uncorrelated is much


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

weaker than for them to be independent


 If jointly-distributed RVs X1 and X2 are independent they must also be
uncorrelated: independence implies uncorrelation
 However, uncorrelated RVs are not necessarily independent
 If joint normally (Gaussian) distributed RVs are uncorrelated, are also independent
 This is a (very, very) special case
 This is one of the reasons we assume that all pdfs in the sequential-probabilistic-
inference solution are Gaussian

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 2 of 7

3.1.6: Understanding joint uncertainty of two unknown quantities

Conditional probability

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 We can define a conditional pdf


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

fX jY .x jy/ D fX;Y .x; y/=fY .y/


as the likelihood that X D x given that Y D y has happened
 Note: Marginal pdf fY .y/ may be calculated as
Z1
fY .y/ D fX;Y .x; y/ dx
1
 For each y , integrate out effect of X
 Conditional pdf = joint pdf / marginal pdf (of RV being conditioned on)

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 3 of 7
3.1.6: Understanding joint uncertainty of two unknown quantities

Bayes’ rule

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 As a direct extension of the definition of a conditional pdf,


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

fX;Y .x; y/ D fX jY .x jy/fY .y/


D fY jX .y jx/fX .x/
 Therefore, we can solve for one conditional pdf in terms of other
fY jX .y jx/fX .x/
fX jY .x jy/ D
fY .y/
 This is known as Bayes’ rule
 Relates posterior probability to prior probability, forms a key step in KF derivation

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 4 of 7

3.1.6: Understanding joint uncertainty of two unknown quantities

Conditional expectation

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Can define conditional expectation as what we expect the


current state of state of power
temperature charge (SOC) health (SOH) cells limits

value of X to be given that Y D y has happened


Z
loop once each measurement interval while pack is active

1
EŒX D x jY D y D EŒX jY  D xfX jY .x jY / dx
1
 Conditional expectation is critical
 KF is an algorithm to compute EŒxk j Yk . . . expected value of model state vector
given complete set of measurements made

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 5 of 7

3.1.6: Understanding joint uncertainty of two unknown quantities

Central limit theorem


P
key off: store data
key on: initialize

D X , and X are independent, identically distributed


meas. voltage estimate estimate balance compute

 If Y
current state of state of power
temperature charge (SOC) health (SOH) cells limits

i i i loop once each measurement interval while pack is active

(IID), and have finite mean and variance: then Y is approx.


normally distributed: approximation improves as more RVs are summed
 Special case: linear combination of Gaussian RVs results in a Gaussian RV
 Since state of dynamic system adds up effects of lots of independent random
inputs, reasonable to assume that distribution of state tends to normal distribution
 Leads to key assumptions for derivation of KF, as we will see:
 Assume state xk , process noise wk , sensor noise vk are normally distributed RVs
 Assume wk and vk are uncorrelated with each other
 Even when these assumptions are broken in practice, KF works quite well

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 6 of 7
3.1.6: Understanding joint uncertainty of two unknown quantities

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 If two RVs are independent, joint pdf equals product of


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

marginal pdfs and knowing value of one RV cannot be used to


help predict value of other in any way
 If two RVs are uncorrelated, expected value of product equals product of expected
values and knowing value of one RV cannot be used with linear equation to help
predict value of other
 In most cases, RVs we will work with are correlated, so conditional expectation will
help us to predict value of one RV given values of other(s)
 Central limit theorem justifies assumption that RVs are Gaussian
 Uncorrelated Gaussian RVs are also independent: a very special case

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 7 of 7
3.1.7: Understanding time-varying uncertain quantities

Overview of vector random (stochastic) processes

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 A stochastic or random process is a family of random vectors


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

indexed by a parameter set (“time” in our case)


 For example, we might refer to a random process Xk for generic k
 Value of random process at any specific time k D m is a random variable Xm
 Usually assume stationarity
 The statistics (i.e., pdf) of the RV are time-shift invariant
 Therefore, EŒXk  D xN for all k and EŒXk1 XkT2  D RX .k1 k2 /

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 1 of 7

3.1.7: Understanding time-varying uncertain quantities

Properties and important points

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

D
current state of state of power
cells

EŒXk1 XkT2 .
temperature charge (SOC) health (SOH) limits

1. Autocorrelation: RX .k1 ; k2 / If stationary, loop once each measurement interval while pack is active

RX . / D EŒXk XkTC 
 Provides a measure of correlation between elements of the process having
time displacement 
 RX .0/ D X2 for zero-mean X
 RX .0/ is always the maximum value of RX . /
2. Autocovariance: CX .k1 ; k2 / D EŒ.Xk1 EŒXk1 /.Xk2 EŒXk2 /T . If stationary,
CX . / D EŒ.Xk x/.X
N kC x/ N T

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 2 of 7

3.1.7: Understanding time-varying uncertain quantities

White noise

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 White noise: Some processes have a unique autocorrelation:


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

1. Zero mean
2. RX . / D EŒXk XkTC  D SX . / where . / is the Dirac delta. . / D 0 8  ¤ 0
 Therefore, the process is uncorrelated in time
 Clearly an abstraction, but proves to be a very useful one
White noise Correlated noise
4 0.2

0.15
2
0.1

0.05
Value
Value

0
0

−0.05
−2
−0.1

−4 −0.15
0 200 400 600 800 1000 0 200 400 600 800 1000
Time Time

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 3 of 7
3.1.7: Understanding time-varying uncertain quantities

Shaping filters: Idea

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Will assume noise inputs to dynamic systems are white


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Limiting assumption, but one that can be easily fixed


loop once each measurement interval while pack is active

à Can use second linear system to “shape” the noise as desired.


Pr✻✈✼✽✉✾ ✿❁❝❂❃❄❅ ◆❆❇ ❈❉❊❋■❏❑

❲❤✐t❡ ❙✂❛♣✄❞
✢ ✣✤ ✥ ✙✚ ● ✳③ ✴ ✛✜
♥♦ s✁ ✇❦ ☎✆✝✞✟ ✠✶❀✡

✭✮✯✰
☛☞✌✍✎
❍ ✪✫ ✬ ✦ ✧★ ✩ ②✘
✏✑✒✓✔ ✕✷✖✗
✱✲✵✸✹✺

 Can drive our linear system with noise that has desired characteristics by
introducing shaping filter H.´/ that itself is driven by white noise

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 4 of 7

3.1.7: Understanding time-varying uncertain quantities

Shaping filters: Model

key off: store data


key on: initialize
meas. voltage estimate estimate compute

 Combined system GH.´/ looks exactly the same as before,


balance
current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

but G.´/ is not driven by pure white noise any more


 Analysis augments original system model  Shaping filter with white input and
with filter states. Original system has desired output statistics has
xk C1 D Axk C Bw w1;k xs;k C1 D As xs;k C Bs w2;k
yk D C xk w1;k D Cs xs;k
 Combine into larger-order augmented system driven by white noise:
      
x k C1 A B w Cs xk
xs;k C1
D 0 As xs;k
C 0
Bs
w2;k
 
  xk
yk D C 0 xs;k

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 5 of 7

3.1.7: Understanding time-varying uncertain quantities

Gaussian processes

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 We will work with Gaussian noises to a large extent


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Uniquely defined by the first- and second central moments


loop once each measurement interval while pack is active

of the statistics à Gaussian assumption not essential


 Our filters will always track only the first two moments.

NOTATION : Until now, we have always used capital letters for random variables
 State of system driven by random process is an RV, so we could call it Xk
 More common to retain standard notation xk and understand from context that we
are discussing an RV

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 6 of 7
3.1.7: Understanding time-varying uncertain quantities

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Random process is a family of RVs indexed by time


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 Will assume our random processes are stationary


 Autocorrelation and autocovariance measure self-predictability of a signal at
different time offsets
 White noise is zero mean signal, completely uncorrelated with self (“completely
random”)
 An abstraction, but a very useful one
 If noises in a system of interest are not white, can filter white noise to create same
general characteristics
 From now on, unless stated otherwise, all noise signals will be white and Gaussian

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 7 of 7
3.1.8: Where from here?

Summary of this week

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 This week, you learned:


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Advantages of a good state estimator compared with a


loop once each measurement interval while pack is active

(mathematically or computationally) simple state estimator


 A careful definition of SOC that is compatible with a physical understanding
 Limitations of simple voltage-based and current-based (coulomb counting)
methods for SOC estimation
 The promise of better estimates from model-based estimation
 Accordingly, we reviewed probability concepts to enable future studies

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 1 of 3

3.1.8: Where from here?

Where from here?

key off: store data


key on: initialize
meas. voltage estimate estimate compute

 Next week, you will learn about “Gaussian sequential


balance
current state of state of power
temperature charge (SOC) health (SOH) cells limits

probabilistic inference” state estimation


loop once each measurement interval while pack is active

4/23/18, 3)08 PM

 Under certain assumptions, this gives optimal (minimum


mean-squared error) estimate of system state even when
measurements contain noise
 Will see that this solution has two primary steps, each having
three sub-steps (six steps total)
 Will apply these steps to derive linear Kalman filter
 In following weeks, will apply these steps to derive nonlinear
extended Kalman filter and sigma-point Kalman filter as well

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 2 of 3
file:///Users/glp/OneDrive%20-%20University%20of%20Colorado%20C…ING/MOOC-BMS/COURSE3/FIGURES/FIGURES-3-1-8/ancient-1300292.svg Page 1 of 1

3.1.8: Where from here?

Credits

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

Credits for photos in this lesson


current state of state of power
temperature charge (SOC) health (SOH) cells limits


loop once each measurement interval while pack is active

“Map” on slide 2: Pixabay license


(https://pixabay.com/en/service/license/), from
https://pixabay.com/en/ancient-historic-map-old-parchment-1300292/

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | The importance of a good SOC estimator j 3 of 3
3.2.1: Predict/correct mechanism of sequential probabilistic inference

Vector notation

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 This week, we derive the Kalman filter algorithm, which is a


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

special case of sequential probabilistic inference


 We begin by defining some math notation that we will use from now on
 Superscript “ ” indicates a predicted quantity based only on past measurements
 Superscript “C” indicates an estimated quantity based on both past and present
measurements
 Symbol “ O ” indicates a predicted or estimated quantity: xO C or xO
 Symbol “ Q ” indicates an error: the difference between a true and predicted or
estimated quantity: xQ D x xO

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 1 of 8

3.2.1: Predict/correct mechanism of sequential probabilistic inference

Matrix notation

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Symbol “†” is used to denote correlation between the two


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

arguments in its subscript (autocorrelation if only one is given)


†xy D EŒxy T  and †x D EŒxx T 
 Furthermore, if the arguments are zero mean (as they often are in the quantities we
talk about), then this represents covariance
†xQ yQ D EŒxQ yQ T  D EŒ.xQ Q yQ
EŒx/. Q T
EŒy/
for zero-mean xQ and yQ

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 2 of 8

3.2.1: Predict/correct mechanism of sequential probabilistic inference

Cost function to minimize (optimize)

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Desire state estimate that minimizes “mean-squared error”


current state of state of power
temperature charge (SOC) health (SOH) cells limits

  
loop once each measurement interval while pack is active

O kMMSE.Yk / D arg min E xk xO kC 2 j Yk


2
x
xO k
 
D arg min E .xk xO kC /T .xk xO kC / j Yk
xO k
 
D arg min E xkT xk 2xkT xO kC C .xO kC /T xO kC j Yk
xO k
C
 Solve for xO k by differentiating cost function and setting result to zero
d  T T C

0 D E xk xk 2xk xk O C .xO kC/T xO kC j Yk
dxO C k

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 3 of 8
3.2.1: Predict/correct mechanism of sequential probabilistic inference

Preliminary solution to state estimate

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 To do so, note the following identities from vector calculus,


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

d T d T d T
dX
Y X D Y; dX
X Y D Y; and
dX
X AX D .A C AT /X
 Then,
d  T T C

0 D CE xk xk 2xk xk O C .xO kC/T xO kC j Yk
dxO k
   
D E 2.xk xO kC/ j Yk D 2xO kC
0 2E xk j Yk
 
O kC D E xk j Yk
x

 Desire to find algorithm for computing for EŒxk j Yk

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 4 of 8

3.2.1: Predict/correct mechanism of sequential probabilistic inference

Prediction error and innovation

key off: store data


key on: initialize
Qk D xk xO k
meas. voltage estimate estimate balance compute

 Define prediction
current state of state of power

error where
cells
x
temperature charge (SOC) health (SOH) limits

 
O D E xk j Yk
loop once each measurement interval while pack is active

xk 1
 Error is always “truth minus prediction” or “truth minus estimate”
 We can’t compute error in practice, since truth value is not known
 But, we can prove statistical results using this definition that give an algorithm for
estimating the truth using measurable values
 Also, define the measurement innovation (what is new or unexpected
 in the
measurement) as yQk D yk O
yk where yOk D E yk j Yk 1

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 5 of 8

3.2.1: Predict/correct mechanism of sequential probabilistic inference

Prediction error and innovation are zero mean

key off: store data


key on: initialize

 Both xQ k and yQk can be shown to be zero mean using


meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

  
method of iterated expectation: EY EX jY X j Y D EX X
loop once each measurement interval while pack is active

          
Q D E xk E E xk j Yk 1 D E xk E xk D 0
E xk
          
E yQk D E yk E E yk j Yk 1 D E yk E yk D 0
 Note also that xQ k is uncorrelated with past measurements as they have already
been incorporated into xO k
       
E xQ k j Yk 1 D E xk E xk j Yk 1 j Yk 1 D 0 D E xQ k

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 6 of 8
3.2.1: Predict/correct mechanism of sequential probabilistic inference

Predict/correct solution

key off: store data


key on: initialize
 
Q j Yk
meas. voltage estimate estimate balance compute

 Consider now expanding the relationship E


current state of state of power
cells
xk
temperature charge (SOC) health (SOH) limits

     
loop once each measurement interval while pack is active

E Q j Yk D E„ xkƒ‚j Yk
xk E xO k j Yk
„ ƒ‚
xO kC xO k

 This is true because xO k D EŒxk j Yk 1  is a constant vector, and further


conditioning on Yk has no additional effect
 We can also expand this relationship a different way
     
Q j Yk D E xQ k j Yk 1; yk D E xQ k j yk
E xk
 
 Combining both expansions, we have xO kC D xO k C E xQ k j yk , which is a
predict/correct sequence of steps, as promised

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 7 of 8

3.2.1: Predict/correct mechanism of sequential probabilistic inference

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 You learned meaning of notation we use, including


current state of state of power
temperature charge (SOC) health (SOH) cells limits

superscripts “ ” and “C”, symbols “ O ” and “ Q ”, and symbol “†”


loop once each measurement interval while pack is active

 We are solving a minimum mean-squared-error


 problem to find a state estimate
 Initial solution was xO kC D EŒxk j Yk
 
 Later refined this to be xO kC D xO k C E xQ k j yk
 A predict/correct structure

 But, what is EŒxQ k j yk ? That’s what we look at next

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 8 of 8
3.2.2: The Kalman-filter gain factor

Pathway to finding Kalman gain

key off: store data


key on: initialize
O C D xO C ExQ j y 
meas. voltage estimate estimate balance compute

 So far, we have derived


current state of state of power

state estimate
cells
x
temperature charge (SOC) health (SOH) limits

  k k k k
 But, what is E xQ k j yk ?
loop once each measurement interval while pack is active

 To evaluate this expression, we consider very generically the problem of finding


f .x j y/ if x and y are jointly Gaussian vectors
 We combine x and y into an augmented vector X where
     
D yNN
  †xQ †xQ yQ
X D x
y
; E X
x
; †e
X D †yQ xQ †yQ

 We will then apply this generic result for f .x j y/ to our specific problem of
determining f .xQ k j yk / by setting x D xQ k and y D yk
 
 We can then use this conditional pdf to find E xQ k j yk

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 1 of 9

3.2.2: The Kalman-filter gain factor

Expanding the conditional pdf

key off: store data


key on: initialize
 To proceed, we first write f .x j y/ D f .x; y/=f .y/
meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 Note that this is proportional to


   T    !
exp 1 x xN † 1
x N
x

f .x; y/
2 y yN e
X y N
y
/   ,
f .y/ exp 1
2 .y N T
y/ †yQ 1 .y y/N
where the constant of proportionality is not important to subsequent operations
 Recall that exp.A/= exp.B / D exp.A B /. . . which we take advantage of next

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 2 of 9

3.2.2: The Kalman-filter gain factor

Condensing the exponential term

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 The combined exponential argument becomes


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

   T    
1 x xN 1 x x N C 21 .y y/
N T †yQ 1 .y y/
N
2 y yN †
e
X y y N
 To condense notation somewhat, define xQ D x xN and yQ D y yN
 Then, the terms in the exponent become,
 T  
1 xQ 1 xQ C 1 yQ T † 1yQ
yQ yQ yQ
†
2 e
X 2

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 3 of 9
3.2.2: The Kalman-filter gain factor

Inverting covariance (step 1)

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 To proceed, we must invert †e


current state of state of power

X . To do so, we substitute the


temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

following transformation (which you can verify)


     
†xQ †xQ yQ †xQ yQ †yQ 1 †xQ †xQ yQ †yQ 1 †yQ xQ
†yQ xQ †yQ
D I
0 I 0
0
†yQ
I
†yQ 1 †yQ xQ
0
I

 Then,
  1   1  1  1
†xQ †xQ yQ †xQ †xQ yQ †yQ 1 †yQ xQ †xQ yQ †yQ 1
†yQ xQ †yQ
D I
1
†yQ †yQ xQ
0
I 0
0
†yQ
I
0 I
   
.†xQ †xQ yQ †yQ 1 †yQ xQ / 1 0 †xQ yQ †yQ 1
D I
†yQ 1 †yQ xQ
0
I 0 †yQ 1
I
0 I

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 4 of 9

3.2.2: The Kalman-filter gain factor

Inverting covariance (step 2)

key off: store data


key on: initialize
D †xQ
meas. voltage estimate estimate balance compute

 Defining Schur complement of †: M †xQ yQ †yQ 1 †yQ xQ ,


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

1
exponent D 2
Q T 1
x M x Q xQ T M 1†xQ yQ †yQ 1yQ yQ T †yQ 1†yQxQ M 1xQ

C yQ T †yQ 1†yQxQ M 1†xQ yQ †yQ 1yQ C yQ T †yQ 1yQ yQ T †yQ 1yQ
 Last two terms cancel; remaining terms can be grouped as
1  
exponent D 2
Q
x
1 T
†xQ yQ †yQ y M
1
x Q Q 1
†xQ yQ †yQ y Q
 In terms of only the original variables, exponent is
 T   1 
1
2
x N C †xQ yQ †yQ
x
1
.y N
y/ †xQ †xQ yQ †yQ †yQ xQ
1
x x N C †xQ yQ †yQ 1
.y N
y/

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 5 of 9

3.2.2: The Kalman-filter gain factor

A solution to the generic conditional Gaussian

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Comparing this exponent to Gaussian standard form


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 T   1 
1
2
x N C †xQ yQ †yQ 1.y y/
x N †xQ
1
†xQ yQ †yQ †yQ xQ x x N C †xQ yQ †yQ 1.y y/
N
 Infer that mean of f .x j y/ must be xN C †xQ yQ †yQ 1 .y y/
N
 Infer that covariance of f .x j y/ must be †xQ †xQ yQ †yQ 1 †yQ xQ
 So, we conclude that
f .xj y/  N .xN C †xQ yQ †yQ 1.y y/;
N †xQ 1
†xQ yQ †yQ †yQ xQ /
     
E x j y D E x C †xQ yQ †yQ y E y
1

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 6 of 9
3.2.2: The Kalman-filter gain factor

State update equation

key off: store data


key on: initialize
D yQk C yOk , we get
meas. voltage estimate estimate balance compute

 Applying this to our problem, when yk


current state of state of power
temperature charge (SOC) health (SOH) cells limits

     
loop once each measurement interval while pack is active

E Q j yk D Q C
xk E xk †xQ y;k
Q Q
1
†y;k yk E yk
   
D Q C E xk †xQ y;k
Q †y;k
1
Q yk Q C yOk E yQk C yOk

D C 0 †xQ y;k
Q †y;k
1
Q yk yk Q C O .0 C yOk / D †xQ y;k Q yQk
1
Q †y;k „ ƒ‚
Lk
 Putting all of the pieces together, we get the general update equation:
xO C D xO C L yQ k k k k

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 7 of 9

3.2.2: The Kalman-filter gain factor

Uncertainty of state estimate

key off: store data


key on: initialize
 State-estimate covariance (uncertainty) †C
meas. voltage estimate estimate balance compute
current state of state of power

xQ ;k is
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

C     T
†xQ ;k D E .xk xO kC/.xk xO kC/T D E .xk xO k / Lk yQk .xk xO k / Lk yk Q
  
D E xQ k Lk yQk xQ k Lk yQk T
    T
D †xQ ;k Lk „E yQkƒ‚
.x k yQk Lk C Lk †y;k
Q k /T „E xQƒ‚ T
Q Lk
T

†y;k
Q LT
k
Lk †y;k
Q

D †xQ ;k Q Lk
Lk †y;k
T

 Final output of Gaussian sequential probabilistic inference has two parts:


1. State estimate. Best guess of present state value, xO kC
2. Covariance estimate. Uncertainty of xO kC , †C
xQ ;k can yield error bounds

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 8 of 9

3.2.2: The Kalman-filter gain factor

Summary

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Generic Gaussian sequential probabilistic inference recursion:


current state of state of power
temperature charge (SOC) health (SOH) cells limits


loop once each measurement interval while pack is active

O kC D xO k C Lk yk yOk D xO k C Lk yQk
x
C
†xQ ;k D †xQ ;k
T
Q Lk
Lk †y;k

where
     
O D E xk j Yk 1
xk †xQ ;k D E .xk xO k /.xk xO k /T D E .xQ k /.xQ k /T
     
O kC D E xk j Yk
x
C
†xQ ;k D E .xk O kC/.xk xO kC/T D E .xQ kC/.xQ kC/T
x
     
Ó k D E ´k j Yk 1 Q D E .yk yOk /.yk yOk / D E .yQk /.yQk /
†y;k
T T
 
Lk D E .xk O k /.yk yOk / †y;k Q D †xQ y;k
T 1 1
x Q †y;k
Q
 Note that this is a linear recursion, even if the system is nonlinear(!)

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 9 of 9
3.2.3: Summarizing the six steps of generic sequential probabilistic inference

Steps 1a–1b

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Generic Gaussian probabilistic inference solution can be


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

divided into two main steps, each having three sub-steps


 General step 1a: State prediction time update
 Each time step, compute an updated prediction of the present value of xk , based
on prior information and the system model
   
O D E xk j Yk
xk 1 D E f .xk 1 ; uk 1 ; wk 1 / j Yk 1
 General step 1b: Error covariance time update
 Determine the predicted state-estimate error covariance matrix †xQ ;k based on
prior information and the system model
 
 We compute †xQ ;k D E .xQ k /.xQ k /T , where xQ k D xk xO k

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 1 of 5

3.2.3: Summarizing the six steps of generic sequential probabilistic inference

Step 1c

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 General step 1c: Predict system output yk


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Predict the system’s output using prior information


loop once each measurement interval while pack is active

   
O D E yk j Yk
yk 1 D E h.xk ; uk ; vk / j Yk 1
 Summarizing general step 1
Step 1a: State prediction time update

Prediction
Step 1b: Error covariance time update

Step 1c: Predict system output

Step 2a: Estimator gain matrix


Correction

Dr. Gregory L. Plett j University of Colorado Colorado Springs


Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 2 of 5
Step 2b: State estimate measurement update
3.2.3: Summarizing the six steps of generic sequential probabilistic inference
Step 2c: Error covariance measurement update
Step 2

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 General step 2a: Estimator gain matrix Lk


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Compute the estimator gain matrix Lk D †xQ y;k 1


loop once each measurement interval while pack is active

Q †y;kQ
 General step 2b: State estimate measurement update
 Compute the posterior state estimate by updating the prediction using the Lk and
the innovation yk O
yk

O C D xO k C Lk .yk
xk O
yk /

 General step 2c: Error covariance measurement update


 Compute the posterior error covariance matrix
C  C 
†xQ ;k D E .x Q k /.xQ kC/T
D †xQ ;k Lk †y;k Q Lk
T

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 3 of 5
Step 1a: State prediction time update

Prediction
Step 1b: Error covariance time update
3.2.3: Summarizing the six steps of generic sequential probabilistic inference

Summarizing step 2

key off: store data


key on: initialize
Step 1c: Predict system output meas. voltage estimate estimate balance compute

 Summarizing general step 2:


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

Step 2a: Estimator gain matrix

Correction
Step 2b: State estimate measurement update

Step 2c: Error covariance measurement update

 KEY POINT : Estimator outputs state estimate xO kC , error covariance estimate †C


xQ ;k q
 That is, we have high confidence that the truth lies within xO kC  3 diag.†C
xQ ;k /
 Estimator then waits until next sample interval, updates k , proceeds to step 1a

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 4 of 5

3.2.3: Summarizing the six steps of generic sequential probabilistic inference

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute
current state of state of power
Step 1a: State prediction time update temperature charge (SOC) health (SOH) cells limits

✂ ✝ ✠ ✚
①❖❦ ❉ ❊ ✁ ✄ ❥ ❨☎✆✶ ✞ ✟ ❢ ✳✡ ☛☞✌ ❀ ✉ ✍✎✏ ✑ ✇✒✓✔ ✴ ✕ ✖✗✘✙ ✛
loop once each measurement interval while pack is active

Prediction
Step 1b: Error covariance time update
✧ ✷ ✺
✻✢✜◗✣✤ ✥ ✦ ★✪✩✬✫ ✭✮✰✯✲✱ ✵❚ ✸ ✹ ✼✽ ✾ ✿ ❂❁❄❃ ❅❆❇ ❈ ❋ ❍●❏■ ❑▲ ❪▼
Step 1c: Predict system output
❯ ❴ ❜ ③
②◆P ❘ ❙ ❱❲ ❳ ❩❬❭❫ ❵ ❛ ❤❝❞ ❡ ❣ ✐ ❧ ♠ ✈ ♥ ♦ ♣ qrst ④
Step 2a: Estimator gain matrix
⑤ ⑥ ⑦ ⑧❶⑨⑩❸❷ ❹❺ ❻ ❼❽
❿❾ ➀➁ ➂
Correction

Step 2b: State estimate measurement update


➄➃➆➅ ➇ ➉➈➋➊ ➌ ➍ ➎ ➏➐➑ ➒ ➔➓→ ➣↔
Step 2c: Error covariance measurement update
↕➜➙➛➝➞ ➟ ➠➤➡➢➥➦ ➧ ➨ ➩ ➫ ➯➭ ➲➳ ➵ ➺➸ ➻

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 5 of 5
3.2.4: Deriving the three Kalman-filter prediction steps

Application to linear systems: Kalman filter

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 We now apply general Gaussian sequential probabilistic


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

inference solution to specific case of a linear system


 Linear systems have desirable property that all pdfs remain Gaussian if stochastic
inputs are Gaussian, so the assumptions made in deriving filter steps hold exactly
 The linear Kalman filter assumes that the system being modeled can be
represented in the “state-space” form
xk D Ak 1xk 1 C Bk 1uk 1 C wk 1
yk D Ck xk C Dk uk C vk

 Input is uk , output is yk , state is xk ; process noise is wk , sensor noise is vk

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 1 of 7

3.2.4: Deriving the three Kalman-filter prediction steps

Assumptions on noises

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 We assume that wk and vk are mutually uncorrelated white


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

Gaussian random processes, with zero mean and covariance


matrices having known value:
( (

EŒwn wkT  D
†e
w; n D kI EŒvn vkT  D
†vQ ; n D kI
0; n ¤ k: 0; n ¤ k,

and EŒwk x0T  D 0 for all k


 The assumptions on the noise processes wk and vk and on the linearity of system
dynamics are rarely (never) met in practice, but the consensus of the literature and
practice is that the method still works very well

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 2 of 7

3.2.4: Deriving the three Kalman-filter prediction steps

Deriving the linear Kalman filter (1a)

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 KF step 1a: State prediction time update.


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Here, we compute the predicted state


loop once each measurement interval while pack is active

 
O D E f .xk 1; uk 1; wk 1/ j Yk 1
xk
 
D E Ak 1xk 1 C Bk 1uk 1 C wk 1 j Yk 1
     
D E Ak 1xk 1 j Yk 1 C E Bk 1uk 1 j Yk 1 C E wk 1 j Yk 1
D Ak 1xO kC 1 C Bk 1uk 1,
by the linearity of expectation, noting that wk 1 is zero-mean
 INTUITION: When predicting the present state given only past measurements, the
best we can do is to use the most recent state estimate and system model,
propagating the mean forward in time

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 3 of 7
3.2.4: Deriving the three Kalman-filter prediction steps

Deriving the linear Kalman filter (1b)

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 KF step 1b: Error covariance time update


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 First, we note that the prediction error is xQ k D xk xO k , so


loop once each measurement interval while pack is active

Q D xk xO k D Ak 1xk 1 C Bk
xk 1 uk 1 C wk 1 O kC 1
Ak 1 x Bk 1 uk 1

D Ak 1xQ kC 1 C wk 1
 Therefore, the covariance of the prediction error is
   
†xQ D E .x
k
Q k /.xQ k /T D E .Ak 1xQ kC 1 C wk 1/.Ak 1xQ kC 1 C wk 1/T
 
D E Ak 1xQ kC 1.xQ kC 1/T ATk 1 C wk 1.xQ kC 1/T ATk 1 C Ak 1xQ kC 1wkT 1 C wk 1wkT 1
D Ak 1†CxQ ;k 1ATk 1 C †ew
 Therefore cross terms drop out of the final result since the white process noise
wk 1 is not correlated with the state at time k 1 and is zero mean

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 4 of 7

3.2.4: Deriving the three Kalman-filter prediction steps

Intuition for step 1b

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute


current state of state of power

INTUITION : When estimating state-prediction error covariance temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

†xQ D Ak C T
C †ew
k 1 †xQ ;k 1 Ak 1
 Best to use most recent covariance estimate and propagate forward in time
 For stable systems, Ak 1 †C T
xQ ;k 1 Ak 1 is contractive: covariance gets “smaller”
 State of stable systems always decays toward zero in absence of input, or
toward a known trajectory if uk ¤0
 Term tells us that we tend to get increasingly certain of state estimate over time
 On the other hand, †e
w adds to the covariance
 Unmeasured inputs add uncertainty to our estimate because they perturb the
trajectory away from the known trajectory based only on uk

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 5 of 7

3.2.4: Deriving the three Kalman-filter prediction steps

Deriving the linear Kalman filter (1c)

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 KF step 1c: Predict system output


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 We predict the system output as


loop once each measurement interval while pack is active

   
O D E h.xk ; uk ; vk / j Yk 1 D E Ck xk C Dk uk C vk j Yk
yk 1
    
D E Ck xk j Yk 1 C E Dk uk j Yk 1 C E vk j Yk 1
D Ck xO k C Dk uk ,
since vk is zero-mean
 O is best guess of system output, given only past measurements.
INTUITION : yk
 The best we can do is to predict the output given the output equation of the
system model, and our best guess of the system state at the present time

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 6 of 7
3.2.4: Deriving the three Kalman-filter prediction steps

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 We have started to specialize the general Gaussian


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

sequential-probabilistic-inference steps to the special case of


a linear system, to develop the Kalman-filter equations
 The general steps are not implementable as computer programs, since they involve
statistical operations (expected values)
 However, the specialized Kalman-filter steps we have developed so far are
completely valid program operations
 By examining the equations, we can gain insight into the operation of a Kalman filter
and have confidence that it is performing reasonable actions

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 7 of 7
3.2.5: Deriving the three Kalman-filter correction steps

Finding the Kalman gain matrix

key off: store data


key on: initialize
 KF step 2a: Estimator (Kalman) gain matrix Lk D †xQ y;k
meas. voltage estimate estimate balance compute

1
current state of state of power
cells

Q †y;k
Q
temperature charge (SOC) health (SOH) limits

 To compute the Kalman gain, we must first compute several


loop once each measurement interval while pack is active

covariance matrices: we first find †y;k


Q
Q D yk yOk D Ck xk C Dk uk C vk Ck xO k Dk uk D Ck xQ k C vk
yk
 
Q D E .Ck xQ k C vk /.Ck xQ k C vk /
T
†y;k
 
D E Ck xQ k .xQ k /T CkT C vk .xQ k /T CkT C Ck xQ k vkT C vk vkT
D Ck †xQ ;k CkT C †vQ .
 Cross terms are zero since vk is zero mean and is uncorrelated with xQ k

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 1 of 8

3.2.5: Deriving the three Kalman-filter correction steps

Finding the Kalman gain matrix

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 We now find †xQ y;k


current state of state of power

Q :
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

   
EŒxQ k yQkT  D E Q
xk .Ck xk Q C vk /T D E xQ k .xQ k /T CkT C xQ k vkT
D T
†xQ ;k Ck

 Combining †y;k
Q and †xQ y;k
Q in Lk D †xQ y;k 1
Q ,
Q †y;k
Lk D †xQ ;k CkT ŒCk †xQ ;k CkT C †vQ  1

 INTUITION : Note that the computation of Lk is the most critical aspect of Kalman
filtering that distinguishes it from a number of other estimation methods
 The whole reason for calculating covariance matrices is to be able to update Lk
 Lk is time-varying: It adapts to give the best update to the state estimate based
on present conditions

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 2 of 8

3.2.5: Deriving the three Kalman-filter correction steps

Finding the Kalman gain matrix

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute


current state of state of power

(continued): Recall that we use Lk in the equation


cells
INTUITION
temperature charge (SOC) health (SOH) limits

O C D xO k C Lk .yk O
loop once each measurement interval while pack is active

xk yk /

Q , indicates relative need for correction to xO k and


 The first component to Lk , †xQ y;k
how well individual states within xO k are coupled to the measurements
Q D †xQ ;k Ck
 We see this clearly in †xQ y;k T

 †xQ ;k tells us about state uncertainty at the present time, which we hope to reduce
as much as possible
 A large entry in †xQ ;k means that the corresponding state is very uncertain and
therefore would benefit from a large update
 A small entry in †xQ ;k means that the corresponding state is very well known
already and does not need as large an update

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 3 of 8
3.2.5: Deriving the three Kalman-filter correction steps

Finding the Kalman gain matrix

key off: store data


key on: initialize
Q D
meas. voltage estimate estimate balance compute

 †xQ ;k CkT
current state of state of power

INTUITION (continued): Continuing to look at †xQ y;k


temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 The CkT term gives the coupling between state and output
 Entries that are zero indicate that a particular state has no direct influence on a
particular output and therefore an output prediction error should not directly
update that state
 Entries that are large indicate that a particular state is highly coupled to an
output so has a large contribution to any measured output prediction error;
therefore, that state would benefit from a large update

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 4 of 8

3.2.5: Deriving the three Kalman-filter correction steps

Finding the Kalman gain matrix

key off: store data


key on: initialize
(continued): Still looking at Lk D †xQ y;k
meas. voltage estimate estimate balance compute

 1
current state of state of power

Q ,
cells
INTUITION Q †y;k
temperature charge (SOC) health (SOH) limits

 †yQ tells us how certain we are that measurement is reliable


loop once each measurement interval while pack is active

 If †yQ is “large,” we want small, slow updates


 If †yQ is “small,” we want big updates
 This explains why we divide the Kalman gain matrix by †yQ
 The form of †yQ D ŒCk †xQ ;k CkT C †vQ  can also be explained
 Ck †xQ CkT indicates how error in state contributes to error in output estimate
 †vQ term indicates uncertainty in sensor reading due to sensor noise
 Since sensor noise is assumed independent of the state, uncertainty in
Q D yk
yk ykO adds the uncertainty in yk to the uncertainty in yOk

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 5 of 8

3.2.5: Deriving the three Kalman-filter correction steps

Finding the Kalman gain matrix

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 KF step 2b: State estimate measurement update


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Computes a posteriori state estimate by updating a priori


loop once each measurement interval while pack is active

estimate using estimator gain and output prediction error yk ykO


OC
x
k D xO k C Lk .yk O
yk /

 INTUITION : yk O
is predicted measurement, based on present state prediction
 Therefore, yk yOk is what is unexpected or new in the measurement
 We call this term the innovation. The innovation can be due to a bad system
model, state error, or sensor noise
 So, we want to use this new information to update the state, but must be careful
to weight it according to the value of the information it contains
 Lk is the optimal blending factor, as we have already discussed

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 6 of 8
3.2.5: Deriving the three Kalman-filter correction steps

Finding the Kalman gain matrix

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 KF step 2c: Error covariance measurement update


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Finally, we update error covariance matrix


loop once each measurement interval while pack is active

C T
†xQ ;k D †xQ ;k Q Lk D †xQ ;k Lk †y;k
T T
Lk †y;k Q †y;k
Q †xQ y;k
Q
D †xQ ;k Lk Ck †xQ ;k
D .I Lk Ck /†xQ ;k
 INTUITION :
A covariance matrix is positive semi-definite, and Lk †y;kQ LTk is also a
positive-semi-definite form, and we are subtracting this from the predicted-state
covariance matrix; therefore, the resulting covariance is “lower” than the
pre-measurement covariance
 Measurement update has decreased our uncertainty in state estimate

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 7 of 8

3.2.5: Deriving the three Kalman-filter correction steps

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Have now derived the entire Kalman filter algorithm


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 Next week, you will learn how to implement and visualize KF


 KEY POINT: Repeating from before, recall that the estimator output comprises the
state estimate xO kC and error covariance estimate †C xQ ;k q
 That is, we have high confidence that the truth lies within xO kC  3 diag.†C
xQ ;k /
 COMMENT: If a measurement is missed for some reason, then skip steps 2a–c for
that iteration. That is, set Lk D 0 and xO kC D xO k and †C xQ ;k D †xQ ;k

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 8 of 8
3.2.6: Where from here?

Summary of this week

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 This week, you learned:


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 That the generic MMSE solution is EŒxk j Yk 


loop once each measurement interval while pack is active

 That generic Gaussian probabilistic inference solution uses predict/correct


recursion to find this solution
 Predict and correct steps both have three sub-steps
 With certain assumptions, can specialize these steps to linear Kalman filter

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 1 of 3

3.2.6: Where from here?

Where from here?

key off: store data


key on: initialize
 Will apply linear KF to linearized battery-cell model to help
meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

visualize the steps involved


loop once each measurement interval while pack is active

 See how to simulate random systems as preparation for


evaluating KF via simulation
 Learn how to implement KF in Octave/MATLAB and evaluate
results computed by the KF
 Some “improvements” to KF to handle real-world numeric
round-off issues
 How KF also provides helpful ways to detect sensor faults

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 2 of 3

3.2.6: Where from here?

Credits

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

Credits for photos in this lesson


current state of state of power
temperature charge (SOC) health (SOH) cells limits


loop once each measurement interval while pack is active

“Map” on slide 2: Pixabay license


(https://pixabay.com/en/service/license/), from
https://pixabay.com/en/map-treasure-pirate-309928/

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Introducing the linear Kalman filter as a state estimator j 3 of 3
3.3.1: Visualizing the Kalman filter with a linearized cell model

Visualizing the linear Kalman filter

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Linear Kalman-filter equations naturally form a recursion:


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

Initialization
①❖✵❈ ✱ ✻✁◗ ❀✂ ➎➏➐➑ ➒➓➔→ ➣↔↕➙➛➜➝ ➞➟➠➡➢➤➥➦➧ ➨
1a 2c  “Simple” to implement on
☎✄❦✆ ❉ ❆✝✞✶ ✠✟☛☞✌
✡ ✍ ❇✎✏✑ ✉ ✒✓✔ ⑩❸❶❷❹❺ ❻ ❼❽ ❾ ❿ ➀ ➁➂ ➃➄➇➅➆➈➉ a digital computer
1b 2b  However, note that our
✕✘✖✗✙✚ ✛ ✜✢✣✤ ✥★✦✧✩✪✫✬ ✭✮✯✰
❚ ✲✳✇❡
Meas. ❤❣❥✐ ❧ ♥♠♣♦ q r s t③④ ⑤ ⑦⑥⑧ ⑨ cell models are nonlinear,
Meas.
1c
➌➍
2a ➊➋ so we cannot apply
②✴✷ ✸ ✹✺ ✽✼✿✾ ❁ ❂❃ ❄ ❅ ▲ ❊ ❋●❏❍■❑▼ ◆❘P ❬❙❯ ❱❨❲❳❩❭ ❪❴❫ ❵❛✈❜ ❝❞❢ (linear) Kalman filter to
them directly

Prediction Correction

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 1 of 8

3.3.1: Visualizing the Kalman filter with a linearized cell model

Setting up a demonstration (1)

key off: store data


key on: initialize
meas. voltage estimate estimate compute

 To demonstrate the KF steps, we’ll develop


balance
current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

and use a crude cell model


OCV versus SOC for four cells at 25°C
1
´ k C1 D 1  ´ k ik
3600  Q
4
Open-circuit voltage (V)

voltk D 3:5 C 0:7  ´k R0 ik 3.5

 Notice that we have:


3
 Linearized the OCV relationship
 Omitted diffusion voltages 2.5

 Omitted hysteresis voltages 0 20 40 60 80 100


State of charge (%)

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 2 of 8

3.3.1: Visualizing the Kalman filter with a linearized cell model

Setting up a demonstration (2)

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Model still isn’t linear because of “3.5” in output equation


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Debias measurement via yk D voltk 3:5 and use


loop once each measurement interval while pack is active

D 1  ´k 36001  Q ik
OCV versus SOC for four cells at 25°C
´ k C1
4
Open-circuit voltage (V)

yk D 0:7  ´k R0 ik
 Define state xk  ´k and input uk  ik
3.5

 For the sake of example, we will use 3

Q D 10000=3600 and R0 D 0:01


 Yields state-space description with A D 1, 2.5

B D
1  10 4 , C D 0:7, and D D 0:01 0 20 40 60 80 100

w D 10 , and †vQ D 0:1


State of charge (%)
 We also model †e 5
 We assume no initial uncertainty so xO 0C D 0:5 and †C
xQ ;0 D 0

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 3 of 8
3.3.1: Visualizing the Kalman filter with a linearized cell model

Iteration 1

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 We look at the first iteration of the linear KF, assuming


current state of state of power
temperature charge (SOC) health (SOH) cells limits

D 1, i1 D 0:5 and v1 D 3:85


loop once each measurement interval while pack is active

i0
①❖❦ ❉ ❆✁✂✶ ☎✄✆✝✞❈ ✟ ❇✠✡☛ ✉ ☞✌✍ ✏✎✒✑ ✓ ✔ ✕ ✵✿✺ ✖ ✗✘✙✹ ✚ ✛ ✜ ✢✣✤✾✥✦
✻★✧◗❀✩ ✪ ✫✬✭✮ ✯✲✰✱✳✴✷✸ ✼✽❁❂ ❚ ❃ ❄✇❡ ❅●❊❋❍■ ❏ ❑ ▲ ▼ ◆ P ❘ ❙❯❱❲ ❳ ❨❩❬❭
②❪❫ ❴ ❵❛ ❝❜❢❞ ❣ ❤✐ ❥ ❧ ♥♠♦ ♣ qrs t ✈③④⑤⑥⑦ ⑧ ⑨⑩❶❷ ❸ ❹❺❻ ❼ ❽❾❿➀➁➂➃
➄ ➅ ➆ ➇➊➈➉➋➌ ➍➏➎ ➐➑➒ ➓➣➔→↔↕ ➙➜➛ ➝➞➠➟ ➡➢➤ ➥ ➦ ➧ ➨➩➫➭ ➯ ➲➳➵➸➺➻➼➽ ➾ ➚➪➶➹ ➘ ➴➷➬➮➱✃
❐ ❒❮❰ÏÐÑÒÓÔÕÖ×
ÙØÛÚ Ü ÞÝàß á â ã äåæ ç éèê ë ÿþ✶❈ ❉ ✵✿✹✾ ✁ ✂ ✻✄☎✆✝✞✟✠✡☛☞✺ ✳✌✍✸✎ ✏ ✑✒✓✔✕✖✗✴
ìíîïðñ òó ô õö÷ø ù úûüý ✘ ✙✚✛✜✢✣✤✥✦

✧ ①★ ✱
◗ ❀❦ ✩ ✪■ ✫ ▲ ✬ ✭ ✮ ✯✰✷✼✽
✲ ❁ ❄❂ ❯❱
❃ ❅❆ ❇ ❊❋ ● ❍❏❑▼◆❖P❘❙❚ ❲ ❳❨❩❬ ❭ ❪❫
❴❵
❧♠
p ❛ ❜❝❞❡❢❣❤✐❥

 Output: Ó D 0:4999  3 9:9995  10 6 D 0:4999  0:0094866


Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 4 of 8

3.3.1: Visualizing the Kalman filter with a linearized cell model

Iteration 2

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 For the second iteration of the linear KF, let


current state of state of power
temperature charge (SOC) health (SOH) cells limits

D 0:5, i2 D 0:25, and v2 D 3:84


loop once each measurement interval while pack is active

i1
❈ ✟ ❇✠✡☛ ✉ ☞✌✍
①❖❦ ❉ ❆✁✂✶ ☎✄✆✝✞ ✏✎✒✑ ✓ ✵✿✹✾✔✕✖✗✘ ✙ ✚✛✜✢ ✣ ✤✥✺ ✦ ✧★✩✪✫✽✬
✻✮✭◗❀✯ ✰ ✱✲✳✴ ✷❁✸✼❂❃❄❅ ❊❋●❍
❚ ■ ❏✇❡ ❑ ▲ ❙ ❯❱❲❳❨❩❬❭❪❫❴ ❵ ❛❜❝❞ ❢ ❣❤✐❥❧♠♥♦♣qrs
◆▼ P❘

②t✈ ③ ④⑤ ⑦⑥⑨ ⑩ ❶❷ ❸ ❹ ❻❺❼ ❽ ❾❿➀➁➂➃➄➅➆➇➈ ➉ ➊➋➌➍ ➎ ➏➐➑➒ ➓ ➔→➣↔↕➙➛➜
➡ ➨ ➳
➝ ➞ ➟ ➠➤➢ ➥➦ ➧➩ ➫➭➯ ➲➸➵ ➺➻ ➼➾ ➚➪➹➶ ➘ ➬ ➮ ➱ ✃❐❒❮❰ÏÐÑÒÓÔÕ Ö ×ØÙÚÛÜÝÞßàáâãäåæ ç èéêë ì íîïðñò
➽ ➴➷
ó ôõö÷øùúûüý
ÿþ❦❈ ❉ ①❖✁ ✂ ▲ ✄ ✳②☎ ✆ ✞✝✟ ✴ ✑✏✷✒ ✓ ✵✔✕✾✖✗✘ ✙ ✚✛✜✢✣✶✤✥✦✧★✩✪✫✬ ✯ ✰✱✲✻✼❀❁❂❃
✭✇❤❡r✠ ✡☛ ☞ ✸✿✽✹ ✌ ✍✎✺✮ ❄ ❅❆❇❊❋●❍■
❏▼❑◗◆P ❘ ❙❚ ❯ ❱ ❲ ❳❨ ❩❬❫❭❪❴❵ ❛❞❜❝❢❣ ✐ ❥❧ ♠ ♥♦♣qst✉✈③④ ⑤ ⑥⑦⑧⑨ ⑩ ❶❷❸❹❺❻❼❽❾❿➀➁
➂ ➃➄➅➆➇➈➉➊➋➌➍➎
p
 Output: Ó D 0:4998  3 1:99976  10 5 D 0:4998  0:013416
Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 5 of 8

3.3.1: Visualizing the Kalman filter with a linearized cell model

Covariance

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Note that covariance (uncertainty) converges over time


current state of state of power
temperature charge (SOC) health (SOH) cells limits

✆✟✝✞✠✷ ✡ ☛✿✾☞✌✍✎✏✑✒✓✔ ✕✘✖✗✙✸ ✚ ✛✜✢✣✤✼✥✦✧★✩✪


loop once each measurement interval while pack is active

✻①◗ ❀✶ ❉ ✁✂✄✵☎✺

✫✭❈✬✮✯ ✰ ✱ ✲✹✳✴✽❁ ❂ ❃❄❅❆❇❊❋●❍■❏❑ ▲❖▼◆P❘ ❙ ❚❯❱❲❳❨❩❬❭❪❫❴ ❵❝❛❜❞❡ ❢ ❣❤✐❥❦❧♠♥♦♣qr

 Covariance increases during propagation, is then reduced by each measurement


 Covariance still oscillates in steady state between †xQ ;ss and †C
xQ ;ss
q C
 Estimation error bounds are 3 †xQ ;k for 99 % assurance of estimate’s accuracy
C

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 6 of 8
3.3.1: Visualizing the Kalman filter with a linearized cell model

Results

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 The plots below show a sample of the Kalman filter operating


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 We’ll soon look at how to write code to evaluate this example


▼❛❧♠◆♥ ❖Pt❡r ✐◗ ❘❝❯❱♦❲ ❊r❂♦❃ ❝❄✈❛❅✐❆♥❇❡ ❉①❋ ▲
◗ ●❦ ❍❏❞ ❑◆▼ ❖P
★✩✪ ✢✣✤✥
✥✦✧

✢✣✤ ❀
✿ ✙✚✛✜

×
❀✿ ✚✛✜ ❚❁❂❃ ✷✵
✴✷ ❊❄❅❆❇❈❉❋ ✴
❙ ✗✘✙ ●❍❏❑▲ ✲✳✱
✰✯ ✕✖✗✘
✔✕✖ ✮
❈ ❘❯❙


❱❨❲

✲✑✒✓ ✑✒✓✔
✸ ✁ ✹✂✄ ✺☎✆ ✻✝✞ ✼✟✠ ✽✡☛ ✾☞✌ ✶✍✎✏ ✸ ✁ ✹✂✄ ✺☎✆ ✻✝✞ ✼✟✠ ✽✡☛ ✾☞✌ ✶✍✎✏
■✫✬✭✮✯✰✱✳ ■✦✧★✩✪✫✬✭

 Note that Kalman filter does not perform especially well since †vQ is quite large
 However, these are best-possible results, since KF is the optimum MMSE estimator
Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 7 of 8

3.3.1: Visualizing the Kalman filter with a linearized cell model

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 KF implements an MSEE-optimal state estimator for linear


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

systems if assumptions regarding system noises are met


 KF equations naturally form a recursive algorithm for estimating the state
 While the KF works only for linear systems, we can linearize system dynamics for
an approximate result (will learn better ways later)
 Example with a simplified battery model demonstrates the kinds of results you can
expect from a KF
 The KF will provide a state estimate. . .
 And uncertainty bounds (error bounds) on that estimate
 We will find this very helpful for SOC estimation

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 8 of 8
3.3.2: Introducing Octave code to generate correlated random vectors

Generating correlated random vectors

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Straightforward to implement KF steps in Octave


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 To exercise KF code, however, also must simulate system


whose state is being estimated
 Produces system input/output data as input to the KF
 Provides “true” state value at every point in time
 But, to simulate true system, must be able to create nonzero mean Gaussian noise
with covariance †e Y.
 That is, we want Y  N .y; N †eY / but randn.m returns X  N .0; I /.
 How to convert X to Y ?

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 1 of 5

3.3.2: Introducing Octave code to generate correlated random vectors

A needed transformation

key off: store data


key on: initialize
 Suppose that we can find matrix A such that AT A D †e
meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

Y loop once each measurement interval while pack is active

 Then, we generate samples x of random vector


X  N .0; I / and compute samples y of random vector Y D yN C AT X
 Since X is zero-mean, EŒY  D EŒyN C AT X  D yN , as desired
 The covariance of Y is
EŒ.Y N
y/.Y N T
y/  D EŒ.AT X /.AT X /T 
D EŒ.AT X /.X T A/
D AT E„ŒXX
ƒ‚
T
 A D †eY;
I
also as desired

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 2 of 5

3.3.2: Introducing Octave code to generate correlated random vectors

Important matrix factorizations

key off: store data


key on: initialize

 So, if we can find A such that AT A D †e


meas. voltage estimate estimate balance compute
current state of state of power

Y , we can generate
temperature charge (SOC) health (SOH) cells limits

samples x of X  N .0; I / and compute y D yN C AT x


loop once each measurement interval while pack is active

 Three ways to generate A


Y computes A such that A A D †e
 Cholesky factorization of †e T
Y as long as †eY is
positive definite (all eigenvalues are strictly greater than zero)
Y produces L, D such that LDL D †e
 LDL factorization of †e T
Ypand requires
only that †eY be positive semi definite: Can then compute A D DLT

Y produces L, U such that LU D †e


 LU factorization of †e Yand requires
 only that p
Y be
†e positive semi definite: Can then compute A D diag diag.U / LT
 Cholesky and LU are built into Octave; all are built into MATLAB

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 3 of 5
3.3.2: Introducing Octave code to generate correlated random vectors

Example Octave code

key off: store data


key on: initialize
meas. voltage estimate estimate compute

 Suppose we wish to generate a single


balance
current state of state of power
temperature charge (SOC) health (SOH) cells limits

sample of y using Cholesky method:


loop once each measurement interval while pack is active

ybar = [1; 2];


5000 samples with mean [1;2] and
covar = [1 , 0.5; 0.5 , 1];
covar [1,0.5; 0.5,1]
A = chol ( covar ) ; 5
x = randn ([2 , 1]) ;
y = ybar + A '* x ; 4

 Suppose we wish to generate 5000

y coordinate
3

samples of y using the LU method: 2


ybar = [1; 2];
covar = [1 , 0.5; 0.5 , 1]; 1
[L , U ] = lu ( covar ) ;
0
A = diag ( sqrt ( diag ( U ) ) ) *L ';
x = randn ([2 ,5000]) ; −1
y = ybar (: , ones ([1 5000]) ) +A '* x ; −4 −2 0 2 4 6
x coordinate
plot ( y (1 ,:) ,y (2 ,:) , '. ') ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 4 of 5

3.3.2: Introducing Octave code to generate correlated random vectors

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 In order to test KF code via simulation, must also simulate


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

system whose state is being estimated


 This requires ability to simulate (possibly) correlated (possibly nonzero mean)
noises
 Octave natively produces samples of zero-mean uncorrelated Gaussians only
 But, can transform these to have desired mean and correlation using a matrix
determined using either the Cholesky or LU matrix decompositions, both of which
are built into Octave

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 5 of 5
3.3.3: Introducing Octave code to implement KF for linearized cell model

Introduction to lesson

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 In this lesson, you will learn how to implement KF in Octave


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Recommend you have KF equations nearby as reference


loop once each measurement interval while pack is active

w D †vQ D 1 and
 Code will be demonstrated for simulated system where †e
xk D xk 1 C uk 1 C wk 1
yk D xk C vk
 Can be modified in straightforward ways to simulate other systems having other
noise sources

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 1 of 7

3.3.3: Introducing Octave code to implement KF for linearized cell model

Initializing the simulation

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 The code begins with some definitions, initializations


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

% Initialize simulation variables


SigmaW = 1; % Process noise covariance
SigmaV = 1; % Sensor noise covariance
A = 1; B = 1; C = 1; D = 0; % Plant definition matrices
maxIter = 40; % Number of iterations to execute simulation

xtrue = 0; % Initialize true system initial state


xhat = 0; % Initialize Kalman filter initial estimate
SigmaX = 0; % Initialize Kalman filter covariance
u = 0; % Unknown initial driving input : assume zero

% Reserve storage for variables we want to plot / evaluate


xstore = zeros ( length ( xtrue ) , maxIter +1) ; xstore (: ,1) = xtrue ;
xhatstore = zeros ( length ( xhat ) , maxIter ) ;
SigmaXstore = zeros ( length ( xhat ) ^2 , maxIter ) ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 2 of 7

3.3.3: Introducing Octave code to implement KF for linearized cell model

KF step 1

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Code continues with main KF loop, step 1


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

for k = 1: maxIter ,
% KF Step 1 a : State estimate time update
xhat = A * xhat + B * u ; % use prior value of " u "

% KF Step 1 b : Error covariance time update


SigmaX = A * SigmaX *A ' + SigmaW ;

% [ Implied operation of system in background , with


% input signal u , and output signal z ]
u = 0.5* randn (1) + cos ( k / pi ) ; % for example ...
w = chol ( SigmaW ) '* randn ( length ( xtrue ) ) ;
v = chol ( SigmaV ) '* randn ( length ( C * xtrue ) ) ;
ytrue = C * xtrue + D * u + v ; % z is based on present x and u
xtrue = A * xtrue + B * u + w ; % future x is based on present u

% KF Step 1 c : Estimate system output


yhat = C * xhat + D * u ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 3 of 7
3.3.3: Introducing Octave code to implement KF for linearized cell model

KF step 2

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Code continues with main KF loop, step 2


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

% KF Step 2 a : Compute Kalman gain matrix


SigmaY = C * SigmaX *C ' + SigmaV ;
L = SigmaX *C '/ SigmaY ;

% KF Step 2 b : State estimate measurement update


xhat = xhat + L *( ytrue - yhat ) ;

% KF Step 2 c : Error covariance measurement update


SigmaX = SigmaX - L * SigmaY *L ';

% [ Store information for evaluation / plotting purposes ]


xstore (: , k +1) = xtrue ; xhatstore (: , k ) = xhat ;
SigmaXstore (: , k ) = SigmaX (:) ;
end

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 4 of 7

3.3.3: Introducing Octave code to implement KF for linearized cell model

Plot results

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Finally, there is code to plot results


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

figure (1) ; clf ;


plot (0: maxIter -1 , xstore (1: maxIter ) ', 'k - ' ,...
0: maxIter -1 , xhatstore ' , 'b - - ' , ...
0: maxIter -1 , xhatstore '+3* sqrt ( SigmaXstore ) ', 'm -. ' ,...
0: maxIter -1 , xhatstore ' -3* sqrt ( SigmaXstore ) ', 'm -. ') ; grid ;
legend ( ' true ' , ' estimate ' , ' bounds ') ;
title ( ' Kalman filter in action ') ;
xlabel ( ' Iteration ') ; ylabel ( ' State ') ;

figure (2) ; clf ;


plot (0: maxIter -1 , xstore (1: maxIter ) '- xhatstore ' , 'b - ' ,...
0: maxIter -1 ,3* sqrt ( SigmaXstore ) ', 'm - - ' ,...
0: maxIter -1 , -3* sqrt ( SigmaXstore ) ', 'm - - ') ; grid ;
legend ( ' Error ' , ' bounds ' ,0) ; title ( ' Error with bounds ') ;
xlabel ( ' Iteration ') ; ylabel ( ' Estimation Error ') ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 5 of 7

3.3.3: Introducing Octave code to implement KF for linearized cell model

Sample results

key off: store data


key on: initialize

w D †vQ D 1, and
meas. voltage estimate estimate balance compute

 Plots show sample output from KF for †e


current state of state of power
temperature charge (SOC) health (SOH) cells limits

D xk 1Cuk 1Cwk
loop once each measurement interval while pack is active

xk 1 ❿➀➁➂➃ ➄➅➆➇ ➈➉➊➋➌➍

D xk C vk
❑✯❧♠✰✱ ✳✴✻✼✽ ✾✿ ❀❝❁❂❃❄
✒✓ ❭

yk ✏✑
t✔✕✖
❡✗✘✙✚✛✜✢
❜✣✤✥✦✧

❽ ❬


❺ ❩

 Error never converges ✭✮


✬✫
✎ ❹
❷❸❶ ❨

to zero, but stays ❙ ✍
⑨⑧ ❲❳ ❪❫❴❵❞
⑦ ❢❣❤❥❦♣

within predicted ☞✌
⑤ ❯❱

bounds (both as ✲✡☛


✵ ✺ ✶ ✁✂ ✷✄ ☎✆ ✸✝ ✞✟ ✹✠
❘❚
❅ ❆ ❇❈ ❉❊ ❋● ❍❏ ▲▼ ◆❖ P◗

expected)
■★✩r❛✪✐♦♥ qs✉✈✇①②③④

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 6 of 7
3.3.3: Introducing Octave code to implement KF for linearized cell model

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 You have now learned how to


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Implement KF code in Octave


loop once each measurement interval while pack is active

 Cosimulate a system of interest with the KF to validate KF performance


 Code can be used to estimate state of any linear system obeying KF assumptions
 Sample results give intuitive sense for what to expect from KF

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 7 of 7
3.3.5: Can we automatically detect bad measurements with a Kalman filter?

Real-world issue: Voltage-sensor faults

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Sometimes systems for which we would like a state estimate


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

have sensors with intermittent faults


 Would like to detect faulty measurements and discard them
 Time update steps of the KF still implemented
 Measurement update steps are skipped (Lk D 0)
 KF provides elegant theoretical means to accomplish this goal. Background:
 Predicted measurement is yOk D Ck xO k C Dk uk
 Prediction covariance (uncertainty) matrix is †y;k
Q DC k †xQ ;k CkT C †Q v

 The innovation is yQk D yk yOk

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 1 of 7

3.3.5: Can we automatically detect bad measurements with a Kalman filter?

Measurement validation gating

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Can place “measurement validation gate” on measurement


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

using normalized estimation error squared (NEES)


ek2 D yQkT †y;k
Q yQk
1

 NEES ek2 has Chi-squared distribution with m degrees of freedom, where yk 2R m

 If ek2 is outside of bounding value for Chi-squared distribution for a desired


confidence level, then measurement is discarded
 Note: If a many measurements are discarded in short time interval, sensor may
truly have failed, or state estimate and covariance may have gotten “lost”
 Is sometimes helpful to “bump up” covariance † Q ;k , which simulates additional
x
process noise, to help Kalman filter to reacquire
 Both done in practice to aid robustness of a real implementation

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 2 of 7

3.3.5: Can we automatically detect bad measurements with a Kalman filter?

NEES is chi-squared

key off: store data


key on: initialize

 To prove NEES is chi-squared, define ´k D Mk yQk


meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Mean of ´k is EŒ´k  D EŒMk yQk  D 0


loop once each measurement interval while pack is active

 Covariance of ´k is † Q́ ;k D EŒMk yQk yQkT MkT  D Mk †y;k


Q MkT
 ´k is Gaussian (since it is a linear combination of Gaussians)
 If we define Mk such that MkT Mk D †y;k 1
Q , then
 Mk is the lower-triangular Cholesky factor of †y;k
Q
1


 Also, ´k  N .0; I / since † Q́ D M M M M D M M M M D I ;k k
T
k k
1 T
k k k
1
k
T T
k
 NEES e D ´ ´ D yQ † Q yQ is the sum of squares of independent N .0; 1/ RVs
2
k
T
k k
T
k
1
y;k k

 So, e is chi-square with m degrees of freedom, where m is the dimension of yQ


2
k k

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 3 of 7
3.3.5: Can we automatically detect bad measurements with a Kalman filter?

What does this really mean?

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 ek2 never negative (sum of squares); pdf also asymmetric


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 pdf of chi-square RV X having m degrees of freedom is


1
fX .x/ D x .m=2 e

1/ m=2 ✛ ❞✐str✢❜✉✣✦♦♥ ✇✧★❤ ✩ ✪❡❣✫✬✭✮ ✯✰ ✱✲✶✹✺✻♠

2 m=2
€.m=2/ ✓✔✕✖

✏✑✒

 Tricky, but don’t need to evaluate in real time ✴



✳ ☞✌✍✎ ✥✗✘✙

 Instead, use value precomputed from pdf ❢


❉ ✠✡☛

 For 1 confidence of a valid measurement, P




need to find 2U such that there is area above


✆✝✞✟

2U (figure drawn for D 0:05)



✸ ✼ ✁✂✄☎

 Discard measurement if NEES greater than 2U ✚

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 4 of 7

3.3.5: Can we automatically detect bad measurements with a Kalman filter?

Computer calculation of U
2

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 In MATLAB (Statistics and Machine Learning Toolbox) can


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

find 2U where inverse CDF is equal to 1


X2U = chi2inv (1 -0.01 ,2) % Upper critical value X2U = 9.2103

 Function “chi2inv” is built in to Octave


 Note that 2U needs to be computed once only, offline
 Based only on m and , so doesn’t need to be recalculated as KF runs
 For hand calculations a 2 -table is available on next page
 If ek2 > 2U , then measurement is discarded (Lk D 0); else, measurement kept

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 5 of 7

3.3.5: Can we automatically detect bad measurements with a Kalman filter?

Manual table-lookup of U
2

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 For chi-squared distribution with m degrees of freedom, table


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

entries list values of 2U . ; m/ for specified upper tail area


Degrees of Upper tail areas
freedom m 0.25 0.10 0.05 0.025 0.01 0.005
1 1.323 2.706 3.841 5.024 6.635 7.879
2 2.773 4.605 5.991 7.378 9.210 10.597
3 4.108 6.251 7.815 9.348 11.345 12.838
4 5.385 7.779 9.488 11.143 13.277 14.860
5 6.626 9.236 11.070 12.833 15.086 16.750
6 7.841 10.645 12.592 14.449 16.812 18.548

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 6 of 7
3.3.5: Can we automatically detect bad measurements with a Kalman filter?

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 KF has built-in mechanism that enables detecting


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

voltage-sensor errors
 Once only, off-line, precompute 2U . ; m/ for yk 2 Rm and desired
 As KF executes, every time sample, compute ek2 D yQkT †y;k
Q yQk
1

 If ek2 > 2U . ; m/, then discard measurement (set Lk D 0)


 Otherwise, apply measurement update as usual
 If many sequential measurements discarded, consider “bumping up” covariance as
†C C
Q ;k D Q†xQ ;k where Q > 1
x
 If problems persist, likely a permanent sensor fault

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 7 of 7
3.3.6: How do I initialize and tune a Kalman filter?

Real-world issue: Initialization

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 If battery load is “off” for a “long” time, just assume that cell
current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

voltage is equivalent to OCV:


 Reset SOC estimate based on OCV
 Set diffusion voltages to zero
 Keep prior value of hysteresis state
 If load has been off for a “short” period of time
 Set up and execute simple time/measurement update (simple KF) equations for
SOC and diffusion voltages
 Hysteresis voltages do not change
 Run a single-step Kalman filter to update state estimate based on total time off

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 1 of 7

3.3.6: How do I initialize and tune a Kalman filter?

Real-world issue: Tuning x;0 Q †

key off: store data


key on: initialize
meas. voltage estimate estimate compute

 KF “tuning” accomplished via changing †xQ ;0 , †e


balance

w , †vQ
current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Ideally, †xQ ;0 D EŒ.x0 xO 0C /.x0 xO 0C /T 


loop once each measurement interval while pack is active

 Since we don’t know x0 exactly, not possible to initialize xO 0C


to exactly correct value: Uncertainty in xO 0C captured by †xQ ;0
 If we assume model states uncorrelated, †xQ ;0 is diagonal
 We often make this assumption simply because we have
no better information regarding state correlation
 Diagonal elements in †xQ ;0 are variances of initial
estimation errors of the corresponding state elements in x
 Set diagonal elements of †xQ ;0 such that you expect true state
p
to lie between xO 0C  3 diag.†xQ ;0 /

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 2 of 7

3.3.6: How do I initialize and tune a Kalman filter?

Real-world issue: Tuning †ew


key off: store data
key on: initialize

meas. voltage estimate estimate balance compute

 Assuming model of cell is perfect, †e


current state of state of power

w is covariance matrix of
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

“process noise” wk driving cell

C D Axk C B uk C wk
xk 1

 Process noise is any unmeasured (zero-mean, white) input that affects state vector
 If wk chosen to model current-sensor noise, then †e
w can be determined
statistically via experimentation
 But, as no model is perfect, †w also attempts to capture—in some way—state-
e
equation inaccuracies, so should have larger uncertainty than simply representing
current-sensor noise alone

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 3 of 7
3.3.6: How do I initialize and tune a Kalman filter?

Real-world issue: Tuning †v Q

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Assuming model of cell is perfect, †vQ is the covariance matrix


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

of “measurement noise” vk
yk D C xk C Duk C vk
 Measurement noise is any unmeasured (zero-mean, white) input that doesn’t affect
state vector, but which does corrupt measurements
 If vk chosen to model voltage-sensor noise, then †vQ can be determined statistically
via experimentation (or data sheet)
 But, as no model is perfect, †vQ also attempts to capture—in some way—output-
equation inaccuracies, so should have larger uncertainty than simply representing
voltage-sensor noise alone

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 4 of 7

3.3.6: How do I initialize and tune a Kalman filter?

Rate of convergence

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Filter convergence rates are determined by †e


current state of state of power

w and †vQ
temperature charge (SOC) health (SOH) cells limits

 Large †e
loop once each measurement interval while pack is active

w says “trust sensor more than model” and makes


state error bounds large
 Large †vQ says “trust model more than sensor” and converges slowly (pseudo
open loop)
 Since model inaccuracies are difficult to quantify, some trial-and-error “tuning” of
e
†w and †vQ is common
 In some cases (noisy sensors or bad model), desired state-estimate accuracy and
convergence rates are simply impossible
 In general, it is not possible to have arbitrarily fast convergence to arbitrarily narrow
error bounds

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 5 of 7

3.3.6: How do I initialize and tune a Kalman filter?

Summary

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 You have learned how to set †xQ ;0 during initialization


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 You have seen tips on tuning †e


w , which represents process-
noise (e.g., current-sensor noise and inaccuracies in state equation) uncertainty
 You have seen some tips on tuning †vQ , which represents sensor-noise (e.g.,
voltage-sensor noise and inaccuracies in voltage equation) uncertainty
 Since model inaccuracies are difficult to quantify, some trial-and-error “tuning” of
e
†w and †vQ is common
 e
Since convergence rates depend on †w and †vQ , it is not possible in general to
have arbitrarily fast convergence to arbitrarily narrow error bounds
 Still, KF is optimal MMSE estimator for the assumptions made during derivation

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 6 of 7
3.3.6: How do I initialize and tune a Kalman filter?

Credits

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

Credits for photos in this lesson


current state of state of power
temperature charge (SOC) health (SOH) cells limits


loop once each measurement interval while pack is active

Tuning fork on slide 2: By Helihark (own work) [CC BY-SA 3.0


(http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons,
https://commons.wikimedia.org/wiki/File:Tuning-fork.jpg

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 7 of 7
3.3.7: Where from here?

Summary of this week

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 This week, you learned:


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 How to apply linear KF to linearized battery-cell model to


loop once each measurement interval while pack is active

help visualize the steps involved


 How to simulate random systems as preparation for evaluating KF via simulation
 How to implement Kalman filter in Octave/MATLAB and evaluate results
computed by the filter
 Some “improvements” to KF to handle real-world numeric round-off issues
 How KF also provides helpful ways to detect sensor faults

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 1 of 3

3.3.7: Where from here?

Where from here?

key off: store data


key on: initialize
 How to generalize state-state model to describe nonlinear
meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

systems
loop once each measurement interval while pack is active

 How to apply two assumptions to derive the extended


Kalman filter from the generic Gaussian
sequential-probabilistic-inference solution
 How to write Octave/MATLAB code to implement EKF for a
simple example and for the battery-cell state-estimation
problem
 See some examples of applying EKF to estimate cell SOC
using lab-test data

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 2 of 3

3.3.7: Where from here?

Credits

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

Credits for photos in this lesson


current state of state of power
temperature charge (SOC) health (SOH) cells limits


loop once each measurement interval while pack is active

“Map” on slide 2: Pixabay license


(https://pixabay.com/en/service/license/), from
https://pixabay.com/en/map-treasure-map-treasure-pirates-162047/

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Coming to understand the linear Kalman filter j 3 of 3
3.4.1: Introducing nonlinear variations to Kalman filters

Models for nonlinear Kalman filters

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 KF assumes a cell model of the form


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

xk D Ak 1 xk 1 C Bk 1 uk 1 C wk 1
yk D Ck x k C Dk uk C vk

 But, cell models are nonlinear, so the standard KF recursion doesn’t apply directly
 We now generalize to the nonlinear case, with system dynamics described as
xk D f .xk 1 ; uk 1 ; wk 1 /
yk D h.xk ; uk ; vk /

 Functions f ./ and h./ may be time-varying, but we generally omit the time
dependency from the notation for ease of understanding

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 1 of 5

3.4.1: Introducing nonlinear variations to Kalman filters

Kinds of nonlinear Kalman filters

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Three basic KF generalizations for nonlinear systems


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 Extended Kalman filter (EKF): Analytic linearization of model


at each point in time: problematic, but still popular
 Sigma-point (Unscented) Kalman filter (SPKF/UKF): Statistical/empirical
linearization of model at each point in time: can be much better than EKF at
same computational complexity
 Particle filters: Most precise, but often thousands of times more computations
required than either EKF/SPKF
 This week, we study EKF; next week SPKF
 Particle filters are beyond the scope of this course

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 2 of 5

3.4.1: Introducing nonlinear variations to Kalman filters

Prediction steps of nonlinear Kalman filters

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 EKF and SPKF both follow same set of general steps as KF


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 Recall general step 1


Step 1a: State prediction time update
Prediction

Step 1b: Error covariance time update

Step 1c: Predict system output

Step 2a: Estimator gain matrix


 EKF and SPKF simply have different expressions from KF for evaluating the
Correction

expectation
Stepoperations (because
2b: State estimate of different system
measurement update model)

Dr. Gregory L. Plett j


Step 2c: Error covariance measurement
University of Colorado Colorado Springs
update
Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 3 of 5
Step 1a: State prediction time update
3.4.1: Introducing nonlinear variations to Kalman filters

Prediction
Step 1b: Error covariance time update
Update steps of nonlinear Kalman filters

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 EKF andStep
current state of state of power

SPKF
1c: both follow same set of general steps as KF temperature charge (SOC) health (SOH) cells limits
Predict system output loop once each measurement interval while pack is active

 Recall general step 2


Step 2a: Estimator gain matrix

Correction
Step 2b: State estimate measurement update

Step 2c: Error covariance measurement update

 Again, EKF and SPKF simply have different expressions from KF for evaluating the
expectation operations implied in Step 2a (because of different system model)

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 4 of 5

3.4.1: Introducing nonlinear variations to Kalman filters

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Battery cells are nonlinear systems, therefore need nonlinear


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

models and nonlinear Kalman filters


 We will study two different approaches to generalizing KF equations for nonlinear
systems, one leading to EKF and the other to SPKF/UKF1
 EKF and SPKF (and variants) still obey predict/correct sequence of six steps
 So, derivation will involve evaluating those six steps under different sets of
assumptions

1
cf. http://www.ieeeghn.org/wiki/index.php/First-Hand:The_Unscented_Transform
re. name “unscented”
Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 5 of 5
3.4.2: Deriving the three extended-Kalman-filter prediction steps

The extended Kalman filter (EKF)

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 EKF makes two simplifying assumptions when adapting


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

general sequential inference equations to a nonlinear system:


 When computing estimates of the output of a nonlinear function, EKF assumes
EŒfn.x/  fn.EŒx/, which is not true in general
 When computing covariance estimates, EKF uses Taylor-series expansion to
linearize the system equations around the present operating point
 In this lesson, you will learn how to apply these approximations and assumptions to
derive the EKF prediction steps
 In the next lesson, you will learn how to derive the EKF update steps

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 1 of 6

3.4.2: Deriving the three extended-Kalman-filter prediction steps

EKF step 1a: State prediction time update

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 The state prediction step is approximated as


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

O D EŒf .x ; u ; w
xk k 1 k 1 k 1/ jY k 1

 f .xO C ; u ; wN
k 1 k 1 k 1/ ,
where wN k 1 D EŒwk 1 k 1 N D 0.)
. (Often, w
 That is, we approximate the expected value of the new state by assuming that it is
reasonable to simply propagate xO kC 1 and wN k 1 through the state equation.

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 2 of 6

3.4.2: Deriving the three extended-Kalman-filter prediction steps

EKF step 1b: Error covariance time update (1)

key off: store data


key on: initialize

 We start with an expression for xQ k :


meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

Q Dx O D f .x OC N
loop once each measurement interval while pack is active

xk k xk k 1; uk 1; wk 1/ f .xk 1
; uk 1; wk 1/

 Approx. first term via Taylor series around prior operating point fxO kC 1 ; uk 1; wkN 1 g
xk  f .xO C k 1
; uk 1; N
wk 1/ C df .x k 1;

dxk
uk 1; wk 1/

C
.xk 1 OC
xk 1
/
1 xk 1 DxO k 1
„ ƒ‚
Defined as AOk 1

C df .x k 1;

dwk
uk 1; wk 1/
.wk 1 N
wk 1/

„
1
ƒ‚
wk 1 DwN k 1

Defined as BO k 1
 
 This gives xQ k  AO k 1 xk Q C C BO
1 k 1w
ek 1

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 3 of 6
3.4.2: Deriving the three extended-Kalman-filter prediction steps

EKF step 1b: Error covariance time update (2)

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Substituting this to find the prediction-error covariance:


current state of state of power
temperature charge (SOC) health (SOH) cells limits

Q k /.xQ k /T   AOk 1†CxQ ;k 1AOTk 1 C BOk 1†ew BOkT


†xQ ;k D EŒ.x
loop once each measurement interval while pack is active

1
 Note, by the chain rule of total differentials,

df .xk 1; uk 1; wk 1/ D @f .x k 1;

@xk
uk 1; wk 1/
dxk 1 C @f .x k 1;

@uk
uk 1; wk 1/
duk 1
1 1

C @f .x k 1; uk
@wk
1; wk 1/
dwk 1
1 0
df .xk 1; uk 1; wk 1/ @f .xk 1; uk 1; wk 1/ @f .xk 1; uk 1; wk 1/ duk
dxk
D @xk
C @uk dxk
1

1 1 1 1
@f .xk 1; uk 1; wk 1/ dwk @f .xk 1; uk 1; wk 1/
+
@wk dxk
1
D @xk
1 1 1
0

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 4 of 6

3.4.2: Deriving the three extended-Kalman-filter prediction steps

EKF step 1c: Output estimate

key off: store data


key on: initialize
 Similarly, df .xk d1w;uk 1 ;wk 1 / D @f .xk 1@w
meas. voltage estimate estimate balance compute
current state of state of power
;uk 1 ;wk 1 / temperature charge (SOC) health (SOH) cells limits

k 1 k 1 loop once each measurement interval while pack is active

 Distinction between total and partial differential not yet critical


 Will be in fourth course in specialization

 System output is estimated to be


O D EŒh.x ; u ; v / j Y
yk k k k k 1

 h.xO ; u ; vN /,
k k k

where vN k D EŒv k

 That is, it is assumed that propagating xO k and the mean sensor noise is the best
approximation to estimating the output

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 5 of 6

3.4.2: Deriving the three extended-Kalman-filter prediction steps

Summary

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 EKF makes two fundamental assumptions to generalize KF


current state of state of power
temperature charge (SOC) health (SOH) cells limits

1. Assume EŒfn.x/  fn.EŒx/, which is not true in general


loop once each measurement interval while pack is active

2. Assume Taylor-series expansion to linearize system equations for covariances


 Applying these to generic-probabilistic-inference solution yields first three EKF
steps (final three in next lesson)
 In general must be careful to distinguish between total and partial differentials
(although not critical here)
 First half of EKF is now derived

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 6 of 6
3.4.3: Deriving the three extended-Kalman-filter correction steps

EKF step 2a: Estimator gain matrix (1)

key off: store data


key on: initialize
 Recall that the KF gain vector is Lk D †xQ y;k
meas. voltage estimate estimate compute
1
balance
current state of state of power

Q †y;k
Q
temperature charge (SOC) health (SOH) cells limits

 Output prediction error may be approximated


loop once each measurement interval while pack is active

Q D yk
yk O D h.xk ; uk ; vk /
yk O
h.xk ; uk ; vk / N
using Taylor-series expansion on first term

yk  h.xO k ; uk ; vNk / C dh.xkd;xuk ; vk / .xk O C dh.xkd;vuk ; vk /


xk / .vk N
vk /
k xk DxO k k vk DNvk
„ ƒ‚ „ ƒ‚
Defined as CO k Ok
Defined as D

 Note, much like we saw in Step 1b,


dh.xk ; uk ; vk / dh.xk ; uk ; vk /
dxk
D @h.xk@x; uk ; vk / and
dvk
D @h.xk@v; uk ; vk /
k k

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 1 of 4

3.4.3: Deriving the three extended-Kalman-filter correction steps

EKF step 2a: Estimator gain matrix (2)

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 From these results, we can compute


current state of state of power
temperature charge (SOC) health (SOH) cells limits

Q  CO k †xQ ;k CO k C DO k †vQ DO k ;
loop once each measurement interval while pack is active

T T
†y;k

Q  EŒ.xQ k /.CO k xQ k C DO k vQ k / 
T
†xQ y;k

D †xQ ;k COkT
 These terms may be combined to get the Kalman gain
D †xQ ;k COkT COk †xQ ;k COkT C DO k †vQ DO kT
  1
Lk

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 2 of 4

3.4.3: Deriving the three extended-Kalman-filter correction steps

EKF step 2b/c: State/covariance meas. update

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

EKF step 2b: State estimate measurement update


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Computes posterior state estimate by updating prediction loop once each measurement interval while pack is active

using estimator gain and innovation yk yOk


O C D xO k C Lk .yk
xk O
yk /

EKF step 2c: Error covariance measurement update


 Finally, the updated covariance is computed as
C
†xQ ;k D †xQ ;k
T
Q Lk
Lk †y;k

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 3 of 4
3.4.3: Deriving the three extended-Kalman-filter correction steps

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 EKF makes two fundamental assumptions to generalize KF


current state of state of power
temperature charge (SOC) health (SOH) cells limits

1. Assume EŒfn.x/  fn.EŒx/, which is not true in general


loop once each measurement interval while pack is active

2. Assume Taylor-series expansion to linearize system equations for covariances


 Applying these to generic-probabilistic-inference solution yields final three EKF
steps
 EKF algorithm is now derived!

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 4 of 4
3.4.4: Introducing a simple EKF example, with Octave code

An EKF example

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 We will look at two examples of implementing EKF


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

1. A simple example, with fairly straightforward math


2. The battery-cell example
 In this lesson, we implement EKF for model having following dynamics:
p
xk C1 D f .xk ; uk ; wk / D 5 C xk C wk
yk D h.xk ; uk ; vk / D xk C vk
3

with †e
w D 1 and †vQ D 2

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 1 of 9

3.4.4: Introducing a simple EKF example, with Octave code

Computing the derivatives

key off: store data


 To implement EKF, we must determine AOk , BO k , CO k , and DO k

key on: initialize


meas. voltage estimate estimate balance compute
current state of state of power
cells

p5 C x C w 
temperature charge (SOC) health (SOH) limits

loop once each measurement interval while pack is active

AOk D D D
@f .xk ; uk ; wk / @ k k 1
q
xk DxO kC 2 5CxO kC
@xk @xk
xk DxO kC
p5 C x C w 
BOk D @f .xk ; uk ; wk /
D @ k k
D1
@w k @w wk DwN k k
wk DwN k

O D @h.xk ; uk ; vk /
Ck D @ xk3 vk C 
D 3.xO k /2
@x k xk DxO k @xk
xk DxO k

Dk O D @h.xk ; uk ; vk / D @ xk3 C
vk

D1
@v k vk DNvk @vk
vk DNvk

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 2 of 9

3.4.4: Introducing a simple EKF example, with Octave code

EKF initialization code

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Code to implement EKF starts below


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Define simulation constants; reserve storage


loop once each measurement interval while pack is active

% Initialize simulation variables


SigmaW = 1; % Process noise covariance
SigmaV = 2; % Sensor noise covariance
maxIter = 40;

xtrue = 2 + randn (1) ; % Initialize true system initial state


xhat = 2; % Initialize Kalman filter initial estimate
SigmaX = 1; % Initialize Kalman filter covariance
u = 0; % Unknown initial driving input : assume zero

% Reserve storage for variables we might want to plot / evaluate


xstore = zeros ( maxIter +1 , length ( xtrue ) ) ; xstore (1 ,:) = xtrue ;
xhatstore = zeros ( maxIter , length ( xhat ) ) ;
SigmaXstore = zeros ( maxIter , length ( xhat ) ^2) ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 3 of 9
3.4.4: Introducing a simple EKF example, with Octave code

EKF steps 1a through 1b

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Main EKF loop starts below


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Also co-simulating system dynamics for sensor inputs


loop once each measurement interval while pack is active

for k = 1: maxIter ,
% EKF Step 1 a : State estimate time update
% ( First compute Ahat , Bhat : Specifics depend on model !)
% Note : For this example , x ( k +1) = sqrt (5+ x ( k ) ) + w ( k )
% Note : You need to insert your system ' s f (...) equation here
Ahat = 0.5/ sqrt (5+ xhat ) ; Bhat = 1;
xhat = sqrt (5+ xhat ) ;

% EKF Step 1 b : Error covariance time update


SigmaX = Ahat * SigmaX * Ahat ' + Bhat * SigmaW * Bhat ';

% [ Co - simulate system , with input signal u , and output signal y ]


w = chol ( SigmaW ) '* randn (1) ;
v = chol ( SigmaV ) '* randn (1) ;
ytrue = xtrue ^3 + v ; % y is based on present x and u
xtrue = sqrt (5+ xtrue ) + w ; % future x is based on present u

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 4 of 9

3.4.4: Introducing a simple EKF example, with Octave code

EKF steps 1c through 2b

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Main EKF loop continues below


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Notice the “extra” robustness code at end


loop once each measurement interval while pack is active

% EKF Step 1 c : Estimate system output


% ( First compute Ahat , Bhat : Specifics depend on model !)
% Note : For this example , y ( k ) = x ( k ) ^3
% Note : You need to insert your system ' s h (...) equation here
Chat = 3* xhat ^2; Dhat = 1;
yhat = xhat ^3;

% EKF Step 2 a : Compute Kalman gain matrix


SigmaY = Chat * SigmaX * Chat ' + Dhat * SigmaV * Dhat ';
L = SigmaX * Chat '/ SigmaY ;

% EKF Step 2 b : State estimate measurement update


xhat = xhat + L *( ytrue - yhat ) ;
xhat = max ( -5 , xhat ) ; % don ' t get square root of negative xhat !

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 5 of 9

3.4.4: Introducing a simple EKF example, with Octave code

EKF step 2c

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Main EKF loop concludes below


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Includes code to force SigmaX to be PSD


loop once each measurement interval while pack is active

% EKF Step 2 c : Error covariance measurement update


SigmaX = SigmaX - L * SigmaY *L ';
[~ ,S , V ] = svd ( SigmaX ) ;
HH = V * S *V ';
SigmaX = ( SigmaX + SigmaX ' + HH + HH ') /4; % Help to keep robust

% [ Store information for evaluation / plotting purposes ]


xstore ( k +1 ,:) = xtrue ; xhatstore (k ,:) = xhat ;
SigmaXstore (k ,:) = ( SigmaX (:) ) ';
end ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 6 of 9
3.4.4: Introducing a simple EKF example, with Octave code

EKF plotting code

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 This is an example showing how to plot the results from this


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

EKF code in two different ways


subplot (1 ,2 ,1) ;
t = 0: maxIter -1;
plot (t , xstore (1: maxIter ) , 'k - ' ,t , xhatstore , 'b - - ' , ...
t , xhatstore +3* sqrt ( SigmaXstore ) , 'm -. ' ,...
t , xhatstore -3* sqrt ( SigmaXstore ) , 'm -. ') ; grid ;
legend ( ' true ' , ' estimate ' , ' bounds ') ;
xlabel ( ' Iteration ') ; ylabel ( ' State ') ;
title ( ' Extended Kalman filter in action ') ;

subplot (1 ,2 ,2) ;
plot (t , xstore (1: maxIter ) - xhatstore , 'b - ' ,t , ...
3* sqrt ( SigmaXstore ) , 'm - - ' ,t , -3* sqrt ( SigmaXstore ) , 'm - - ') ;
grid ; legend ( ' Error ' , ' bounds ' ,0) ;
title ( ' EKF Error with bounds ') ;
xlabel ( ' Iteration ') ; ylabel ( ' Estimation error ') ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 7 of 9

3.4.4: Introducing a simple EKF example, with Octave code

Representative results

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Figures below show representative results


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 EKF works well for small states, when system is fairly linear
loop once each measurement interval while pack is active

 EKF struggles for larger states, when system is more nonlinear


Extended Kalman filter in action EKF error with bounds
7 0.5
Truth
6 EKF estimate
EKF bounds 0
5
Estimation error

4 −0.5
State

3
−1
2
−1.5
1 EKF error
EKF bounds
0 −2
0 10 20 30 40 0 10 20 30 40
Iteration Iteration

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 8 of 9

3.4.4: Introducing a simple EKF example, with Octave code

Summary

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Have now seen code to implement EKF on relatively simple


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

nonlinear state-space model


 Finding derivatives was most difficult part to do correctly (but, not too bad for this
simple model)
 Actual code was straightforward implementation of steps seen earlier this week
 Results show that EKF provides good estimates and bounds only for operating
regimes where the model is nearly linear (as expected)
 Estimates and bounds are poorer when the model is being operated far away from
a linear region

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 9 of 9
3.4.5: Preparing to implement EKF on an ECM

Derivatives for SOC state

key off: store data


key on: initialize
To implement EKF using ESC model, need AOk , BO k , CO k , D
Ok
meas. voltage estimate estimate balance compute


current state of state of power
temperature charge (SOC) health (SOH) cells limits

We first examine components of state equation to find AOk , BO k


loop once each measurement interval while pack is active


 Model true cell current as ik C wk , but measure ik only (wk is current-sensor error)
 Assume k D 1, leverage adaptivity of EKF overcome this inaccuracy
 Then, state-of-charge equation can be written
t
Q
.ik C wk / ´ k C1 D ´k
 The two derivatives that we need for this term are (with Q having units [A s]):
@´k C1 @´k C1 t
@´k C
D 1, and
@wk
D Q
´k DÓ k wk DwN

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 1 of 8

3.4.5: Preparing to implement EKF on an ECM

Derivatives for R–C states

key off: store data


key on: initialize
D exp.
meas. voltage estimate estimate balance compute

 If j
current state of state of power

t=.Rj Cj //, then resistor-currents state temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

equation can be written as


2 3 2 3
1 0    1 1
iR;k C1 D6
4 0 2 7
5 iR;k C6
4 1 2 7
5 .ik C wk /
:: ::: ::
: :
„ ƒ‚ „ ƒ‚
ARC BRC
 The two derivatives can be found to be
@iR;k C1 @iR;k C1
D ARC , and D BRC
@iR;k iR;k DiOR;k
C @wk wk DwN

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 2 of 8

3.4.5: Preparing to implement EKF on an ECM

Derivatives for dynamic hysteresis state (1)

key off: store data


key on: initialize

 
.ik Cwk / t
D exp
meas. voltage estimate estimate balance compute

 If AH;k
current state of state of power

, then hysteresis state temperature charge (SOC) health (SOH) cells limits

Q loop once each measurement interval while pack is active

hk C1 D AH;k hk C .AH;k 1/sgn .ik C wk /


 Taking partial with respect to the state and evaluating at the setpoint (noting that
wk D wN is a member of the setpoint),
.ik C wN k / t
 
@hk C1
@hk hkDhO C
D exp Q
D ANH;k
wk DwNk

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 3 of 8
3.4.5: Preparing to implement EKF on an ECM

Derivatives for dynamic hysteresis state (2)

key off: store data


key on: initialize
 Problem: @hk C1 =@wk does not exist at ik C wk D0
meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

 If we assume that ik C wk > 0,


loop once each measurement interval while pack is active

 
@hk C1 t t
@wk
D Q
exp
Q
j.ik C wk /j .1 C hk /
 If we assume that ik C wk < 0,
 
@hk C1 t t
@wk
D Q
exp
Q
j.ik C wk /j .1 hk /

 Overall, evaluating at Taylor-series linearization setpoint,


 
@hk C1 t N
D AH;k 1 C sgn.ik C w/
N hO C
@wk hk h D OC Q k
wk w
k
DN

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 4 of 8

3.4.5: Preparing to implement EKF on an ECM

Derivatives for instantaneous hysteresis state (2)

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 The zero-state hysteresis equation is defined as


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active


(
sgn.ik C wk /; jik C wk j > 0;
sk C1 D
sk ; else
 If we consider ik C wk D 0 to be a zero-probability event, then
@sk C1 @sk C1
@sk
D 0, and
@wk
D0

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 5 of 8

3.4.5: Preparing to implement EKF on an ECM

Derivatives for output equation

key off: store data


key on: initialize

 We now look at the components that determine CO k and DO k


meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

 The ESC-model output equation is


X
yk D OCV.´k / C M0sk C M hk Rj iRj ;k R0 ik C vk
j
no longer considering ik to have wk noise added to it (this would add correlation
between process noise and sensor noise).
 We have
@yk @yk @yk @yk
@sk
D M0 , @hk
D M, @iRj ;k
D Rj ,
@vk
D1

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 6 of 8
3.4.5: Preparing to implement EKF on an ECM

Derivative of OCV function

key off: store data


key on: initialize
meas. voltage estimate estimate compute

 Can use (evenly spaced) OCV data to approximate


balance
current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

@yk @OCV.´k /
@´k
D @´k
5
Empirical OCV derivative for six cells

´k DÓ k ´k DÓ k 4

∂ OCV/ ∂ SOC (V)


 The figure shows empirical OCV derivative 3

relationships for six different lithium-ion cells 2

 There is a little noise, which could be filtered (with a 1

zero-phase filter!) 0
0 10 20 30 40 50 60 70 80 90 100
 Filtering not really necessary State of charge (%)

% Find dOCV / dz at SOC = z from { SOC , OCV } data


function dOCVz = dOCVfromSOC ( SOC , OCV , z )
dZ = SOC (2) - SOC (1) ; % Find spacing of SOC vector
dUdZ = diff ( OCV ) / dZ ; % Scaled forward finite difference
dOCV = ([ dUdZ (1) dUdZ ] + [ dUdZ dUdZ ( end ) ]) /2; % Avg of fwd / bkwd diffs
dOCVz = interp1 ( SOC , dOCV , z ) ; % Could make more efficient than this ...

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 7 of 8

3.4.5: Preparing to implement EKF on an ECM

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 To implement EKF on ESC model, need noise assumptions


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Assumed process noise is additive to electrical current


loop once each measurement interval while pack is active

 Assumed sensor noise is additive to voltage measurement


 Then, must find all partial derivates for AOk , BO k , CO k , DO k
 This was a little complicated for the hysteresis state, since the update equation is
not differentiable at all points
 However, by a limiting argument, we found all matrices we need
 We are ready to implement EKF on ESC model!

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 8 of 8
3.4.6: Introducing Octave code to initialize and control EKF for SOC estimation

Implementing EKF on ESC model

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Refactor EKF code: represent real BMS implementation better


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Initialization routine (initEKF.m), called once at startup


loop once each measurement interval while pack is active

 Update routine (iterEKF.m), called every sample interval


 “Wrapper” code, coordinates the entire simulation process
 Wrapper code begins (load data, store in local variables):
% Load cell model , cell - test data ( incl . variable " DYNData " of which the field
% " script1 " is of interest ) . It has sub - fields time , current , voltage , soc .
load CellModel % loads " model " of cell
load ( ' Cell_DYN_P25 ') ; % loads data from cell test
T = 25; % Test temperature

time = DYNData . script1 . time (:) ; deltat = time (2) - time (1) ;
time = time - time (1) ; % start time at 0
current = DYNData . script1 . current (:) ; % discharge > 0; charge < 0.
voltage = DYNData . script1 . voltage (:) ;
soc = DYNData . script1 . soc (:) ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 1 of 6

3.4.6: Introducing Octave code to initialize and control EKF for SOC estimation

Wrapper code (2)

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Wrapper code continues by reserving storage, initializing


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

covariances, calling EKF initialization routine


% Reserve storage for computed results , for plotting
sochat = zeros ( size ( soc ) ) ;
socbound = zeros ( size ( soc ) ) ;

% Covariance values
SigmaX0 = diag ([1 e -3 1e -3 1e -2]) ; % uncertainty of initial state
SigmaV = 2e -1; % uncertainty of voltage sensor , output equation
SigmaW = 1 e1 ; % uncertainty of current sensor , state equation

% Create ekfData structure and initialize variables using first


% voltage measurement and first temperature measurement
ekfData = initEKF ( voltage (1) ,T , SigmaX0 , SigmaV , SigmaW , model ) ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 2 of 6

3.4.6: Introducing Octave code to initialize and control EKF for SOC estimation

Wrapper code (3)

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Wrapper code continues by entering main simulation loop


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 “Measure” sensor readings; update EKF


loop once each measurement interval while pack is active

% Now , enter loop for remainder of time , where we update the EKF
% once per sample interval
hwait = waitbar (0 , ' Computing ... ') ;
for k = 1: length ( voltage ) ,
vk = voltage ( k ) ; % " measure " voltage
ik = current ( k ) ; % " measure " current
Tk = T ; % " measure " temperature

% Update SOC ( and other model states )


[ sochat ( k ) , socbound ( k ) , ekfData ] = iterEKF ( vk , ik , Tk , deltat , ekfData ) ;
% update waitbar periodically , but not too often ( slow procedure )
if mod (k ,1000) ==0 , waitbar ( k / length ( current ) , hwait ) ; end ;
end
close ( hwait ) ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 3 of 6
3.4.6: Introducing Octave code to initialize and control EKF for SOC estimation

Wrapper code (4)

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Wrapper code continues with plotting/analysis code


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

figure ; plot ( time /60 ,100* sochat , time /60 ,100* soc ) ; hold on
plot ([ time /60; NaN ; time /60] ,...
[100*( sochat + socbound ) ; NaN ; 100*( sochat - socbound ) ]) ;
title ( ' SOC estimation using EKF ') ; xlabel ( ' Time ( min ) ') ; ylabel ( ' SOC (%) ') ;
legend ( ' Estimate ' , ' Truth ' , ' Bounds ') ; grid on

fprintf ( ' RMS SOC estimation error = % g %%\ n ' , sqrt ( mean ((100*( soc - sochat ) ) .^2) ) ) ;

figure ; plot ( time /60 ,100*( soc - sochat ) ) ; hold on


plot ([ time /60; NaN ; time /60] ,[100* socbound ; NaN ; -100* socbound ]) ;
title ( ' SOC estimation errors using EKF ') ;
xlabel ( ' Time ( min ) ') ; ylabel ( ' SOC error (%) ') ; ylim ([ -4 4]) ;
legend ( ' Estimation error ' , ' Bounds ') ; grid on

ind = find ( abs ( soc - sochat ) > socbound ) ;


fprintf ( ' Percent of time error outside bounds = % g %%\ n ' ,...
length ( ind ) / length ( soc ) *100) ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 4 of 6

3.4.6: Introducing Octave code to initialize and control EKF for SOC estimation

EKF initialization code

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 The EKF initialization code is:


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

function ekfData = initEKF ( v0 , T0 , SigmaX0 , SigmaV , SigmaW , model )


% Initial state description
ir0 = 0; ekfData . irInd = 1;
hk0 = 0; ekfData . hkInd = 2;
SOC0 = SOCfromOCVtem p ( v0 , T0 , model ) ; ekfData . zkInd = 3;
ekfData . xhat = [ ir0 hk0 SOC0 ] '; % initial state

% Covariance values
ekfData . SigmaX = SigmaX0 ; ekfData . SigmaV = SigmaV ;
ekfData . SigmaW = SigmaW ; ekfData . Qbump = 5;

% previous value of current ( and its sign )


ekfData . priorI = 0; ekfData . signIk = 0;

% store model data structure too


ekfData . model = model ;
end

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 5 of 6

3.4.6: Introducing Octave code to initialize and control EKF for SOC estimation

Summary

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 Implementation of EKF on ESC model refactors code


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Initialization routine (initEKF.m), called once at startup


loop once each measurement interval while pack is active

 Update routine (iterEKF.m), called every sample interval


 “Wrapper” code, coordinates the entire simulation process
 You have now seen the details of the initialization routine and the wrapper code
 Next lesson will present the update routine

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 6 of 6
3.4.7: Introducing Octave code to update EKF for SOC estimation

EKF iteration code, load model

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Implementation of EKF on ESC model refactors code


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 “Wrapper” code, coordinates the entire simulation process


loop once each measurement interval while pack is active

 Initialization routine (initEKF.m), called once at startup


 Update routine (iterEKF.m), called every sample interval, which starts with:
function [ zk , zkbnd , ekfData ] = iterEKF ( vk , ik , Tk , deltat , ekfData )
model = ekfData . model ;
% Load the cell model parameters
Q = getParamESC ( ' QParam ' ,Tk , model ) ;
G = getParamESC ( ' GParam ' ,Tk , model ) ;
M = getParamESC ( ' MParam ' ,Tk , model ) ;
M0 = getParamESC ( ' M0Param ' ,Tk , model ) ;
RC = exp ( - deltat ./ abs ( getParamESC ( ' RCParam ' ,Tk , model ) ) ) ';
R = getParamESC ( ' RParam ' ,Tk , model ) ';
R0 = getParamESC ( ' R0Param ' ,Tk , model ) ;
eta = getParamESC ( ' etaParam ' ,Tk , model ) ;
if ik <0 , ik = ik * eta ; end ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 1 of 8

3.4.7: Introducing Octave code to update EKF for SOC estimation

EKF iteration code, load covariances/states

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 EKF iteration code continues


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Load covariances, states from prior iteration


loop once each measurement interval while pack is active

% Get data stored in ekfData structure


I = ekfData . priorI ;
SigmaX = ekfData . SigmaX ;
SigmaV = ekfData . SigmaV ;
SigmaW = ekfData . SigmaW ;
xhat = ekfData . xhat ;
irInd = ekfData . irInd ;
hkInd = ekfData . hkInd ;
zkInd = ekfData . zkInd ;
if abs ( ik ) >Q /100 , ekfData . signIk = sign ( ik ) ; end ;
signIk = ekfData . signIk ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 2 of 8

3.4.7: Introducing Octave code to update EKF for SOC estimation

EKF iteration code, steps 1a–1b

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 EKF iteration code continues


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Compute b bk 1, and implement steps 1a and 1b loop once each measurement interval while pack is active

Ak 1 , B
% Step 1 a : Compute Ahat [k -1] , Bhat [k -1]; Then , state estimate time update
nx = length ( xhat ) ; Ahat = zeros ( nx , nx ) ; Bhat = zeros ( nx ,1) ;
Ahat ( zkInd , zkInd ) = 1; Bhat ( zkInd ) = - deltat /(3600* Q ) ;
Ahat ( irInd , irInd ) = diag ( RC ) ; Bhat ( irInd ) = 1 - RC (:) ;
Ah = exp ( - abs ( I * G * deltat /(3600* Q ) ) ) ; % hysteresis factor
Ahat ( hkInd , hkInd ) = Ah ;
B = [ Bhat , 0* Bhat ];
Bhat ( hkInd ) = - abs ( G * deltat /(3600* Q ) ) * Ah *(1+ sign ( I ) * xhat ( hkInd ) ) ;
B ( hkInd ,2) = Ah -1;

xhat = Ahat * xhat + B *[ I ; sign ( I ) ];

% Step 1 b : Error covariance time update


% sigmaminus ( k ) = Ahat (k -1) * sigmaplus (k -1) * Ahat (k -1) ' + ...
% Bhat (k -1) * sigmawtilde * Bhat (k -1) '
SigmaX = Ahat * SigmaX * Ahat ' + Bhat * SigmaW * Bhat ';

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 3 of 8
3.4.7: Introducing Octave code to update EKF for SOC estimation

EKF iteration code, steps 1c–2a

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 EKF iteration code continues


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Output estimate; estimator gain matrix


loop once each measurement interval while pack is active

% Step 1 c : Output estimate


yhat = OCVfromSOCtemp ( xhat ( zkInd ) ,Tk , model ) + M0 * signIk + ...
M * xhat ( hkInd ) - R * xhat ( irInd ) - R0 * ik ;

% Step 2 a : Estimator gain matrix


Chat = zeros (1 , nx ) ;
Chat ( zkInd ) = dOCVfromS OC temp ( xhat ( zkInd ) ,Tk , model ) ;
Chat ( hkInd ) = M ;
Chat ( irInd ) = -R ;
Dhat = 1;
SigmaY = Chat * SigmaX * Chat ' + Dhat * SigmaV * Dhat ';
L = SigmaX * Chat '/ SigmaY ;

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 4 of 8

3.4.7: Introducing Octave code to update EKF for SOC estimation

EKF iteration code, steps 2b–2c

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 EKF iteration code continues


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 State and covariance measurement updates


loop once each measurement interval while pack is active

% Step 2 b : State estimate measurement update


r = vk - yhat ; % residual . Use to check for sensor errors ...
if r ^2 > 100* SigmaY , L (:) =0.0; end
xhat = xhat + L * r ;
xhat ( hkInd ) = min (1 , max ( -1 , xhat ( hkInd ) ) ) ; % Help maintain robustness
xhat ( zkInd ) = min (1.05 , max ( -0.05 , xhat ( zkInd ) ) ) ;

% Step 2 c : Error covariance measurement update


SigmaX = SigmaX - L * SigmaY *L ';
if r ^2 > 4* SigmaY , % bad voltage estimate by 2 std . devs , bump SigmaX
fprintf ( ' Bumping SigmaX \ n ') ;
SigmaX ( zkInd , zkInd ) = SigmaX ( zkInd , zkInd ) * ekfData . Qbump ;
end
[~ ,S , V ] = svd ( SigmaX ) ;
HH = V * S *V ';
SigmaX = ( SigmaX + SigmaX ' + HH + HH ') /4; % Help maintain robustness

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 5 of 8

3.4.7: Introducing Octave code to update EKF for SOC estimation

EKF iteration code, cleanup

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

 EKF iteration code continues


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Store results for next time through loop


loop once each measurement interval while pack is active

% Save data in ekfData structure for next time ...


ekfData . priorI = ik ;
ekfData . SigmaX = SigmaX ;
ekfData . xhat = xhat ;
zk = xhat ( zkInd ) ;
zkbnd = 3* sqrt ( SigmaX ( zkInd , zkInd ) ) ;
end

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 6 of 8
3.4.7: Introducing Octave code to update EKF for SOC estimation

Example EKF on ESC results

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 In following example, EKF was executed for a test having


current state of state of power
temperature charge (SOC) health (SOH) cells limits

loop once each measurement interval while pack is active

dynamic profiles from 100 % SOC down to around 10 % SOC


 RMS SOC estimation error = 0:46 %
 Percent of time error outside bounds = 0 %
SOC estimation using EKF SOC estimation errors using EKF
120 4
Estimate Estimation error
100 Truth Bounds
Bounds 2

SOC error (%)


80
SOC (%)

60 0

40
−2
20

0 −4
0 100 200 300 400 500 600 0 100 200 300 400 500 600
Time (min) Time (min)

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 7 of 8

3.4.7: Introducing Octave code to update EKF for SOC estimation

Summary

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 Implementation of EKF on ESC model refactors code


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Initialization routine (initEKF.m), called once at startup


loop once each measurement interval while pack is active

 Update routine (iterEKF.m), called every sample interval


 “Wrapper” code, coordinates the entire simulation process
 You have now seen the details of the entire codeset plus some example results
 EKF works quite well as SOC estimator using ESC model

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 8 of 8
3.4.8: Where from here?

Summary of this week

key off: store data


key on: initialize
meas. voltage estimate estimate balance compute

 This week, you learned:


current state of state of power
temperature charge (SOC) health (SOH) cells limits

 How to generalize linear state-state model to describe


loop once each measurement interval while pack is active

nonlinear systems
 How to apply two assumptions to derive the extended Kalman filter from the
generic Gaussian sequential-probabilistic-inference solution
 How to write Octave/MATLAB code to implement EKF for a simple example and
for the battery-cell state-estimation problem
 See some examples of applying EKF to estimate cell SOC using lab-test data

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 1 of 3

3.4.8: Where from here?

Where from here?

key off: store data


key on: initialize
 Next week, you will learn
meas. voltage estimate estimate balance compute
current state of state of power
temperature charge (SOC) health (SOH) cells limits

 Sigma-point approach to approximating statistics of a RV loop once each measurement interval while pack is active

passed through a nonlinear function


 How to apply sigma-point approach to general Gaussian
sequential-probabilistic-inference solution to derive the
sigma-point Kalman filter
 How to write Octave code to implement SPKF for a simple
example and for battery-cell state-estimation problem
 See some examples of applying SPKF to estimate cell
SOC using lab-test data

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 2 of 3

3.4.8: Where from here?

Credits

key off: store data


key on: initialize

meas. voltage estimate estimate balance compute

Credits for photos in this lesson


current state of state of power
temperature charge (SOC) health (SOH) cells limits


loop once each measurement interval while pack is active

“Map” on slide 2: Pixabay license


(https://pixabay.com/en/service/license/), cropped from
https://pixabay.com/en/compass-navigation-map-direction-390054/

Dr. Gregory L. Plett j University of Colorado Colorado Springs Battery State-of-Charge (SOC) Estimation | Cell SOC estimation using an extended Kalman filter j 3 of 3

You might also like