Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope MODSERIAL QEI TextLCD mbed
Fork of TotalControlEmg2 by
Diff: Filter.cpp
- Revision:
- 50:16314b798754
- Parent:
- 3:344b173f85fe
diff -r b571c822c3f9 -r 16314b798754 Filter.cpp
--- a/Filter.cpp Tue Oct 27 12:01:44 2015 +0000
+++ b/Filter.cpp Wed Oct 28 09:28:48 2015 +0000
@@ -1,20 +1,13 @@
#include "Filter.h"
-
-double Filter(double u, double &v1, double &v2, const double a1, const double a2, const double b0, const double b1, const double b2, const double gain){
- // volgens direct form 2, uit de embedded filtering and control sheets van T.J.W. Lankhorst
- // u = ingangssignaal (zonder filter)
- // v = tussentap
- // v1 = v bij u(x-1), dus v van 1 geleden
- // v2 = v bij u(x-2), dus v van 2 geleden
- // a1 en a2 variabele uit ASN filter, a0 =1
- // b0, b1, b2 variabele uit ASN filter
- // y = uitgangssignaal (gefilterd)
-
+// According to Direct form 2, see sheets of T.J.W. Lankhorst
+ // u = input (without filter)
+ // v = memory (by reference
+ // a1 and a2 variabel from ASN filter, a0 =1
+ // b0, b1, b2 variabel from ASN filter
+double Filter(double u, double &v1, double &v2, const double a1, const double a2, const double b0, const double b1, const double b2, const double gain){
double v = u - a1 * v1 - a2 * v2;
- double y = gain * (b0 * v + b1 * v1 + b2 * v2);
-
- v2 = v1; // signalen doorschuiven, zodat bij de volgende input, de vorige waardes van v worden onthouden
- v1 = v;
-
- return y;
+ double y = gain * (b0 * v + b1 * v1 + b2 * v2);
+ v2 = v1; // shift memory
+ v1 = v;
+ return y; // filtered output
}
\ No newline at end of file
