From the series: Understanding Kalman Filters

*
Melda Ulusoy, MathWorks
*

Learn the working principles of state observers, and discover the math behind them. State observers are used to estimate the internal states of a system when you can’t directly measure them.

You will learn how a state observer uses the input and output measurements to estimate system states. The example will walk you through the mathematical derivation of a state observer.

You will discover how the state observer utilizes feedback control to drive the estimated states to the true states. Kalman filtering provides an optimal way of choosing the gain of this feedback controller.

In this video, we’ll discuss state observers. This concept will help explain what Kalman filters are and how they work. Let’s start with an example. This is little Timmy, and you want to know about his mood and how he’s feeling right now. However, there is no direct way of measuring his mood. So, what you do is give him a cookie and start observing his facial expressions. This observation helps you estimate his real mood. State observation helps you estimate something that you can’t see or measure directly.

Throughout the rest of the discussion, if you see something with a hat on it, this means that it is estimated through a state observer. So, if the state x is shown with a hat, then it is an estimated state.

Next, we’ll look at a more solid example. You’re traveling in space to discover new planets. In order to get to the planets safely, you need to monitor the internal temperature of your jet engine. If it gets too hot, it could damage your spacecraft. However, there isn’t any feasible way of measuring the internal temperature, since a sensor placed inside the engine would melt. What you can do is to place the sensor on a colder surface and measure the temperature there. Let’s call this temperature T_{external} and the one you can’t measure, but you need to estimate, T_{internal}.

This is your rocket. You’re wondering how high the internal temperature of the engine is, since this will tell you how you should regulate the fuel flow to your rocket. However, you don’t have access to the state T_{internal}. Instead, you can measure T_{external}. The signals that are available to you are the fuel flow and your measurement. How do you estimate the internal temperature? Actually, you have access to more information. Since your math is pretty good, you can drive the equations that will give you the mathematical model of your real system. You already know how much fuel you’re adding to your rocket, so if you now input this fuel flow to your mathematical model, this will give you an estimate of your output. And also, notice that since you have all the governing equations, you can even calculate the internal state of this system.

Ok, does this solve your problem now? Unfortunately, it doesn’t. No doubt that you’re good at math, but in reality, the mathematical model you found is only an approximation of your real system. It is subject to uncertainties. If you had a perfect model without any uncertainties and if your real system and your model had the same initial conditions, then your measurement and estimated output values would match each other, and therefore the estimated internal temperature would match the true internal temperature as well. But in real life, this is an unlikely scenario and therefore the estimated external temperature won’t match the measured temperature. That’s why you need to use a state estimator to estimate your internal states. Let’s see how a state estimator works:

Here, our goal is to match the estimated external temperature with the measured external temperature. We know that if these two are equal, then the model will converge to the real system. So, the estimated internal temperature will converge to its true value. What we’re trying to do is to minimize the difference between the estimated and measured external temperature. Does this sound familiar to you? Actually, we’re talking about a feedback control system, where we try to control the error between the measured and estimated external temperature at zero using a controller K.

If we now update our diagram on the left hand side based on what we’ve discussed here, it will look like this. This part represents the state observer. By closing the loop with a controller K around the observer, we try to eliminate the error between the estimated and measured external temperature such that the estimated internal temperature is driven to its true value.

In summary, you can’t directly measure the internal engine temperature. But you know how much fuel you’re supplying to your rocket, so you can run this through your mathematical model and estimate the output, which you can then use along with your real measurement to estimate the internal state of the system.

The question is how to choose the controller gain K such that the error between the measured and estimated external temperature is minimized optimally. We’ll provide more insights into this in the next videos where we’ll discuss how Kalman filters work.

Next, let’s look at how we can explain the state observer mathematically:

We will generalize the problem and show the input as u, the output as y, and any states we want to estimate as x. Our goal is to drive x̂ to x, so we can define the difference between these values as an error. Next, let’s write down the equations for the system and the observer. If we subtract these equations from each other, this will give us the error dynamics. By rearranging terms, we see that the error dynamics can be shown by this equation. The solution to this equation is an exponential function. What this means is if this term is less than zero, we’re good, because we know that our error will vanish over time and x̂ will converge to x.

At this point, you may be asking if we really need the KC term in this equation. Because even without the feedback loop that adds the KC term to the equation, we would have a decaying exponential function for the error. The significance of having a feedback loop around the observer is that we can control the decay rate of the error function by selecting the controller gain K accordingly. However, here the decay rate solely depends on the matrix A. And if there are some uncertainties in the mathematical model, this means you don’t know A exactly. Therefore, you can’t control how quickly the error will vanish. Having the feedback controller gives you more control over this equation and guarantees a faster elimination of the error. And the faster the error vanishes, the faster the estimated states x̂ converge to the true states x.

An optimal way of choosing the gain K is performed through the use of Kalman filters. In the next video, we’ll get insights into how Kalman filters work.

**Recorded: 14 Feb 2017**