Monday, June 3, 2013

Filtering techniques



Hi : ) today a very short entry about filtering. Most of information will be given from external sources. 
At first Kalman filter:
Fig. 1. Principle of Kalman operation

It is very sophisticated method for estimation of measured values. But, it works perfectly, like no other filter. Every kind of measurement has some accuracy error; additionally during measure occurs some noisy (mainly in electronic measuring equipment). We can mention that also our measurement device perturb measurement process. All of those factors cause inaccuracy of our measurement. We have to deal with (sometimes) huge differences between real and measure value. If we want to minimize this factor, we have to use some estimation/approximation methods, so-called filtering techniques. One of them is Kalman filter. It is  so-called linear quadratic estimation (LQE), and an algorithm uses a series of measurements observed over time, containing noise (random variations) and other inaccuracies, and produces estimates of unknown variables that tend to be more precise than those based on a single measurement alone. More formally, the Kalman filter operates recursively on streams of noisy input data to produce a statistically optimal estimate of the underlying system state. The filter is named for Rudolf (Rudy) E. Kálmán, one of the primary developers of its theory.
All of theory of Kalman filter is very mathematically complicated, and till now we don’t understand it : ) but we will work at it ; ) more information in references.

Complementary filter
Complementary filter bases in simplest way of two filters connected in parallel: low-pass filter and high-pass filter:
Fig. 2. Principle of Complementary filter

Mathematical description is as following: The complementary filter is a frequency domain filter. In its strictest sense, the definition of a complementary filter refers to the use of two or more transfer functions, which are mathematical  complements of one another. Thus, if the data from one sensor is operated on by G(s), then the data from the other sensor is operated on by I-G(s), and the sum of the transfer functions is I, the identity matrix. In the case of a one-dimensional filter as will be described in this paper, the identity matrix reduces to the scalar  number  one.
In a typical two -input system, one input will provide information with high frequency noise, and is thus low -pass filtered. The other input provides information with low frequency noise, and is high-pass filtered. If the low -pass and high-pass filters are mathematical complements, then the output of the filter is the complete reconstruction of the variable being sensed, minus the noise associated with the sensors.

Unfortunately, theory of complementary filters is not described well; so I have to reference into some Internet links. 

However, how co connect measurements from gyroscope and accelerometer, and then try to find original (real) value?

At first, we have to assume as following:


Then, we have to think how to estimate our values (now, more or less, they are in the same units ; ) )
We can use here some model to interpret such a situation:

It is possible to implement Kalman filter as following:

But it needs more time to spend on it. Much easier to implement complementary filter:

And short explanation:

At the end, our results. We implement exactly like above, complementary filter (the same coefficient, at the beginning). Results are shown below. In first chart – accelerometer measurement, below gyroscope and at the bottom – filtered values. It’s everything for today : )

References:
1. http://www.cs.unc.edu/~welch/kalman/
2. http://bilgin.esme.org/BitsBytes/KalmanFilterforDummies.aspx
3. http://www.glassercommunications.com/paul/samples/filters_for_fusion.pdf
4. http://robottini.altervista.org/kalman-filter-vs-complementary-filter

And the main source:

web.mit.edu/scolton/www/filter.pdf