Emg filter function script for a uni project. Made by Teun van der Molen
Dependencies: HIDScope MODSERIAL mbed
Fork of frdm_EMG by
Diff: main.cpp
- Revision:
- 4:1baefd1397d6
- Parent:
- 3:499c71ca30a0
- Child:
- 5:56725d9362ee
--- a/main.cpp Mon Sep 21 09:37:43 2015 +0000 +++ b/main.cpp Mon Sep 21 09:57:12 2015 +0000 @@ -2,18 +2,18 @@ #include "HIDScope.h" #include "math.h" // Define the HIDScope and Ticker object -HIDScope scope(2); +HIDScope scope(3); Ticker scopeTimer; Ticker biquadTicker; -double v1=0, v2=0, u=0, y=0; -const double -//b0 = 0.9999999999999999,b1 = 1.9999999999999998,b2 = 0.9999999999999999, a1 = 1.9999999999999998 ,a2 = 0.9999999999999998; //low-pass Fc = 50hz -//b0 = 0.02008333102602092 ,b1 = 0.04016666205204184 ,b2 = 0.02008333102602092, a1 = -1.5610153912536877 ,a2 = 0.6413487153577715; //low-pass Fc = 5hz -//b0 = 0.8005910266528649,b1 = -1.6011820533057297,b2 = 0.8005910266528649,a1 = -1.5610153912536877,a2 = 0.6413487153577715; //high-pass Fc = 5hz -b0 = 0.007820199259120319,b1 = 0.015640398518240638,b2 = 0.007820199259120319,a1 = -1.7347238224240125,a2 = 0.7660046194604936; //low-pass Fc = 3hz -//b0 = 0.0009446914586925257,b1 = 0.0018893829173850514,b2 = 0.0009446914586925257,a1 = -1.911196288237583,a2 = 0.914975054072353; //low-pass Fc = 1hz +double v1=0, v2=0, u=0, y=0, fy=0, fv1=0, fv2=0, fu=0; +//const double b0 = 0.9999999999999999,b1 = 1.9999999999999998,b2 = 0.9999999999999999, a1 = 1.9999999999999998 ,a2 = 0.9999999999999998; //low-pass Fc = 50hz +const double fb0 = 0.02008333102602092 ,fb1 = 0.04016666205204184 ,fb2 = 0.02008333102602092, fa1 = -1.5610153912536877 ,fa2 = 0.6413487153577715; //low-pass Fc = 5hz +//const double b0 = 0.8005910266528649,b1 = -1.6011820533057297,b2 = 0.8005910266528649,a1 = -1.5610153912536877,a2 = 0.6413487153577715; //high-pass Fc = 5hz +//const double b0 = 0.007820199259120319,b1 = 0.015640398518240638,b2 = 0.007820199259120319,a1 = -1.7347238224240125,a2 = 0.7660046194604936; //low-pass Fc = 3hz +//const double b0 = 0.0009446914586925257,b1 = 0.0018893829173850514,b2 = 0.0009446914586925257,a1 = -1.911196288237583,a2 = 0.914975054072353; //low-pass Fc = 1hz +const double b0 = 0.956542835577484, b1 = -1.913085671154968, b2 = 0.956542835577484, a1 = -1.911196288237583, a2 = 0.914975054072353; //high-pass Fc = 1hz @@ -27,7 +27,8 @@ void scopeSend() { scope.set(0,y); - scope.set(1,an_in); + scope.set(1,fy); + scope.set(2,an_in); scope.send(); } @@ -37,6 +38,11 @@ y= b0*v + b1*v1 +b2*v2; v2=v1; v1=v; + + double fv = y - fa1*fv1 - fa2*fv2; + fy= fb0*fv + fb1*fv1 + fb2*fv2; + fv2=fv1; + fv1=fv; } @@ -47,12 +53,6 @@ biquadTicker.attach(&computeBiquad,0.01f); //float i = 1; while(1) { - // sinewave output - // float u = (0.25 + 0.1*sin(i) + (0.25 + 0.1*sin(100*i))); - - // i = i+0.01; - // an_out = y; - // wait(0.01); - // double an_in = y; + } } \ No newline at end of file