Included Filters

To reduce sensor noise!

Median Filter

The median filter works as:

  1. Create list of 'n' size

    • If you would like to alway get the middle value, set n to an odd number

    • If you would like to alway get the average of the two middle most values, set n to an even number

  2. Add data to array

  3. Remove oldest data if array size is > n

  4. Sort the array in ascending order

  5. Calculate the statistical median

Due the the properties of this filter, it will return the 'middle' value of the window and ignore values too high or too low.

medianFilter = MedianFilter(5)
mf.push(sensorMeasurment)
filteredDistance = mf.median()

Low Pass Filter

The low pass filter is another filter included in this library, it is a basic algorithm that smooths values given to it.

By adjusting the gain, this filter can be tuned. When gain values increase, each new measurement has a greater influence on the estimate than when gain values are smaller. Iteratively, this process updates the estimate at each timestamp. You must have a gain value between 0 and 1!

lowPassFilter = LowPassFilter(0.5)
filteredDistance = lp.estimate(sensorMeasurment)

Last updated