Last week, we studied the extended Kalman filter for battery state estimation. The EKF is probably the most-used and the best-known nonlinear Kalman filter, not only for battery state estimation but for nonlinear state estimation in general. But it does have some serious flaws, and these can be corrected fairly easily. The basic issue is how the input mean and covariance of a random variable are propagated through the static nonlinear functions that define the state equation and the output equation of the model in order to create an estimate of the output mean and the output covariance. Remember that in EKF, steps 1a and 1c, the EKF assumes that the expected value of a nonlinear function of a random variable is approximately equal to the same nonlinear function evaluated at the expected value of the random variable. In other words, it assumes that I can move the expectation operation from the output of the function to the input of the function. And you understand that this assumption is not true in general, and sometimes it's not even close to being true. The assumption is most valid when the nonlinear function is approximately linear, but if the nonlinear function is very different from a linear, straight-line relationship, then the approximation will not work well. The second issue with the EKF has to do with how it computes covariance matrices. When we compute covariance matrices in steps 1b and 2a, we need to linearize the nonlinear state equation and output equation of the model, and we use a Taylor-series expansion and we delete the higher order terms. So remember the Taylor-series expansion takes any old function and writes it as a constant value, plus a linear term, plus quadratic terms and so forth. And we are assuming that the quadratic and higher terms are zero and keeping only the constant value on the linear term. So that is going to result in a loss of accuracy. And if the nonlinear terms are relatively small, then the EKF should work well. But if the nonlinear terms are relatively large, the EKF may not work well at all. So the Taylor-series expansion gives us actually a pretty good way to think about how linear or how nonlinear some function is. If the quadratic and higher order terms are significant when compared to the linear term, then we would say that the function is quite nonlinear. But if the quadratic and higher order terms are small or negligible compared with the linear term, then we might assume that the function is fairly linear instead. So the general principle is that if the functions describing the state equation and the operative equation of the model are fairly linear, the EKF should work pretty well, but otherwise it may not. The illustration on this slide attempts to show this idea graphically. In the illustration, we are investigating what happens when we propagate some random variable through a nonlinear function. The input to the nonlinear function comes from the horizontal axis. But since the input is a random variable, we can't simply draw one point on the horizontal axis. Instead I draw the pdf, the probability density function, of the input random variable on the horizontal axis. And here that's shown as the blue Gaussian pdf that is labeled Input pdf. And in our case, the input has a mean of 1.05 and a standard deviation of approximately 0.1. In this illustration, samples of the input random variable are passed through a nonlinear function to produce outputs, and the nonlinear function is drawn on this illustration using the red solid line. So if this were a deterministic example, we would take our deterministic input from the horizontal axis and we would draw a line vertically until we intersect the red nonlinear function line. And then from that intersection point, we would draw a line horizontally until we intersect with the vertical axis and that would be the output of the function. But here, when samples of the input random variable are propagated through the nonlinear function, they produce samples of an output random variable in much the same way as that. And if I do this for an infinite number of samples, then we would get an output random variable description, a statistics description of it. They would have maybe some mean and some covariance. The EKF assumes that we can predict what the mean and the covariance of that output random variable are by making some assumptions. It assumes that if I take the input mean and pass that through the nonlinear function, then whatever value I get out is going to be the output mean. And so to do this we would take the input value, which is the input mean of 1.05. We would pass that value into the red function, again, we would locate the point on the horizontal axis, so 1.05, and draw a line vertically until it intersects the red line. And then we draw a straight line horizontally from that intersection point until it encounters the vertical axis. And that value would be the EKF estimate of the output mean. And in this case, it's a value of around 4.5. So the EKF approach using assumption number one, defining the mean of an output variable, produces an estimated mean of about 4.5. The EKF approach to finding the covariance of the output variable is to take the input covariance and scale it using the slope of the nonlinear function at the location of the mean. So we evaluate that slope where the input random variable has its mean value. And here that slope of the nonlinear function is illustrated by the dotted line. And the input standard deviation is scaled by that slope to produce the output standard deviation. Or the input variance is scaled by that slope squared to produce the output variance. When we propagate the mean of the input pdf through the nonlinear function and we propagate the covariance of the input pdf through the nonlinear function using these EKF assumptions, the resulting output mean and variance estimates produce an output pdf, if we assume the output is Gaussian, that is drawn on the vertical axis and denoted by the arrow as EKF output pdf. You can see that's a dotted line. The true output pdf, on the other hand, is drawn on the vertical axis as a blue solid line. And you can see that the blue solid line of the true output pdf is very different from the dashed line or dotted line of the EKF approximate pdf. And so the EKF approach, using assumption one and assumption number two, is not producing an accurate estimate of the output mean and covariance for that example. What do here is I do the same thing except for a 2-dimensional input. The left figure shows a scatter plot of random samples drawn from a 2-dimensional Gaussian distribution, and I've also drawn the 3-sigma contour line for this distribution using a blue ellipse. So more than 99% of the input data points are contained inside of this ellipse. When the input random variable is passed through a nonlinear function, and I don't illustrate what that function is in this case, but when I pass it through some nonlinear function, it produces a 2-dimensional output random variable whose data points I've also plotted as a scatterplot on the right. And the shape of the output scatterplot is not an ellipse. You can see that pretty clearly. So we can conclude that the output pdf is not actually a Gaussian random variable. But we can still use the EKF assumptions to produce an estimated mean and an estimated covariance of the output. And we can use statistical methods to find the true mean and the 3-sigma contour of the output, which is what I do here. So these are illustrated on the figure as a dotted black line for the EKF assumption, and the blue solid line for the more accurate computation. And you can see that the EKF proximation is quite poor compared with the true contour. So this week you will learn about a different method for propagating random variables through nonlinear functions to estimate the mean and covariance of the output random variable. And this method is known as a sigma-point approach. And the sigma-point approach can make much better estimates of the mean and covariance of output random variables, especially if the function involved is quite nonlinear. So we're now starting week five. And you're going to learn about the sigma-point common filter. And by now, you know very well that the EKF is the best-known and probably the most widely used nonlinear state estimator. But you've seen that it has some limitations due to the assumptions that were made in deriving its steps, regarding how it approximates expectations inside of the Gaussian sequential probabilistic inference solution. It makes the assumption that the expected value of a nonlinear function of a random variable is approximately equal to that function evaluated at the expected value of its input random variable. But you know that this approximation is not exactly true, and sometimes it may be very far from true. The EKF also makes the assumption that it is reasonable to truncate a Taylor-series expansion when evaluating covariances. But you know that this can also result in a significant loss of accuracy when the function being approximated is very nonlinear. This week you will learn about a sigma-point approach to approximating expectations. And this approach can work much better for functions that are significantly nonlinear. The sigma-point approach results in a different kind of Kalman filter that's commonly known as the sigma-point Kalman filter. And, one variation is known as the unscented Kalman filter. Sigma-point Kalman filters usually outperform extended Kalman filters for nonlinear problems, and they have the same computational complexity as the extended Kalman filter. In other words, they have the same order, the same relative number of floating-point operations required, but I grant you that they are somewhat more conceptually complicated. They are more difficult to understand initially so we're going to spend some time this week examining, very carefully, how the sigma-point Kalman filter works and how to implement it efficiently in Octave code. So to do that, you'll experiment with this code that I provide to you for using a sigma-point Kalman filter for state-of-charge estimation. And working the SPKF will be part of the capstone project for this course as well.