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:
- 1:75f61e111ed0
- Parent:
- 0:674026fdd982
- Child:
- 2:ce5ead27b7cc
--- a/main.cpp Fri Sep 18 12:36:54 2015 +0000 +++ b/main.cpp Fri Sep 18 13:31:04 2015 +0000 @@ -4,7 +4,20 @@ // Define the HIDScope and Ticker object HIDScope scope(1); 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; +//b0 = 0.02008333102602092 ,b1 = 0.04016666205204184 ,b2 = 0.02008333102602092, a1 = -1.5610153912536877 ,a2 = 0.6413487153577715; + + +void computeBiquad(){ + double v = u - a1*v1 - a2*v2; + y= b0*v + b1*v1 +b2*v2; + v2=v1; + v1=v; +} // Read the analog input AnalogIn an_in(A0); AnalogOut an_out(DAC0_OUT); @@ -19,15 +32,19 @@ { // Attach the data read and send function at 100 Hz scopeTimer.attach_us(&scopeSend, 1e4); + //biquadTicker.attach(&computeBiquad,0.01f); float i = 1; while(1) { // sinewave output - // for (int i = 1; i < 360; i++) { - - float func = 0.5 + 0.5*sin(i); + float u = 0.5 + 0.5*sin(i); + double v = u - a1*v1 - a2*v2; + y= b0*v + b1*v1 +b2*v2; + v2=v1; + v1=v; + i = i+0.01; - an_out = func; - wait(0.001); - // } + an_out = y; + wait(0.01); + } } \ No newline at end of file