Remco Dasselaar / Mbed 2 deprecated TotalControlEmg2

Dependencies:   HIDScope MODSERIAL QEI TextLCD mbed

Fork of TotalControlEmg2 by Remco Dasselaar

Filter.cpp

Committer:
RemcoDas
Date:
2015-10-28
Revision:
50:16314b798754
Parent:
3:344b173f85fe

File content as of revision 50:16314b798754:

#include "Filter.h"
// 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;                            // shift memory
    v1 = v;    
    return y;                           // filtered output
    }