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
SimpleFilter.cpp@0:ac15e38daeb5, 2011-04-20 (annotated)
- Committer:
- shimniok
- Date:
- Wed Apr 20 08:00:25 2011 +0000
- Revision:
- 0:ac15e38daeb5
- Child:
- 1:70348515ed2f
Initial release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:ac15e38daeb5 | 1 | #include "SimpleFilter.h" |
shimniok | 0:ac15e38daeb5 | 2 | |
shimniok | 0:ac15e38daeb5 | 3 | SimpleFilter::SimpleFilter(short shift): _filter_value(0), _shift(shift) { |
shimniok | 0:ac15e38daeb5 | 4 | // nothing to do here, really |
shimniok | 0:ac15e38daeb5 | 5 | } |
shimniok | 0:ac15e38daeb5 | 6 | |
shimniok | 0:ac15e38daeb5 | 7 | short SimpleFilter::filter(short value) { |
shimniok | 0:ac15e38daeb5 | 8 | |
shimniok | 0:ac15e38daeb5 | 9 | _filter_value += value - (_filter_value >> _shift); |
shimniok | 0:ac15e38daeb5 | 10 | _filter_value >>= _shift; |
shimniok | 0:ac15e38daeb5 | 11 | |
shimniok | 0:ac15e38daeb5 | 12 | return _filter_value; |
shimniok | 0:ac15e38daeb5 | 13 | } |