Kalman Filter Commonly Used to Stabilize Sensor Readings. The Kalman filter reduces the errors of raw measurements, provides estimates for quantities. The Kalman filter is widely used in robotics, navigation, GPS, biomedical, electronic control circuits of ubiquitous communication systems such as radio and computer. It is a mathematical model which can be applied as a snippet. The Kalman filter is an efficient recursive filter that estimates the internal state of a linear dynamic system from a series of noisy measurements, like noise we had seen with Arduino ECG module. Often for complex sensors to detect position in 3D space, data from multiple sensors do not create a smooth “curve”. Kalman Filter results smoothness not only of graphs but also of the remote controlled vehicles.
The prerequisite is that the values of interest can be described by a mathematical model, for example in the form of equations of motion. The peculiarity of the filter introduced by Kálmán in 1960 is its special mathematical structure, which enables its use in real-time systems of various technical fields. Mathematical estimation theory is also called a Bayesian minimum-variance estimator for linear stochastic systems in state space representation. In engineering, the Kalman filter is also referred to as the optimal filter for linear stochastic systems.
During the 60s there were also more general, non-linear filters by Ruslan L. Stratonovich (who included the Kalman filter and other linear filters). The first significant and successful use of the filter was in real-time navigation and guidance systems developed as part of NASA’s Apollo program. There is now a wide range of Kalman filters for a wide variety of applications. In addition to the original formulation, these are the Advanced Kalman Filters. The most widely used variant, however, is the phase control loop originating from the control theory, an essential component of most modern means of communication.
---
The algorithm works in a two-step process – (i) Prediction and (ii) Estimation.
In the prediction step, the filter produces estimates of the current state, along with their error probabilities. At the beginning, initial conditions are used. Once the next raw sensor reading is entered to the filter, these estimates are updated using a weighted average of the raw readings, with more weight being given to estimates with higher certainty.
Commonly the equations appear scary to the unused. They are not dangerous. “k” represents the present state and “k-1” represents the previous state. X(k) denotes current position, X(k-1) denotes previous position. u(k) represents the previous velocity and the acceleration, B(k) represents the directions, F(k) represents the orientation, w(k) is used to indicate the unknown forces like friction.
If we know the previous position of an object, velocity, and the acceleration then you can calculate the position of that object after a known time using the following equation :
S = ut + 0.5at^2
After estimating the current position now we can compare with the physical sensor data. That is how we can remove the noises and errors from raw sensor data.
Using Kalman Filter With Arduino
There are many libraries. Kalman Filter can be for one variable of multiple variables. Here is an easy, one variable :
1 2 3 | # https://github.com/nut-code-monkey/KalmanFilter-for-Arduino # |
Usage will be like this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include "KalmanFilter.h" KalmanFilter kalmanFilter; double getSomeValue() { // return values in range 0..1023 return analogRead(A0); } void setup() { kalmanFilter.setState( getSomeValue() ); // kalmanFilter.setCovariance(0.1); // optional Serial.begin(9600); } void loop() { double value = getSomeValue(); kalmanFilter.correct(value); double correctedValue = kalmanFilter.getState(); Serial.print(value); Serial.print(" | "); Serial.println(correctedValue); } |
This is another library, which is for complex 3D space orientation :
1 2 3 4 5 | # https://github.com/TKJElectronics/KalmanFilter # |