# Kalman Filter: How to Define Inputs and Outputs of a Model

I'm a software engineer with a CS degree working in machine learning. I'm trying to learn about Kalman Filters.

In this short YouTube video from Mathworks, there's a discussion on a Kalman Filter with regard to a rocket:

• We want to measure a rocket engine's internal temperature $$T_{in}$$.
• We can't put a temperature sensor directly inside the exhaust port because it's too hot.
• Instead, we put an external temperature sensor outside the engine exhaust to measure $$T_{ext}$$.
• We know how much fuel we're using: $$W_{fuel}$$.

The video says that we want to reduce the error between the measured external temperature $$T_{ext}$$ and an estimate of the external temperature $$\hat{T}_{ext}$$. In turn, that will reduce the error between the unobserved temperature $$T_{in}$$ and its estimate $$\hat{T}_{in}$$.

I work in machine learning, so I'm confused by what are the inputs and outputs of this system. My specific questions are:

1. $$T_{ext}$$ is an input to the system using an external sensor. Why is it shown as an output of this system?

2. We are trying to predict $$\hat{T}_{in}$$. Presumably it is a function of $$W_{fuel}$$ and $$T_{ext}$$; that is, $$\hat{T}_{in} = f(W_{fuel}, T_{ext})$$. Why is this system even trying to predict the external temperature $$\hat{T}_{ext}$$ if the true external temperature $$T_{ext}$$ is measured?

3. If I were to solve this problem using machine learning, I'd implement a regression model to predict exactly $$\hat{T}_{in} = f(W_{fuel}, T_{ext})$$ with $$W_{fuel}$$ and $$T_{ext}$$ as input features to linear regression or a neural network model. Why do we need to set up this Kalman Filter system at all?

Thanks for any help.

• Notice the bracket on Text. Measured external temperature vs estimated external temperature. The first one is an input, the second one an output. Based on your model, process noise and measurement noise estimates, the Kalman filter will try to estimate optimally (in a Gaussian sense) the external and internal temperatures.
– Ben
Aug 12, 2021 at 4:27
• If your model is reasonably close to your system and if your process and measurement covariances are well chosen, then Text measured and Text estimated should comverge
– Ben
Aug 12, 2021 at 4:28
• @Ben: Why do we even need to estimate $\hat{T}_{ext}$? Why do we care about it? We want to estimate $\hat{T}_{in}$, right? Aug 12, 2021 at 4:37
• Your measurement is absolutely noise-free? If not, then estimating it will improve the measurement. Remember, you also have your fuel intake as a measurement.
– Ben
Aug 12, 2021 at 12:41
• Shouldn't the arrow for $T_{ext}$ in that picture be pointing into the box rather than out of the box? Aug 12, 2021 at 17:12

The Kalman Filter is basically a framework to fuse 2 things:

1. Measurement.
2. Dynamic Model (Dynamic in the sense we can predict next value from a current value).

In your case the model is composed of two things:

1. Model which connects $${T}_{ext}$$ and $${W}_{fuel}$$ to $${T}_{in}$$.
2. Measurement of $${T}_{ext}$$.

Now, the reason you estimate $${T}_{ext}$$ is because no sensor is perfect. The model of a sensor is $${T}_{ext} \left[ k \right] = {T}_{ext - gt} \left[ k \right] + v \left[ k \right]$$. Namely we get a measurement with added noise.

What's missing in the model of the video is the actual model. I have no experience in the field of heat transfer but let's assume the model is something like:

$${T}_{in} \left[ k \right] = {T}_{in} \left[ k - 1 \right] + \alpha {w} \left[ k - 1 \right]$$

And:

$${T}_{ext} \left[ k \right] = \beta {T}_{in} \left[ k \right]$$

Then you can build the model for the Kalman Filter and it will fuse the knowledge about $${T}_{in}$$ from the model which relates to $${T}_{out}$$ and the model which given the $${T}_{in}$$ of the previous iteration how it should be in the next.

Regarding your experience with Machine Learning.
Kalman Filter assumes a Bayesian Model. Hence it is not a parameterized.
You could estimate $${T}_{in}$$ from measurements of $${T}_{ext}$$ and $$W$$ but then you'll miss the prior you're given: The dynamic model.

• Thank you for the answer. Am I correct in generalizing that in problems that need a Kalman Filter: (1) We are looking to predict some hidden state (in this case $T_{in}$); (2) We also need to predict the measurement of every noisy sensor that we use; and (3) More accurately performing (2) will help us more accurately perform (1) ? Aug 14, 2021 at 15:46
• There are 2 models: The dynamic model and the measurement model. They define the same state vector. Kalman Filter fuse them for the optimal estimation of the state vector.
– Royi
Aug 14, 2021 at 16:05
• Thank you. Can you please let me know if my three points (1), (2), (3) are correct, incorrect, or even irrelevant? Aug 14, 2021 at 18:22
• They are correct. Just pay attention we don't do (2) explicitly. We just go for (3) which is written in a form which fuse the measurement and the model optimally.
– Royi
Aug 14, 2021 at 18:25