Implements a simple leaky integrator integer value filter, handy for fast, simple, ADC output filtering. Implemented as described here: [[http://ece124web.groups.et.byu.net/references/readings/Simple%20Software%20Lowpass%20Filter.pdf|Simple Software Lowpass Filter.pdf]]

Dependents:   AVC_20110423 WallBot_Simple AVC_2012

Committer:
shimniok
Date:
Wed Apr 20 16:57:54 2011 +0000
Revision:
1:70348515ed2f
Parent:
0:ac15e38daeb5
Fixed major implementation bug. I am an idiot. :)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:ac15e38daeb5 1 /** SimpleFilter implements a simple low pass integer "leaky integrator" described here:
shimniok 0:ac15e38daeb5 2 *
shimniok 0:ac15e38daeb5 3 * http://ece124web.groups.et.byu.net/references/readings/Simple%20Software%20Lowpass%20Filter.pdf
shimniok 0:ac15e38daeb5 4 *
shimniok 0:ac15e38daeb5 5 * Well suited for filtering ADC integer values very quickly
shimniok 0:ac15e38daeb5 6 *
shimniok 0:ac15e38daeb5 7 * Michael Shimniok http://bot-thoughts.com/
shimniok 0:ac15e38daeb5 8 */
shimniok 0:ac15e38daeb5 9 class SimpleFilter {
shimniok 0:ac15e38daeb5 10 public:
shimniok 0:ac15e38daeb5 11 /** Creates a new filter object
shimniok 0:ac15e38daeb5 12 *
shimniok 0:ac15e38daeb5 13 * @param shift: the number of shifts to perform at each filtering input step; lower means higher bandwidth
shimniok 0:ac15e38daeb5 14 */
shimniok 0:ac15e38daeb5 15 SimpleFilter(short shift);
shimniok 0:ac15e38daeb5 16
shimniok 0:ac15e38daeb5 17 /** Supplies input to the filter and returns filtered output value
shimniok 0:ac15e38daeb5 18 *
shimniok 0:ac15e38daeb5 19 * @param value is the input value to the filter, e.g., some measurement
shimniok 0:ac15e38daeb5 20 * @returns the filtered output value
shimniok 0:ac15e38daeb5 21 */
shimniok 0:ac15e38daeb5 22 short filter(short value);
shimniok 0:ac15e38daeb5 23
shimniok 1:70348515ed2f 24 /** Read the current value in the filter
shimniok 1:70348515ed2f 25 *
shimniok 1:70348515ed2f 26 * @returns the current value in the filter
shimniok 1:70348515ed2f 27 */
shimniok 1:70348515ed2f 28 short value(void);
shimniok 1:70348515ed2f 29
shimniok 1:70348515ed2f 30 /** Shorthand operator for value()
shimniok 1:70348515ed2f 31 *
shimniok 1:70348515ed2f 32 * @returns the current value in the filter
shimniok 1:70348515ed2f 33 */
shimniok 1:70348515ed2f 34 operator short() { return value(); }
shimniok 1:70348515ed2f 35
shimniok 0:ac15e38daeb5 36 private:
shimniok 0:ac15e38daeb5 37 long _filter_value;
shimniok 0:ac15e38daeb5 38 short _shift;
shimniok 0:ac15e38daeb5 39 };