# Data Science of IoT: Sensor fusion and Kalman filters, Part 2

The second part of this tutorial examines use of Kalman filters to determine context for IoT systems, which helps to combine uncertain measurements in a multi-sensor system to accurately and dynamically understand the physical world.

**Introduction**

This two part paper is created as part of the **Data Science for IoT practitioners course** (starting Nov 17) by Ajit Jaokar. Kalman filters and sensor fusion is a hard topic and has implications for IoT. I welcome comments and feedback at ajit.jaokar at futuretext.com. Please email us at **info at ****futuretext.com **if you want to join the Data Science for IoT practitioners course.

Part One of this article can be found at Data Science of IoT: Sensor fusion and Kalman filters, Part 1

**Understanding State**

At the risk of introducing some mathematics – it is necessary to understand the meaning of ‘State’ when it comes to Kalman filters. Typically, Kalman filters are used to predict the state of Dynamic systems.

Dynamic systems are systems that change or evolve in time according to a fixed rule. For many physical systems, this rule can be stated as a set of first-order differential equations: . This set of input, output and state variables related by first-order differential equations is called a state-space representation of a physical system. For simplicity, here, we describe systems that have a state characterized by linear and time-invariant (LTI) properties.

In Dynamic systems, the minimum set of variables, known as state variables, fully describe the system and its response to any given set of inputs. In particular, in a state-determined system, given a minimum set of variables xi(t), i = 1,…,n, together with knowledge of those variables at an initial time t0 and the system inputs for time t ≥ t0, we can predict the future system state and outputs for all time t>t0. Large classes of engineering, biological, social and economic systems may be represented by state-determined system models. This included Internet of Things applications.

**Implications of Kalman filters to IoT **

Based on the above, we can see that there are synergies in the use of Kalman filters and IoT. For example, in inferring state based on inputs, use of Time series data, working with values that are incomplete. **More generally, IoT systems need to understand and interpret context**. They need to filter noise and also project input readings to infer a new state (which can be seen as a reflection of the overall context). This requires us to combine readings from different sources and also to interpret their relative significance. Hence, Kalman filters are used in Sensor fusion. Sensor fusion techniques are used in a variety of areas involving IoT including Radars, Robotics, Wearables, Health etc.

The Context of a user or a system is key in many areas like Mobility and Ubiquitous computing. Context based design is used in cross referencing the physical context with the digital context making the user experience and response interactive. The paper An adaptive Kalman filter technique for context-aware heart rate monitoring . is an example of the use of Kalman filters in healthcare IoT applications.

*Traditional physiological monitoring systems convert a person’s vital sign waveforms, such as heart rate, respiration rate and blood pressure, into meaningful information by comparing the instant reading with a preset threshold or a baseline without considering the contextual information of the person. It would be beneficial to incorporate the contextual data such as activity status of the person to the physiological data in order to obtain a more accurate representation of a person’s physiological status. In this paper, we proposed an algorithm based on adaptive Kalman filter that describes the heart rate response with respect to different activity levels. It is towards our final goal of intelligent detection of any abnormality in the person’s vital signs. Experimental results are provided to demonstrate the feasibility of the algorithm.*

To summarise the use of Kalman filters to determine context for IoT systems:

- We start with the idea that the sensors we will use can generate fragments of context information with varying degrees of confidence that feed into the overall context estimation of the state. These sensor outputs often have overlaps and conflicts, sensors are highly distributed and their individual performance varies.
- Sensed information from individual sensors will include the sensor’s confidence level and it’s timestamp.
- The Kalman filter averages a prediction of a system’s state with a new measurement using a weighted average. Values with smaller estimated uncertainty are trusted more. The relative weights between the sensor inputs and their impact on the overall state are calculated using covariance. This gives a new state of the system.
- This process is repeated every time step, with the new estimate and its covariance informing the prediction used in the following iteration.
- Because this operation is recursive, it only requires the last estimate(not the historical values)

Thus, the general problem arising in all these cases is : how to combine diverse and uncertain measurements and other information available in a multi-sensor system to accurately and dynamically understand the physical world. Kalman filters can achieve this aim as above. Note that there are other methods such as **Dempster – Shafer** theory can also be used in Sensor fusion.

An example of the use of Kalman filters in fusing accelerometer, gyroscope, and magnetometer data to deliver accurate and reliable motion-sensing information Image source: ST Microsystems via digikey

This paper is created as part of the **Data Science for IoT practitioners course**** starting on Nov 17**. We welcome comments and feedback at ajit.jaokar at futuretext.com. Please email us at **info at futuretext.com** if you want to join the Data Science for IoT practitioners course.

Many thanks to Dr Gary Butler – founder and CEO of Camgian Microsystems and Karthik Padmanabhan – manager Smart mobility at Ford Motor Company for their comments.

**References**

http://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/

http://www.cs.cmu.edu/~whd/publications/1076-Siegel.pdf

http://www.cs.cmu.edu/~whd/publications/7179.pdf

https://www-sigproc.eng.cam.ac.uk/foswiki/pub/Main/OP205/mphil.pdf

http://biorobotics.ri.cmu.edu/papers/sbp_papers/integrated3/kleeman_kalman_basics.pdf

http://www.onera.fr/sites/default/files/u523/C086-Dezert-SPIE2013Baltimore.pdf

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=SystemModeling

http://www.electrical4u.com/state-space-analysis-of-control-system/

http://web.mit.edu/2.14/www/Handouts/StateSpace.pdf https://www.udacity.com/wiki/cs373/unit-2

**Related:**