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 16:57:54 2011 +0000
Parent:
0:ac15e38daeb5
Commit message:
Fixed major implementation bug. I am an idiot. :)

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
--- a/SimpleFilter.cpp	Wed Apr 20 08:00:25 2011 +0000
+++ b/SimpleFilter.cpp	Wed Apr 20 16:57:54 2011 +0000
@@ -6,8 +6,11 @@
 
 short SimpleFilter::filter(short value) {
 
-    _filter_value += value - (_filter_value >> _shift);
-    _filter_value >>= _shift;
+    _filter_value += (value - (_filter_value >> _shift));
     
-    return _filter_value;
-}
\ No newline at end of file
+    return _filter_value >> _shift;
+}
+
+short SimpleFilter::value(void) {
+    return _filter_value >> _shift;
+}
--- a/SimpleFilter.h	Wed Apr 20 08:00:25 2011 +0000
+++ b/SimpleFilter.h	Wed Apr 20 16:57:54 2011 +0000
@@ -21,6 +21,18 @@
      */
     short filter(short value);
 
+    /** Read the current value in the filter
+     *
+     * @returns the current value in the filter
+     */
+    short value(void);
+
+    /** Shorthand operator for value()
+     *
+     * @returns the current value in the filter
+     */
+    operator short() { return value(); }
+
 private:
     long _filter_value;
     short _shift;