script zover
Dependencies: HIDScope MODSERIAL mbed
main.cpp
- Committer:
- wiesdat
- Date:
- 2014-10-22
- Revision:
- 11:91d827c62a50
- Parent:
- 9:cc60d28643cb
- Child:
- 12:8604a4c1c708
File content as of revision 11:91d827c62a50:
#include "mbed.h" #include "MODSERIAL.h" #include "HIDScope.h" #include <iostream> #define A1LP1 0.018180963222803 #define A0LP1 0.016544013176248 #define B1LP1 -1.718913340044714 #define B0LP1 0.753638316443765 #define A1HP1 -1.999801878951505 #define A0HP1 0.999801878951505 #define B1HP1 -1.971717601075000 #define B0HP1 0.972111984032897 #define A0N 0.99436777112 #define A1N -1.89139989664 #define A2N 0.99436777112 #define B1N 1.89070035439 #define B2N -0.988036 #define TSAMP 0.001 AnalogIn emg1(PTB1); MODSERIAL pc(USBTX,USBRX); HIDScope scope(5); Ticker timer; float emg_value1, ylp1, yhp1, yn1; volatile bool looptimerflag; float ysum1 = 0, yave1=0 ; float readEMG() { emg_value1=emg1.read(); return emg_value1; } float notchfilter1(float ylp1) { static float yn1,x1=0,x2=0,y1=0,y2=0,x; x = ylp1; yn1 = A0N*x + A1N*x1+A2N*x2+B1N*y1+B2N*y2; x2 = x1; x1 = x; y2 = y1; y1 = yn1; return yn1; } float hpfilter1(float yn1) { static float x1=0,y1=0,x2=0, y2=0,x; x = yn1; yhp1 = x + A1HP1*x1 + A0HP1*x2 - B1HP1*y1 - B0HP1*y2; x2 = x1; x1 = x; y2 = y1; y1 = yhp1; return yhp1; } float lpfilter1(float yhp1) { static float x1=0,y1=0,x2=0, y2=0,x; x = yhp1; ylp1 = A1LP1*x1-B1LP1*y1+A0LP1*x2-B0LP1*y2; x2 = x1; x1 = x; y2 = y1; y1 = ylp1; return ylp1; } void viewer() { scope.set(0,emg_value1); scope.set(1,yn1); scope.set(2,yhp1); scope.set(3,ylp1); scope.set(4,yave1); scope.send(); } void setlooptimerflag(void) { looptimerflag = true; } int main() { pc.baud(115200); timer.attach(setlooptimerflag,TSAMP); int n = 0; while(1) { while(!looptimerflag) /* do nothing */; looptimerflag = false; emg_value1 = readEMG(); yn1 = notchfilter1(emg_value1); yhp1 = hpfilter1(yn1); //function hpfilter ylp1 = lpfilter1(yhp1); //function filter ysum1 = ysum1+sqrt(ylp1*ylp1); n++; if(n==100) { yave1 = abs(ysum1/100); ysum1 = 0; n = 0; } viewer(); //functie hidscope } }