State Observers | Understanding Kalman Filters, Part 2
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.
Download this virtual lab to study linear and extended Kalman filter design with interactive exercises.
Recorded: 14 Feb 2017
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 moods. So what you do is give him a cookie and start observing his facial expressions. This observation helps you estimate his real moods. 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 measurements. How do you estimate the internal temperature? Actually, you have access to more information. Since your method's pretty good, you can derive 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 the system.
Okay, 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 estimate of the 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 0 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 measurements 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 derive x hat 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 aerodynamics 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 hat 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 will have a decaying exponential function for the error.
The significance of having a feedback loop around the observer is that we can control the decaying rate of the error function by selecting the controller gain k accordingly. However, here the decay rates 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 hat 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.