N2 Soc
N2 Soc
N2 Soc
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–2
State-of-charge (SOC) estimation
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–3
KEY POINT : We are aided by some definitions that can calibrate our tests.
DEFINITION: A cell is fully charged when its open circuit voltage (OCV)
reaches vh.T /, a manufacturer specified voltage that may be a
function of temperature T .
■ e.g., vh.25 ıC/ D 4:2 V for LMO; vh .25 ıC/ D 3:6 V for LFP.
■ A common method to bring a cell to a fully charged state is to
execute a constant-current charge profile until the terminal voltage
is equal to vh.T /, followed by a constant-voltage profile until the
charging current becomes infinitesimal.
■ We define the SOC of a fully charged cell to be 100 %.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–5
■ While the SI unit for charge is coulombs (C), it is more common in
practice 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.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–6
■ The nominal capacity is a constant value.
■ Since the nominal capacity is representative of a lot of cells and
the 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.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–7
3.2: Some approaches to estimate state of charge
■ The “Tino” method assumes a cell model v.t/ D OCV.´.t// " i.t/R0
and then looks up v.t/ C i.t/R0 on “SOC versus OCV” curve
! Better, but still misses diffusion voltages, hysteresis
True SOC and voltage-based estimate
■ Example shows that Tino 100
SOC estimate
True SOC
estimate is very noisy.
SOC and estimate (%)
80
■ Hysteresis is another 20
complicating factor. 0
0 100 200 300 400 500
Time (min)
■ Even though its estimates are noisy, we’ll find an application for the
Tino method in the next chapter of notes.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–8
System Model
Predicted Output
State Est.
yk D h.xk ; uk ; vk /,
where uk is a known (deterministic/measured) input signal, wk is a
process-noise random input, and vk is a sensor-noise random input.
■ We note that f .$/ and h.$/ may be time-varying, but we generally omit
the time dependency from the notation for ease of understanding.
SEQUENTIAL PROBABILISTIC INFERENCE: Estimate the present state xk
of a dynamic system using all measurements Yk D fy0; y1; $ $ $ ; yk g .
yk"2 yk"1 yk
Observed fY jX .yk j xk /
Unobserved
xk"2 xk"1 xk
fX jX .xk j xk"1 /
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–10
3.3: Review of probability
■ 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 “random variables” (RVs).
! Cannot predict exactly what we will get each time we measure or
sample the random variable, but
! We can characterize the probability of each sample value by the
“probability density function” (pdf).
■ For a brief review, define random vector X and sample vector x0 as
2 3 2 3
X1 x1
6 7 6 7
6 X2 7 6 x2 7
X D6 7
6 ::: 7 , x0 D 6 7
6 ::: 7 ,
4 5 4 5
Xn xn
where X1 through Xn are scalar random variables and x1 through xn
are scalar constants.
■ 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 /.
! That is, fX .x0 / dx1 dx2 $ $ $ dxn is the probability that X is between
x0 and x0 C dx.
■ Properties of joint pdf fX .x/:
1. Z
fX .x/ % 0 Z8 x.
1Z 1 1
2. $$$ fX .x/ dx1 dx2 $ $ $ dxn D 1.
"1 "1 "1 Z
Z Z 1
1 1
3. xN D EŒX" D $$$ xfX .x/ dx1 dx2 $ $ $ dxn.
"1 "1 "1
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–11
4. Correlation matrix:
†X D EŒXX T " (outer product)
Z 1Z 1 Z 1
D ::: xx T fX .x/ dx1 dx2 $ $ $ dxn.
"1 "1 "1
5. Covariance matrix: Define X N Then,
e D X " x.
†Xe D EŒ.X " x/.X
N N T"
" x/
Z 1Z 1 Z 1
D $$$ .x " x/.x
N N T fX .x/ dx1 dx2 $ $ $ dxn .
" x/
"1 "1 "1
†Xe is symmetric and positive-semi-definite (psd). This means
y T †Xe y % 0 8 y.
■ Notice that correlation D covariance for zero-mean random vectors.
■ The covariance entries have specific meaning:
.†Xe /i i D &X2 i
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–12
■ The Gaussian or normal pdf is defined as, where we say
X ' N .x;
N †Xe /
! "
1 1 T "1
fX .x/ D 1=2
exp " .x " N
x/ †Xe .x " x/
N :
.2(/ j†Xe j
n=2 2
j†Xe j D det.†Xe /; †"1
e requires positive-definite †X
X e.
MAIN POINT #2: If jointly normally distributed RVs are uncorrelated, then
they are independent. This is a (very) special case.
MAIN POINT #3: We can define a conditional pdf
fX;Y .x; y/
fXjY .xjy/ D
fY .y/
as the probability that X D x given that Y D y has happened.
D fY jX .yjx/fX .x/,
Therefore,
fY jX .yjx/fX .x/
fXjY .xjy/ D .
fY .y/
■ This is known as Bayes’ rule. It relates the posterior probability to the
prior probability.
■ It forms a key step in the Kalman filter derivation.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–15
3.4: Overview of vector random (stochastic) processes
■ A stochastic or random process is a family of random vectors indexed
by a parameter set (“time” in our case).
! For example, we might refer to a random process Xk for generic k.
! The value of the 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 Xk2 " D RX .k1 " k2 /.
T
Value
Value
0.05
0
0
−0.05
−2
−0.1
−4 −0.15
0 200 400 600 800 1000 0 200 400 600 800 1000
Time Time
4. Shaping filters: We will assume that the noise inputs to the dynamic
systems are white (Gaussian) processes.
■ Pretty limiting assumption, but one that can be easily fixed ➠ Can
use second linear system to “shape” the noise as desired.
Previous Picture New Picture
White yk Shaped yk
noise wk G.´/ G.´/
noise w1;k
White w1;k
H.´/ G.´/ yk
noise w2;k Shaped
■ Therefore, we can drive our linear system with noise that has a
desired characteristics by introducing a shaping filter H.´/ that
itself is driven by white noise.
■ The combined system GH.´/ looks exactly the same as before,
but the system G.´/ is not driven by pure white noise any more.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–17
■ Analysis augments original system model with filter states.
Original system has
xkC1 D Axk C Bw w1;k
yk D C xk .
■ Shaping filter with white input and desired output statistics has
xs;kC1 D As xs;k C Bs w2;k
w1;k D Cs xs;k .
■ Combine into one system:
2 3 2 32 3 2 3
xkC1 A Bw Cs xk 0
4 5D4 54 5C4 5 w2;k
xs;kC1 0 As xs;k Bs
2 3
h i xk
yk D C 0 4 5.
xs;k
■ Augmented system just a larger-order system driven by white
noise.
5. Gaussian processes: We will work with Gaussian noises to a large
extent, which are uniquely defined by the first- and second central
moments 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. The state of a system driven by a random process is a
random vector, so we could now call it Xk . However, it is more
common to retain the standard notation xk and understand from the
context that we are discussing an RV.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–18
3.5 Sequential-probabilistic-inference solution
■ In the notation that follows,
! The superscript “"” indicates a predicted quantity based only on
past measurements.
! The superscript “C” indicates an estimated quantity based on both
past and present measurements.
! The decoration “O” indicates a predicted or estimated quantity.
! The decoration “Q” indicates an error: the difference between a
true and predicted or estimated quantity.
! The symbol “†” is used to denote the correlation between the two
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 "
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–19
■ We solve for xO kC by differentiating the cost function and setting the
result to zero
d $ &
0 D C E xkT xk " 2xkT xO kC C .xO kC/xO kC j Yk .
dxO k
■ To do so, note the following identities from vector calculus,
d T d T d T
Y X D Y; X Y D Y; and X AX D .A C AT /X.
dX dX dX
■ Then,
$ C
& C
$ &
0 D E " 2.xk " xO k / j Yk D 2xO k " 2E xk j Yk
$ &
xO kC D E xk j Yk .
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–20
■ 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 .
■ So,
$ &
xO kC D xO k" CE xQ k" j yk ,
which is a predict/correct sequence of steps, as promised.
$ " &
Q k j yk ? We can show that, generically, when x and y
■ But, what is E x
D †" "1
Q †y;k yQk .
„ ƒ‚ Q …
xQ y;k
Lk
■ Putting all of the pieces together, we get the general update equation:
xO kC D xO k" C Lk yQk .
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–21
■ Note that Lk is a function of †C Q , which may be computed as
x;k
C
$ C C T
&
Q D E .xk " x
†x;k O k /.xk " xO k /
$˚ "
*˚ "
*T &
D E .xk " xO k / " Lk yQk .xk " xO k / " Lk yQk
$˚ *˚ *T &
D E xQ k" " Lk yQk xQ k" " Lk yQk
$ & $ " T& T
D †" Q
x;k " Lk E Q
y .
k kQ
x " T
/ " E xQ k yQk Lk C Lk †y;k T
Q Lk
„ ƒ‚ … „ ƒ‚ …
†y;k
Q Lk
T Lk †y;k
Q
D †" Q Lk .
Q " Lk †y;k
x;k
T
†C
Q
x;k D †! Q Lk ,
Q " Lk †y;k
x;k
T
where
$ & $ & $ &
xO k! D E xk j Yk!1 Q D E .xk " x
†!
x;k O k! /.xk " xO k! /T D E .xQ k! /.xQ k! /T
$ & $ & $ &
xO kC D E xk j Yk Q D E .xk " x
†C
x;k O kC /.xk " xO kC /T D E .xQ kC /.xQ kC /T
$ & $ & $ &
Ó k D E ´k j Yk!1 Q D E .yk " y
†y;k Ok /.yk " yOk /T D E .yQk /.yQk /T
$ &
Lk D E .xk " xO k! /.yk " yOk /T †!1 !
Q D †xQ y;k
y;k
!1
Q .
Q †y;k
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–22
3.6: The six-step process
D †" Q Lk .
Q " Lk †y;k
x;k
T
KEY POINT : The estimator output comprises the state estimate xO kC and
error covariance estimate †C
Q .
x;k
■ That is,rwe have high confidence that the truth lies within
# '
C C
xO k ˙ 3 diag †x;k
Q .
■ The estimator then waits until the next sample interval, updates k,
and proceeds to step 1a.
Prediction
Step 1b: Error
$
covariance&
time
$
update
†"Q D E .x
x;k Q k" /.xQ k"/T D E .xk " xO k" /.xk " xO k" /T ".
Step 1c: Estimate
$
system
& $
output &
yOk D E yk j Yk"1 D E h.xk ; uk ; vk / j Yk"1 .
Step 2a: Estimator gain matrix
Lk D †" "1
Q .
Q †y;k
xQ y;k
Correction
Step 2b: State estimate measurement update
xO kC D xO k" C Lk .yk " yOk /.
Step 2c: Covariance estimate measurement update
†C "
Q D †x;k
x;k Q Lk .
Q " Lk †y;k
T
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–24
Optimal application to linear systems: The Kalman filter
■ In the next section, we take the general solution and apply it to the
specific case where the system dynamics are linear.
■ Linear systems have the desirable property that all pdfs do in fact
remain Gaussian if the stochastic inputs are Gaussian, so the
assumptions made in deriving the filter steps hold exactly.
■ The linear Kalman filter assumes that the system being modeled can
be represented in the “state-space” form
yk D Ck xk C Dk uk C vk .
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–25
3.7: Deriving the linear Kalman filter
■ We now apply the general solution to the linear case, and derive the
linear Kalman filter.
■ An attempt to aid intuition is also given as we proceed.
D Ak"1†C
Q
x;k"1 A T
e.
k"1 C †w
■ The 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.
INTUITION: When estimating the error covariance of state prediction,
! The best we can do is to use the most recent covariance estimate
and propagate it forward in time.
C
! For stable systems, Ak"1 †x;k"1
Q ATk"1 is contractive, meaning that
the covariance gets “smaller.” The state of stable systems always
decays toward zero in the absence of input, or toward a known
trajectory if uk ¤ 0. As time goes on, this term tells us that we tend
to get more and more certain of the state estimate.
! On the other hand, †w
e adds to the covariance. Unmeasured inputs
D Ck xO k" C Dk uk ,
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–27
since vk is zero-mean.
INTUITION: yOk is our best guess of the system output, given only past
measurements.
! 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.
KF step 2a: Estimator (Kalman) gain matrix.
■ To compute the Kalman gain matrix, we first need to compute several
covariance matrices: Lk D †" "1
Q . We first find †y;k
Q †y;k
xQ y;k Q .
D Ck xQ k" C vk
$ &
†y;k
Q D E .Ck xQ k" C vk /.Ck xQ k" C vk /T
$ &
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 †"
Q Ck C †vQ .
x;k
T
■ Again, the cross terms are zero since vk is uncorrelated with xQ k" .
■ Similarly,
$ &
EŒxQ k" yQkT " DE xQ k" .Ck xQ k"
C vk / T
D †"
Q Ck .
x;k
T
■ Combining,
Lk D †" T "
Q Ck ŒCk †x;k
x;k
T "1
Q Ck C †vQ " .
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–28
! †"
Q tells us about state uncertainty at the present time, which we
x;k
hope to reduce as much as possible.
◆ A large entry in †"
Q means that the corresponding state is very
x;k
uncertain and therefore would benefit from a large update.
◆ A small entry in †"
Q means that the corresponding state is very
x;k
well known already and does not need as large an update.
! 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.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–29
! †yQ tells us how certain we are that the measurement is reliable.
◆ 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 can also be explained.
◆ The Ck †" xQ Ck part indicates how error in the state contributes to
T
†C "
Q D †x;k
x;k Q " Lk †y;k
Q Lk
T
# 'T
D †"
Q
x;k " Lk †y;k "T
Q †y;k
Q
"
†xQ y;k
Q
D †" "
Q " Lk Ck †x;k
x;k Q
D .I " Lk Ck /†"
Q .
x;k
KEY POINT : Repeating from before, recall that the estimator output
comprises the state estimate xO kC and error covariance estimate †C
Q .
x;k
■ That is,rwe have high confidence that the truth lies within
# '
C C
xO k ˙ 3 diag †x;k
Q .
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–31
3.8: Visualizing the Kalman filter
Initialization
xO 0C , †C
Q
x;0 next time sample: increment k
1a 2c
C
xO k" D Ak"1xO k"1 C Bk"1uk"1 †C "
Q D .I " Lk Ck /†x;k
x;k Q
1b 2b
C
†"
Q D Ak"1 †x;k"1
x;k Q ATk"1C†we Meas. xO kC D xO k" C Lk .yk " yOk /
Meas.
uk yk
1c 2a
yOk D Ck xO k" C Dk uk Lk D†" T " T
Q Ck C†vQ "
Q Ck ŒCk †x;k
x;k
"1
Prediction Correction
1
´kC1 D 1 $ ´k " ik 3
3600 $ Q
2.5
voltk D 3:5 C 0:7 # ´k " R0ik .
0 20 40 60 80 100
State of charge (%)
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–32
■ Notice that we have linearized the OCV relationship, and omitted the
diffusion and hysteresis voltages.
■ This model still isn’t linear because of the “3.5” in the output equation,
so we debias the measurement via yk D voltk " 3:5 and use the model
1
´kC1 D 1 $ ´k " ik
3600 $ Q
yk D 0:7 # ´k " R0ik .
■ Define state xk ( ´k and input uk ( ik .
■ For the sake of example, we will use Q D 10000=3600 and R0 D 0:01.
■ This yields a state-space description with A D 1, B D "1 # 10"4,
C D 0:7, and D D "0:01. We also model †we D 10"5, and †vQ D 0:1.
■ We assume no initial uncertainty so xO 0C D 0:5 and †C
Q D 0.
x;0
C
xO k" D Ak"1 xO k"1 C Bk"1 uk"1 xO 1" D 1 # 0:5 " 10"4 # 1 D 0:4999
C
†"
Q D Ak"1 †x;k"1
x;k Q ATk"1 C †w
e †"
Q D 1 # 0 # 1 C 10
x;1
"5
D 10"5
Lk D †" T " T
Q Ck C†vQ "
Q Ck ŒCk †x;k
x;k
"1
L1 D 10"5 # 0:7Œ0:72 # 10"5 C 0:1""1
D 6:99966#10"5
xO kC D xO k" C Lk .yk " yOk / xO 1C D 0:4999 C 6:99966#10"5.0:35 " 0:34493/
(where yk D 3:85 " 3:5) D 0:4999004
†C "
Q D .I " Lk Ck /†x;k
x;k Q †C
Q D .1 " 6:99966#10
x;1
"5
# 0:7/ # 10"5
D 9:9995#10"6
p
■ Output: q
O D 0:4999 ˙ 3 9:9995 # 10"6 D 0:4999 ˙ 0:0094866.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–33
Iteration 2: (let i1 D 0:5, i2 D 0:25, and v2 D 3:84)
C
xO k" D Ak"1 xO k"1 C Bk"1 uk"1 xO 1" D 0:4999004 " 10"4 # 0:5 D 0:49985
C
†"
Q D Ak"1 †x;k"1
x;k Q ATk"1 C †w
e †"
Q D 9:9995#10
x;2
"6
C 10"5 D 1:99995#10"5
Lk D †" T " T
Q Ck C†vQ "
Q Ck ŒCk †x;k
x;k
"1
L2 D 1:99995#10"5 # 0:7Œ1:99995#10"5 # 0:72 C 0:1""1
D 0:00013998
xO kC D xO k" C Lk .yk " yOk / xO 2C D 0:49985 C 0:00013998.0:34 " 0:347395/
(where yk D 3:84 " 3:5) D 0:499849
†C "
Q D .I " Lk Ck /†x;k
x;k Q †C
Q D .1 " 0:00013998 # 0:7/ # 1:99995#10
x;2
"5
D 1:99976#10"5
p
■ Output: q
O D 0:4998 ˙ 3 1:99976 # 10"5 D 0:4998 ˙ 0:013416.
■ Note that covariance (uncertainty) converges, but it can take time
†"
Q D 1#10
x;1
"5
†"
Q D 1:99995#10
x;2
"5
†"
Q D 2:99976#10
x;3
"5
†C
Q D0
x;0 †C
Q D 9:99951#10
x;1
"6
†C
Q D 1:99976#10
x;2
"5
†C
Q D 2:99931#10
x;3
"5
C
Kalman filter in action Error covariance †"
Q and †x;k
x;k Q
0.6 1.44
0.5
Covariance × 103
0.4
1.43
0.3 True
State
Estimate
0.2 Error
1.42
0.1
†"
xQ
0
†C
xQ
−0.1 1.41
300 400 500 600 700 800 900 1000 300 400 500 600 700 800 900 1000
Iteration Iteration
■ Note that Kalman filter does not perform especially well since †vQ is
quite large.
■ However, these are the best-possible results, since the KF is the
optimum MMSE estimator.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–35
3.9: Matlab code for the Kalman filter steps
[L,D] = ldl(covar); 0
x = randn([2,5000]); −1
y = ybar(:,ones([1 5000])) −4 −2 0 2 4 6
x coordinate
+(L*sqrt(D))*x;
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–36
SigmaV = 1; % Sensor noise covariance
A = 1; B = 1; C = 1; D = 0; % Plant definition matrices
maxIter = 40;
for k = 1:maxIter,
% KF Step 1a: State estimate time update
xhat = A*xhat + B*u; % use prior value of "u"
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–37
% [Store information for evaluation/plotting purposes]
xstore(:,k+1) = xtrue; xhatstore(:,k) = xhat;
SigmaXstore(:,k) = SigmaX(:);
end
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');
■ The plots below show a sample of the Kalman filter operating for an
example where
xk D xk"1 C uk C wk
yk D xk C vk
and †we D †vQ D 1.
Kalman filter in action Error with bounds
true
10 2
estimate
Estimation Error
bounds
1
5
State
0 Error
−1 bounds
−2
−5
0 10 20 30 40 0 10 20 30 40
Iteration Iteration
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–38
3.10: Practical considerations
1. Symmetric, and
2. Positive definite (all eigenvalues strictly positive).
■ It is possible for both conditions to be violated due to round-off errors
in a computer implementation.
■ We wish to find ways to limit or eliminate these problems.
†C "
Q D ŒI " Lk Ck " †x;k
x;k
T T
Q ŒI " Lk Ck " C Lk †vQ Lk
D †" "
Q " Lk Ck †x;k
x;k
"
Q " †x;k
T T
Q Ck Lk C Lk Ck †x;k
" T T T
Q Ck Lk C Lk †vQ Lk
( ) T
D †"
Q
x;k " L C †"
k k x;k
Q " †"
Q
x;k C T T
k Lk C Lk C † "
k x;k
Q C T
k C †vQ Lk
D †" "
Q " Lk Ck †x;k
x;k
"
Q " †x;k
T T
Q Ck Lk C Lk †y;k
Q L
T
# '
" " " T T " T "1 T
D †x;k
Q " Lk Ck †x;k
Q " †x;k
Q Ck Lk C †x;k
Q Ck †y;k
Q †y;k
Q L
D †" "
Q .
Q " Lk Ck †x;k
x;k
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–40
Measurement validation gating
■ Sometimes the systems for which we would like a state estimate have
sensors with intermittent faults.
■ We would like to detect faulty measurements and discard them (the
time update steps of the KF are still implemented, but the
measurement update steps are skipped).
■ The Kalman filter provides an elegant theoretical means to
accomplish this goal. Note:
"
! The measurement covariance matrix is †y;k Q Ck C †vQ ;
T
Q D Ck †x;k
yk D h.xk ; uk ; vk /,
where uk is a known (deterministic/measured) input signal, wk is a
process-noise random input, and vk is a sensor-noise random input.
■ We note that f .$/ and h.$/ may be time-varying, but we generally omit
the time dependency from the notation for ease of understanding.
■ There are three basic generalizations to KF to estimate the state of a
nonlinear system
! Extended Kalman filter (EKF): Analytic linearization of the model at
each point in time. Problematic, but still popular.
! Sigma-point (Unscented) Kalman filter (SPKF/UKF): Statistical/
empirical linearization of the model at each point in time. Much
better than EKF, at same computational complexity.
! Particle filters: The most precise, but often thousands of times
more computations required than either EKF/SPKF. Does not
assume Gaussian distributions but approximates distributions via
histograms and uses Monte-Carlo integration techniques to find
probabilities, expectations, and uncertainties.
■ In this section, we present the EKF and SPKF. Particle filters are
beyond the scope of this course.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–42
3.11: The extended Kalman filter (EKF)
■ The EKF makes two simplifying assumptions when adapting the
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.
■ Here, we will show how to apply these approximations and
assumptions to derive the EKF equations from the general six steps.
EKF step 1a: State prediction time update.
■ The state prediction step is approximated as
xO k" D EŒf .xk"1; uk"1; wk"1 / j Yk"1"
C
) f .xO k"1 ; uk"1; wN k"1 /,
where wN k"1 D EŒwk"1". (Often, wN k"1 D 0.)
■ That is, we approximate the expected value of the new state by
C
assuming that it is reasonable to simply propagate xO k"1 and wN k"1
through the state equation.
EKF step 1b: Error covariance time update.
■ The covariance prediction step is accomplished by first making an
approximation for xQ k" .
xQ k" D xk " xO k"
C
D f .xk"1; uk"1; wk"1 / " f .xO k"1 ; uk"1; wN k"1/.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–43
■ The first term is expanded as a Taylor series around the prior
C
operating “point” which is the set of values fxO k"1 ; uk"1; wN k"1 g
ˇ
C df .xk"1; uk"1; wk"1 / ˇˇ C
xk ) f .xO k"1; uk"1; wN k"1 / C ˇ .xk"1 " xO k"1 /
dxk"1 C
xk"1 DxO k"1
„ ƒ‚ …
Defined as AOk"1
ˇ
df .xk"1; uk"1; wk"1/ ˇˇ
C ˇ .wk"1 " wN k"1 /.
dwk"1 wk"1 DwN k"1
„ ƒ‚ …
Defined as BO k"1
# '
■ This gives xQ k" ) AOk"1xQ k"1 C BO k"1 w
C f
k"1 .
) AOk"1†C
Q
x;k"1 AOTk"1 C BO k"1 †we BO k"1
T
.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–44
@f .xk"1; uk"1; wk"1 / dwk"1
@wk"1 dxk"1
„ƒ‚…
0
) h.xO k"; uk ; vN k /,
where vN k D EŒvk ".
■ That is, it is assumed that propagating xO k" and the mean sensor noise
is the best approximation to estimating the output.
EKF step 2a: Estimator gain matrix.
■ The output prediction error may then be approximated
yQk D yk " yOk D h.xk ; uk ; vk / " h.xO k"; uk ; vN k /
using again a Taylor-series expansion on the first term.
ˇ
" dh.xk ; u k k ˇˇ
; v / "
yk ) h.xO k ; uk ; vN k / C ˇ .xk " O
x k /
dxk "
xk DxO k
„ ƒ‚ …
Defined as CO k
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–45
ˇ
dh.xk ; uk ; vk / ˇˇ
C ˇ .vk " vN k /.
dvk
„ ƒ‚ vk DvN…k
Defined as DO k
D †" OT
Q Ck .
x;k
†C
Q
x;k D †"
Q
x;k " Lk † Q
y;k Lk.
T
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–46
3.12: An EKF example, with code
yk D h.xk ; uk ; vk / D xk3 C vk
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–47
xhat = 2; % Initialize Kalman filter initial estimate
SigmaX = 1; % Initialize Kalman filter covariance
u = 0; % Unknown initial driving input: assume zero
for k = 1:maxIter,
% EKF Step 0: Compute Ahat, Bhat
% Note: For this example, x(k+1) = sqrt(5+x(k)) + w(k)
Ahat = 0.5/sqrt(5+xhat); Bhat = 1;
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–48
SigmaX = SigmaX - L*SigmaY*L';
[~,S,V] = svd(SigmaX);
HH = V*S*V';
SigmaX = (SigmaX + SigmaX' + HH + HH')/4; % Help to keep robust
figure(2); clf;
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');
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
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–49
3.13: Preparing to implement EKF on ESC model
■ To implement the EKF for battery-cell state estimation using the ESC
model, we must know the AOk , BO k , CO k and DO k matrices. We first
examine the components of the state equation to find AOk and BO k .
■ Suppose that the process noise models current-sensor measurement
error. That is, the true cell current is ik C wk , but we measure ik only.
■ Also assume we can simplify model with #k D 1, and have adaptivity
of EKF handle the small error introduced by this assumption.
■ Then, the state-of-charge equation can be written as
$t
´kC1 D ´k " .ik C wk / .
Q
■ The two derivatives that we need for this term are:
ˇ ˇ
@´kC1 ˇˇ @´kC1 ˇˇ $t
D 1, and D " ,
@´k ˇ´k DÓ C @wk ˇwk DwN Q
k
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–50
! ˇ ˇ"
ˇ .ik C wk / )$t ˇ
■ If we define AH;k D exp " ˇˇ ˇ , then hysteresis state
ˇ
Q
hkC1 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),
ˇ ! ˇ ˇ"
ˇ
@hkC1 ˇ ˇ .ik C wN k / )$t ˇˇ
ˇ OC
ˇ
D exp " ˇ ˇ D ANH;k .
@h hk Dh
k k Q
wk DwN
■ Next, we must find @hkC1 =@wk . However, the absolute-value and sign
functions are not differentiable at ik C wk D 0. Ignoring this detail,
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–52
3.14: Implementing EKF on ESC model
% Covariance values
SigmaX0 = diag([1e-3 1e-3 1e-2]); % uncertainty of initial state
SigmaV = 2e-1; % uncertainty of voltage sensor, output equation
SigmaW = 1e1; % uncertainty of current sensor, state equation
% 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
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–53
Tk = T; % "measure" temperature
ind = find(abs(soc-sochat)>socbound);
fprintf('Percent of time error outside bounds = %g%%\n',...
length(ind)/length(soc)*100);
% Covariance values
ekfData.SigmaX = SigmaX0;
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–54
ekfData.SigmaV = SigmaV;
ekfData.SigmaW = SigmaW;
ekfData.Qbump = 5;
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–55
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) = 1-Ah;
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–56
[~,S,V] = svd(SigmaX);
HH = V*S*V';
SigmaX = (SigmaX + SigmaX' + HH + HH')/4; % Help maintain robustness
■ For the following example, the EKF was executed for a test having
dynamic profiles from 100 % SOC down to around 10 % SOC.
80
0
60
40
−2
20
0 −4
0 100 200 300 400 500 600 0 100 200 300 400 500 600
Time (min) Time (min)
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–57
3.15: Problems with EKF, improved with sigma-point methods
■ The EKF is the best known and most used nonlinear Kalman filter.
■ However, it has serious flaws that can be remedied fairly easily.
ISSUE : How input mean and covariance are propagated through static
nonlinear function to create output mean and covariance estimates.
■ Recall that the EKF, when computing mean estimates in Steps 1a
and 1c, makes the simplification EŒfn.x/" ) fn.EŒx"/.
! This is not true in general, and not necessarily even close to true
(depending on “how nonlinear” the function fn.$/ is).
■ Also, in EKF Steps 1b and 2a, a Taylor-series expansion is performed
as part of the calculation of output-variable covariance.
True 3σ contour
Nonlinear
function
➠
3σ contour EKF 3σ contour
* D ˛ 2 .L C +/ " L is a scaling parameter, with .10!2 & ˛ & 1/. Note that this ˛ is different from ˛ .m/ and ˛ .c/ . + is either 0 or 3 " L.
p
ˇ incorporates prior information. For Gaussian RVs, ˇ D 2. h may take any positive value. For Gaussian RVs, h D 3.
! UKF and CDKF are derived quite differently, but the final methods
are essentially identical.
! CDKF has only one “tuning parameter” h, so implementation is
simpler. It also has marginally higher theoretic accuracy than UKF.
■ Output sigma points are computed: Yi D f .Xi /. Then, the output
mean and covariance are computed as well:
p p
X .m/
X .c/
yN D ˛i Y i and †yQ D ˛i .Yi " y/.Y N T.
N i " y/
i D0 i D0
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–61
■ The diagram illustrates the overall process, with the sets X and Y
stored compactly with each set member a column in a matrix:
i th sigma point
X make
sigma
points
p p
xN N
xC) †xQ N
x") †xQ xN †xQ
Y
compute
statistics
yN †yQ
■ Before introducing the SPKF EKF vs. SPKF: mean, variance approximation
10
algorithm, we re-examine the 9 Nonlinear function
Function output value
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–62
Input data scatter Output data scatter
SPKF 3σ contour
True 3σ contour
Nonlinear
function
➠
3σ contour
EKF 3σ contour
■ These five points are transformed to five output points (frame (b)).
■ We see that the mean and covariance of the output sigma points
(dashed ellipse) closely match the true mean and covariance.
■ Will the sigma-point method always be so much better than EKF?
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–63
3.16: The SPKF Steps
C
xO k!1 †C
Q
x;k!1
a;C
Xk!1 make and
augmented wN †e
w
sigma
points vN †vQ
q q
a;C a;C
xO k!1 a;C
xO k!1 C) †a;C
Q
x;k!1
a;C
xO k!1 ") †a;C
Q
x;k!1 xO k!1 †a;C
Q
x;k!1
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–64
i th sigma
point
■ Evaluate state equation using all
x;C w;C
pairs of Xk"1;i and Xk"1;i (where x;C
Xk!1
subscript i denotes that the ith
vector is being extracted from w;C
Xk!1
the original set), yielding the a
uk!1
x;"
priori sigma points Xk;i . x;!
state eqn: Xk;i x;C
Df .Xk!1;i w;C
; uk!1 ; Xk!1;i /
■ That is, compute
x;" x;C w;C
Xk;i D f .Xk"1;i ; uk"1; Xk"1;i /.
Xkx;!
operation. ˛p.m/ xO k!
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–65
noise.
uk
■ First, we compute the points x;!
output eqn: Yk;i D h.Xk;i v;C
; uk ; Xk!1;i /
x;" v;C
Yk;i D h.Xk;i ; uk ; Xk"1;i /.
Yk
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–66
p
X .c/ ( x;" )( )T
†"
xQ y;k
Q D ˛i Xk;i " xO k" Yk;i " yOk .
i D0
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–67
3.17: An SPKF example, with code
yk D xk3 C vk
% Some constants for the SPKF algorithm. Use standard values for
% cases with Gaussian noises. (These are the weighting matrices
% comprising the values of alpha(c) and alpha(m) organized in a
% way to make later computation efficient).
h = sqrt(3);
Wmx(1) = (h*h-Nxa)/(h*h); Wmx(2) = 1/(2*h*h); Wcx=Wmx;
Wmxy = [Wmx(1) repmat(Wmx(2),[1 2*Nxa])]';
for k = 1:maxIter,
% SPKF Step 1a: State estimate time update
% 1a-i: Calculate augmented state estimate, including ...
xhata = [xhat; 0; 0]; % process and sensor noise mean
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–68
% 1a-ii: Get desired Cholesky factor
Sigmaxa = blkdiag(SigmaX,SigmaW,SigmaV);
sSigmaxa = chol(Sigmaxa,'lower');
% 1a-iii: Calculate sigma points (strange indexing of xhat to
avoid
% "repmat" call, which is very inefficient in Matlab)
X = xhata(:,ones([1 2*Nxa+1])) + h*[zeros([Nxa 1]), ...
sSigmaxa, -sSigmaxa];
% 1a-iv: Calculate state equation for every element
% Hard-code equation here for efficiency
Xx = sqrt(5+X(1,:)) + X(2,:);
xhat = Xx*Wmxy;
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–69
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');
xlabel('Iteration'); ylabel('State');
title('Sigma-point Kalman filter in action');
figure(2); clf;
plot(0:maxIter-1,xstore(1:maxIter)-xhatstore,'-',0:maxIter-1, ...
3*sqrt(SigmaXstore),'--',0:maxIter-1,-3*sqrt(SigmaXstore),'--');
grid; legend('Error','bounds',0);
title('SPKF Error with bounds');
xlabel('Iteration'); ylabel('Estimation Error');
1
State
4
0
2 −1
0 −2
0 10 20 30 40 0 10 20 30 40
Iteration Iteration
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–70
3.18: Implementing SPKF on ESC model
■ We refactor the SPKF code much like we did for EKF. The “wrapper”
code is:
load CellModel % loads "model" of cell
% Covariance values
SigmaX0 = diag([1e-3 1e-3 1e-2]); % uncertainty of initial state
SigmaV = 2e-1; % Uncertainty of voltage sensor, output equation
SigmaW = 1e1; % Uncertainty of current sensor, state equation
% Now, enter loop for remainder of time, where we update the SPKF
% 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
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–71
if mod(k,1000)==0, waitbar(k/length(current),hwait); end;
end
close(hwait);
ind = find(abs(soc-sochat)>socbound);
fprintf('Percent of time error outside bounds = %g%%\n',...
length(ind)/length(soc)*100);
% Covariance values
spkfData.SigmaX = SigmaX0;
spkfData.SigmaV = SigmaV;
spkfData.SigmaW = SigmaW;
spkfData.Snoise = real(chol(diag([SigmaW; SigmaV]),'lower'));
spkfData.Qbump = 5;
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–72
Nx = length(spkfData.xhat); spkfData.Nx = Nx; % state-vector length
Ny = 1; spkfData.Ny = Ny; % measurement-vector length
Nu = 1; spkfData.Nu = Nu; % input-vector length
Nw = size(SigmaW,1); spkfData.Nw = Nw; % process-noise-vector length
Nv = size(SigmaV,1); spkfData.Nv = Nv; % sensor-noise-vector length
Na = Nx+Nw+Nv; spkfData.Na = Na; % augmented-state-vector length
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–73
Nw = spkfData.Nw;
Nv = spkfData.Nv;
Na = spkfData.Na;
Snoise = spkfData.Snoise;
Wc = spkfData.Wc;
irInd = spkfData.irInd;
hkInd = spkfData.hkInd;
zkInd = spkfData.zkInd;
if abs(ik)>Q/100, spkfData.signIk = sign(ik); end;
signIk = spkfData.signIk;
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–74
% Q-bump code
if r^2>4*SigmaY, % bad voltage estimate by 2-SigmaX, bump Q
fprintf('Bumping sigmax\n');
SigmaX(zkInd,zkInd) = SigmaX(zkInd,zkInd)*spkfData.Qbump;
end
% Calculate new states for all of the old state vectors in xold.
function xnew = stateEqn(xold,current,xnoise)
current = current + xnoise; % noise adds to current
xnew = 0*xold;
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–75
xnew(irInd,:) = RC*xold(irInd,:) + (1-RC)*current;
Ah = exp(-abs(current*G*deltat/(3600*Q))); % hysteresis factor
xnew(hkInd,:) = Ah.*xold(hkInd,:) - (1-Ah).*sign(current);
xnew(zkInd,:) = xold(zkInd,:) - current/3600/Q;
xnew(hkInd,:) = min(1,max(-1,xnew(hkInd,:)));
xnew(zkInd,:) = min(1.05,max(-0.05,xnew(zkInd,:)));
end
■ For the following example, the SPKF was executed for the same test
profiles as before.
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)
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–76
3.19: Real-world issues pertaining to sensors, initialization
Current-sensor bias
ikb D ik"1
b
C nbk"1,
where nbk is a fictitious noise source included in the model only that
allows the SPKF to adapt the bias state.
■ The output equation is also modified:
X
yk D OCV.´k / C M hk " Rj iRj ;k " R0.ik " ikb / C vk ;
j
■ We find -2U from where the inverse CDF is equal to 1 " ˛=2. In
MATLAB:
X2U = chi2inv(1-0.025,24) % Upper critical value X2U = 39.3641
■ Note that -2L and -2U need to be computed once only, offline.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–79
■ If vehicle is off for a “long” time, just assume that cell voltage is
equivalent to OCV:
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–80
3.20: Real-world issue: Speed, solved by “bar-delta” filtering
■ In this section we talk about efficient SOC estimation for all individual
cells in a large battery pack.
OBSERVATION : While “pack SOC” does not make sense, the concept of
“pack-average SOC” is a useful one.
■ Since all cells in a series string experience the same current, we
expect their SOC values to
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–81
! Also, the delta states change much more slowly than the average
state, so the delta filters can be run less frequently, down to 1=Ns
times the rate of the bar filter.
! Overall complexity can be reduced from order Ns to order 1C .
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–83
3.21: Bar-delta filtering using the ESC cell model
ikb D ik"1
b
C nbk"1,
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–84
■ And, if we also consider the current-bias state,
b
Ń k D Ń k"1 " .ik"1 " ik"1 /$t QN inv;k"1.
ikb D ik"1
b
C nbk"1 ,
RN QN
where nk 0 and nk inv are fictitious noise sources that allow the SPKF to
adapt the corresponding pack-average parameters.
■ The bar-filter for the pack employs an SPKF that uses this model of
pack-average states and the measurement equation
X
N
yNk D OCV. Ń k / C M hk " Rj iNRj ;k " RN 0;k .ik " ikb / C vk ;
j
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–85
■ These all factor into determining pack available power and lifetime
(state-of-health) estimates.
■ We will first consider the delta filter approach to determining cell SOC.
.i / .i /
■ Note, from before, $´k D ´k " Ń k . Then, using prior equations for
.i /
the dynamics of ´k and Ń k , we find:
.i / .i /
$´k D ´k " Ń k
( .i / ) ( )
/$t QN inv;k"1
b .i / b
D ´k"1 " .ik"1"ik"1 /$tQinv;k"1 " Ń k"1 " .ik"1"ik"1
.i / b .i /
D $´k"1 " .ik"1"ik"1 /$t$Qinv;k"1
where $Qinv;k D Qinv;k " QN inv;k .
.i / .i /
.i / .i /
■ Because $Qinv;k tends to be small, the state $´k does not change
quickly, and can be updated at a slower rate than the pack-average
SOC by accumulating .ik"1 " ik"1
b
/$t in-between updates.
■ An output equation suitable for combining with this state equation is
X
.i / .i / N
yk D OCV. Ń k C $´k / C M hk " Rj iNRj ;k " .RN 0;k C $R0;k /.ik " ikb / C vk
.i /
.i /
■ To estimate $´k , an SPKF is used with these two equations. Since it
is a single-state SPKF, it is very fast.
■ As a preview of parameter estimation (talked about more in the next
chapter. . . ) we can similarly make state-space models of the
delta-resistance and delta capacity states.
■ A simple state-space model of the delta-resistance state is:
.i / .i / $R
$R0;k D $R0;k"1 C nk"10
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–86
where $R0;k D R0;k " RN 0;k and is modeled as a constant value with a
.i / .i /
$R
fictitious noise process nk 0 allowing adaptation, yk is a crude
$R
estimate of the cell’s voltage, and vk 0 models estimation error.
■ The dynamics of the delta-resistance state are simple and linear
enough to use a single-state EKF rather than an SPKF.
■ To estimate cell capacity using an EKF, we model
.i / .i / $Q
$Qinv;k D $Qinv;k"1 C nk"1inv
.i / .i /b
dk D .´k " ´k"1/ C .ik"1 " ik"1 /$t #
# '
QN inv;k"1 C $Qinv;k"1 C ek
.i /
.i / 1
Qk D
QN inv;k C $Qinv;k
.i /
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–87
3.22: Example of bar-delta, using desktop validation
DESKTOP VALIDATION :
BMS
Evaluation
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–88
■ Either way, validation scenarios include: Normal operation, improper
SOC initialization, sensor failures (fault + noise), temperature drift,
new and old cells mixed, different drive cycles, current-sensor bias.
■ Insight and validation via analysis and display of outputs.
−25 3.9
−50 3.8
−75 3.7
−100 3.6
−125 3.5
−150 3.4
−175 3.3
−200 3.2
0 5 10 15 20 25 30 35 40 45 50 55 60 65 0 5 10 15 20 25 30 35 40 45 50 55 60 65
Time (min) Time (min)
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–89
■ Some results showing accuracy of the method:
Total bar-delta SOC estimates for all cells Total bar-delta estimated resistances for all cells
60 2.8
True SOC 2.7
Estimated SOC
55 2.6
2.4
50
2.3
2.2
45 2.1
2
40 1.9
1.8 True resistance
1.7 Estimated resistance
35
1.6
0 5 10 15 20 25 30 35 40 45 50 55 60 65 0 5 10 15 20 25 30 35 40 45 50 55 60 65
Time (min) Time (min)
3 3
2 2
1 1
0 0
−1 −1
−2 −2
−3 −3
−4 −4
−5 −5
0 5 10 15 20 25 30 35 40 45 50 55 60 65 0 5 10 15 20 25 30 35 40 45 50 55 60 65
Time (min) Time (min)
True resistance
3.25
Estimated resistance 0.75
Current-sensor bias (A)
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–90
■ Capacity estimates evolve in a similar way to resistance estimates.
Description of test (for pack comprising 100 cells) CPU time per iteration Speedup
One pack bar filter, 100 delta filters updated per iteration 0.190 ms 27.7
One pack bar filter, 50 delta filters updated per iteration 0.123 ms 42.9
■ We have seen good and bad ways to estimate SOC for all cells.
■ Model-based methods are preferred; KF-based methods are “optimal”
in some sense.
■ Additionally, KF estimates entire state—not only SOC—therefore can
also be used for degradation predictions. . .
■ Lots of nuances unexplored in this short section of notes. ECE5550
goes into much more depth and breadth of implementation of KF
■ Our next step is to look at state-of-health estimation, which is a form
of parameter estimation.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–91
Appendix: General sequential probabilistic inference solution
yk D h.xk ; uk ; vk /;
Definitions: Let
xQ k" D xk " xO k" ; yQk D yk " yOk .
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–92
Appendix: Summary of the linear Kalman filter
yk D Ck xk C Dk uk C vk ,
( )
State estimate measurement update: xO kC D xO k" C Lk yk " yOk .
"
If a measurement is missed for some reason, then simply skip the measurement update for that
iteration. That is, Lk D 0 and xO kC D xO k! and †C
Q
x;k D †!
Q .
x;k
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–93
Appendix: Summary of the nonlinear extended Kalman filter
yk D h.xk ; uk ; vk /;
Definitions: ˇ ˇ
df .x ; u ; w / ˇ df .x ; u ; w / ˇ
AOk D BO k D
k k k ˇ k k k ˇ
dxk ˇ C dwk ˇ
ˇ xk DxO k ˇ wk DwN k
dh.xk ; uk ; vk / ˇˇ dh.xk ; uk ; vk / ˇˇ
CO k D ˇ DO k D ˇ .
dx k !
xk DxO k dv k vk DvN k
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–94
Appendix: Summary of the nonlinear sigma-point Kalman filter
yk D h.xk ; uk ; vk /;
Definitions: Let
$ &T $ &T
xka D xkT ; wkT ; vkT ; Xka D .Xkx /T ; .Xkw /T ; .Xkv /T ; p D 2 # dim.xka /.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Battery State Estimation 3–95
Computation: (cont):
p
X .c/ ( )( )T
Estimator gain matrix: Q D
†y;k ˛i Yk;i " yOk Yk;i " yOk .
i D0
p
X .c/ ( )( )T
†" Q D
xQ y;k ˛i x;"
Xk;i " xO k" Yk;i " yOk .
i D0
Lk D †" "1
Q .
Q †y;k
xQ y;k
( )
State estimate meas. update: xO kC D xO k" C Lk yk " yOk .
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
Degrees of Upper Tail Areas
■
Freedom 0.995 0.99 0.975 0.95 0.90 0.75 0.25 0.10 0.05 0.025 0.01 0.005
1 0.000 0.000 0.001 0.004 0.016 0.102 1.323 2.706 3.841 5.024 6.635 7.879
2 0.010 0.020 0.051 0.103 0.211 0.575 2.773 4.605 5.991 7.378 9.210 10.597
3 0.072 0.115 0.216 0.352 0.584 1.213 4.108 6.251 7.815 9.348 11.345 12.838
4 0.207 0.297 0.484 0.711 1.064 1.923 5.385 7.779 9.488 11.143 13.277 14.860
5 0.412 0.554 0.831 1.145 1.610 2.675 6.626 9.236 11.070 12.833 15.086 16.750
6 0.676 0.872 1.237 1.635 2.204 3.455 7.841 10.645 12.592 14.449 16.812 18.548
7 0.989 1.239 1.690 2.167 2.833 4.255 9.037 12.017 14.067 16.013 18.475 20.278
8 1.344 1.646 2.180 2.733 3.490 5.071 10.219 13.362 15.507 17.535 20.090 21.955
9 1.735 2.088 2.700 3.325 4.168 5.899 11.389 14.684 16.919 19.023 21.666 23.589
10 2.156 2.558 3.247 3.940 4.865 6.737 12.549 15.987 18.307 20.483 23.209 25.188
ECE5720, Battery State Estimation
11 2.603 3.053 3.816 4.575 5.578 7.584 13.701 17.275 19.675 21.920 24.725 26.757
12 3.074 3.571 4.404 5.226 6.304 8.438 14.845 18.549 21.026 23.337 26.217 28.300
13 3.565 4.107 5.009 5.892 7.042 9.299 15.984 19.812 22.362 24.736 27.688 29.819
14 4.075 4.660 5.629 6.571 7.790 10.165 17.117 21.064 23.685 26.119 29.141 31.319
15 4.601 5.229 6.262 7.261 8.547 11.037 18.245 22.307 24.996 27.488 30.578 32.801
16 5.142 5.812 6.908 7.962 9.312 11.912 19.369 23.542 26.296 28.845 32.000 34.267
17 5.697 6.408 7.564 8.672 10.085 12.792 20.489 24.769 27.587 30.191 33.409 35.718
Appendix: Critical Values of -2
18 6.265 7.015 8.231 9.390 10.865 13.675 21.605 25.989 28.869 31.526 34.805 37.156
19 6.844 7.633 8.907 10.117 11.651 14.562 22.718 27.204 30.144 32.852 36.191 38.582
20 7.434 8.260 9.591 10.851 12.443 15.452 23.828 28.412 31.410 34.170 37.566 39.997
21 8.034 8.897 10.283 11.591 13.240 16.344 24.935 29.615 32.671 35.479 38.932 41.401
22 8.643 9.542 10.982 12.338 14.041 17.240 26.039 30.813 33.924 36.781 40.289 42.796
23 9.260 10.196 11.689 13.091 14.848 18.137 27.141 32.007 35.172 38.076 41.638 44.181
24 9.886 10.856 12.401 13.848 15.659 19.037 28.241 33.196 36.415 39.364 42.980 45.559
25 10.520 11.524 13.120 14.611 16.473 19.939 29.339 34.382 37.652 40.646 44.314 46.928
critical value of -2 for a specified upper tail area ˛.
26 11.160 12.198 13.844 15.379 17.292 20.843 30.435 35.563 38.885 41.923 45.642 48.290
For some deg. of freedom, each entry represents the
27 11.808 12.879 14.573 16.151 18.114 21.749 31.528 36.741 40.113 43.195 46.963 49.645
0
28 12.461 13.565 15.308 16.928 18.939 22.657 32.620 37.916 41.337 44.461 48.278 50.993
29 13.121 14.256 16.047 17.708 19.768 23.567 33.711 39.087 42.557 45.722 49.588 52.336
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
30 13.787 14.953 16.791 18.493 20.599 24.478 34.800 40.256 43.773 46.979 50.892 53.672
1"˛
31 14.458 15.655 17.539 19.281 21.434 25.390 35.887 41.422 44.985 48.232 52.191 55.003
32 15.134 16.362 18.291 20.072 22.271 26.304 36.973 42.585 46.194 49.480 53.486 56.328
33 15.815 17.074 19.047 20.867 23.110 27.219 38.058 43.745 47.400 50.725 54.776 57.648
34 16.501 17.789 19.806 21.664 23.952 28.136 39.141 44.903 48.602 51.966 56.061 58.964
35 17.192 18.509 20.569 22.465 24.797 29.054 40.223 46.059 49.802 53.203 57.342 60.275
36 17.887 19.233 21.336 23.269 25.643 29.973 41.304 47.212 50.998 54.437 58.619 61.581
-2U.˛;df/
37 18.586 19.960 22.106 24.075 26.492 30.893 42.383 48.363 52.192 55.668 59.893 62.883
˛
38 19.289 20.691 22.878 24.884 27.343 31.815 43.462 49.513 53.384 56.896 61.162 64.181
39 19.996 21.426 23.654 25.695 28.196 32.737 44.539 50.660 54.572 58.120 62.428 65.476
40 20.707 22.164 24.433 26.509 29.051 33.660 45.616 51.805 55.758 59.342 63.691 66.766
45 24.311 25.901 28.366 30.612 33.350 38.291 50.985 57.505 61.656 65.410 69.957 73.166
50 27.991 29.707 32.357 34.764 37.689 42.942 56.334 63.167 67.505 71.420 76.154 79.490
3–96