BioRobotics Group 3 / Mbed 2 deprecated Moving-average

Dependencies:   HIDScope MODSERIAL mbed

Fork of Signal Filter by BioRobotics Group 3

main.cpp

Committer:
Peasofcake
Date:
2015-09-21
Revision:
4:d6a3b318c744
Parent:
3:04f3cca82b22
Child:
5:ba1679ff9951

File content as of revision 4:d6a3b318c744:

#include "mbed.h"
#include "MODSERIAL.h"
#include "math.h"
#include "HIDScope.h"


AnalogIn EMG(A0);
MODSERIAL pc(USBTX, USBRX);

//const int baudrate = 115200;
//const int ms_wait = 100;

// Define the HIDScope and Ticker objects
HIDScope    scope(1);
Ticker scopeTimer;
// Define the storage variables and filter coeicients for two filters


 // Define the storage variables and filter coeicients for two filters
 double f1_v1 = 0, f1_v2 = 0, f2_v1 = 0, f2_v2 = 0;
 const double f1_a1 =  0.25071442433, f1_a2 = 0.21711875780, f1_b0 = 1.0, f1_b1 = -1.62432585007, f1_b2 = 1.0;
 const double f2_a1 = -1.77682226139, f2_a2 = 0.80213897411, f2_b0 = 1.0, f2_b1 =  -1.62432585007, f2_b2 = 1.0;

 double biquad( double u, double &v1, double &v2, const double a1, const double a2, const double b0, const double b1, const double b2 )
 {
 double v = u-a1*v1-a2*v2;
 double y = b0*v + b1*v1 + b2*v2;
 v2 = v1; v1 = v;
 return y;
 }

 // This is your controller, call it using a Ticker
// void myController() {
 //double u1 = EMG, u2 = y1 ;
 //double y1 = biquad( u1, f1_v1, f1_v2, f1_a1, f1_a2, f1_b0, f1_b1, f1_b2 );
 //double y2 = biquad( u2, f2_v1, f2_v2, f2_a1, f2_a2, f2_b0, f2_b1, f2_b2 );
 //}




void scopeSend(){
 double u1 = EMG  ;
 double y1 = biquad( u1, f1_v1, f1_v2, f1_a1, f1_a2, f1_b0, f1_b1, f1_b2 );
 double u2 = y1;
 double y2 = biquad( u2, f2_v1, f2_v2, f2_a1, f2_a2, f2_b0, f2_b1, f2_b2 );   
scope.set(0,y2);
scope.send();
 }
 
int main()
{
    scopeTimer.attach_us(&scopeSend,1e4);
     while(1){}
        
}