Skip to main content
Dmitri De Vaz

Bayesian Filtering - Estimating Room Temperature using Sensor Fusion

Kalman Filter Animation
Estimating the position of an object using a Kalman Filter, from Kalman and Bayesian Filtering in Python.

Objective #

The main objective was to be able to reliably estimate the temperature that occupants experience using only ceiling mounted temperature sensors. This is challenging since there is normally a temperature gradient from floor to ceiling, so measuring temperature at the ceiling and reporting it as the room temperature would lead lead to problems, especially when using this temperature as feedback in a temperature control system which is a primary use-case for the product.

We needed to develop a system that is robust to different ceiling heights (to an extent), and different levels of temperature stratification within the space (the floor to ceiling temperature offset varies between spaces). In order to do this, we knew we needed to take multiple measurements, account for sensor noise, incorporate different methods of sensing technology, and combine that with a model of room temperature thermal dynamics while also accounting for uncertainty in the model itself. Bayesian filters are a good candidate for this type of problem.

What is Bayesian filtering and what problem does it solve? #

Bayesian filtering is a method for estimating the state of a dynamic system based on a sequence of noisy observations. These methods are usually recursive, meaning that they can easily be efficiently implement on a computer or microcontroller, without requiring huge amounts of compute.

What is Sensor Fusion? #

Sensor fusion is a process of combining information from multiple sensors to create a more accurate and reliable measurement than from any individual sensor. The idea is to take the strengths of each type of sensor and combine that information into a stronger estimate, in a sense creating a virtual sensor from different physical sensors. There are many ways to implement sensor fusion such as the Kalman filter.

The Kalman Filter #

The Kalman filter is a specific type of Bayesian filter that is well suited for problems that are (mostly) linear and where the noise in the system are normally distributed (both of these conditions are satisfied for the temperature measurement problem).

There are many excellent explainer blog posts and text books for the Kalman filter. I'll give a high level overview here and then list some of my favourite explainers below.

The Kalman filter has 2 main steps:

1. Predict #

Based on all of the observations we've seen thus far and our model of the system, what is our best guess of the system state? When making a prediction, all we're doing is computing the expected output of our model for the next time step. When doing this, it's important to capture the inherent uncertainty in this process (i.e. making a pointy distribution a little more flat, spread out, and less precise). The amount of uncertainty increase is based on the process noise which is a parameter of the Kalman Filter. In addition to tracking the system state, the Kalman filter also tracks the variance and covariance between the different state variables.

2. Update #

Compute the Kalman gain which is a parameter that tells the filter how much to trust the measurements relative to the prediction from the model. The computation for the gain is based on the ratio of variances between the model and the observations - which makes some intuitive sense. If the measurements are all over the place, it makes more sense to trust the model. On the other hand, if the measurements are very tightly grouped, then we can trust the measurements more. This parameter dynamically adapts as the Kalman filter runs. In most well designed Kalman filters, this gain eventually converges to a mostly constant value. So this step applies the Kalman gain to combine the prediction with the measurements. Again, we have to update the covariances so that they reflect our current belief and uncertainty.

That was a very quick explanation of the Kalman filter. I really like the following resources for a gentle introduction to Kalman filters:

My role #

As the Senior engineer and technical lead, my role in this project was to:

Impact #