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

Files at this revision

API Documentation at this revision

Comitter:
shimniok
Date:
Wed Apr 20 08:00:25 2011 +0000
Child:
1:70348515ed2f
Commit message:
Initial release

Changed in this revision

SimpleFilter.cpp Show annotated file Show diff for this revision Revisions of this file
SimpleFilter.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleFilter.cpp	Wed Apr 20 08:00:25 2011 +0000
@@ -0,0 +1,13 @@
+#include "SimpleFilter.h"
+
+SimpleFilter::SimpleFilter(short shift): _filter_value(0), _shift(shift) {
+    // nothing to do here, really
+}
+
+short SimpleFilter::filter(short value) {
+
+    _filter_value += value - (_filter_value >> _shift);
+    _filter_value >>= _shift;
+    
+    return _filter_value;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleFilter.h	Wed Apr 20 08:00:25 2011 +0000
@@ -0,0 +1,27 @@
+/** SimpleFilter implements a simple low pass integer "leaky integrator" described here:
+ * 
+ * http://ece124web.groups.et.byu.net/references/readings/Simple%20Software%20Lowpass%20Filter.pdf
+ *
+ * Well suited for filtering ADC integer values very quickly
+ *
+ * Michael Shimniok http://bot-thoughts.com/
+ */
+class SimpleFilter {
+public:
+    /** Creates a new filter object
+     *
+     * @param shift: the number of shifts to perform at each filtering input step; lower means higher bandwidth
+     */
+    SimpleFilter(short shift);
+
+    /** Supplies input to the filter and returns filtered output value
+     *
+     * @param value is the input value to the filter, e.g., some measurement
+     * @returns the filtered output value
+     */
+    short filter(short value);
+
+private:
+    long _filter_value;
+    short _shift;
+};
\ No newline at end of file