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 #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 1:70348515ed2f 9 _filter_value += (value - (_filter_value >> _shift));
shimniok 0:ac15e38daeb5 10
shimniok 1:70348515ed2f 11 return _filter_value >> _shift;
shimniok 1:70348515ed2f 12 }
shimniok 1:70348515ed2f 13
shimniok 1:70348515ed2f 14 short SimpleFilter::value(void) {
shimniok 1:70348515ed2f 15 return _filter_value >> _shift;
shimniok 1:70348515ed2f 16 }