script zover

Dependencies:   HIDScope MODSERIAL mbed

Revision:
3:9a7ed524bb30
Parent:
2:620ff9f02d62
Child:
4:92e5c7220897
diff -r 620ff9f02d62 -r 9a7ed524bb30 main.cpp
--- a/main.cpp	Wed Oct 15 13:35:09 2014 +0000
+++ b/main.cpp	Thu Oct 16 10:55:57 2014 +0000
@@ -10,24 +10,25 @@
 #define B1HP -1.943446330323158
 #define B0HP 0.945001709500376
 
-#define TSAMP 0.0001
+#define TSAMP 0.001
 
 AnalogIn    emg0(PTB1);
 MODSERIAL pc(USBTX,USBRX);
 HIDScope scope(5);
 Ticker timer;
 float filter(float);
-float emg_value;
+float emg_value, ylp1, yhp1;
 volatile bool looptimerflag;
 float ysum = 0, yave=0 ;
 
+
 uint16_t readEMG()
 {
 
     return emg0.read_u16();
 }
 
-float hpfilter(float emg0_value)
+float hpfilter1(float emg0_value)
 {
     static float y,x1=0,y1=0,x2=0,y2=0;
     y = y1*B1HP-y2*B0HP-x1*A1HP+x2*A0HP;
@@ -38,10 +39,10 @@
     return yhp1;
 }
 
-float lpfilter(float yhp1)
+float lpfilter1(float yhp1)
 {
     static float y,x1=0,y1=0,x=0;
-    y = A1LP*x1lp+y1lp*B1LP;
+    y = A1LP*x1+y1*B1LP;
     y1 = y;
     x1 = x;
     x = y;
@@ -51,10 +52,9 @@
 void viewer()
 {
     scope.set(0,emg_value);
-    scope.set(1,yhp);
-    scope.set(2,ylp);
-    scope.set(3,ysum);
-    scope.set(4,yave);
+    scope.set(1,yhp1);
+    scope.set(2,ylp1);
+    scope.set(3,yave);
     scope.send();
 }
 
@@ -72,15 +72,14 @@
 
         while(!looptimerflag) /* do nothing */;
         looptimerflag = false;
-        //read();                     //waardes inladen
         emg_value =  readEMG();
-        yhp1 = hpfilter(emg_value);  //functie hpfilter
-        ylp1 = lpfilter(yhp1);         //functie filter
-        ysum = ysum+abs(ylp);
+        yhp1 = hpfilter1(emg_value);  //function hpfilter
+        ylp1 = lpfilter1(yhp1);       //function filter
+        ysum = ysum+abs(ylp1);
         n++;
 
-        if(n==1000) {
-            yave = ysum/1000;
+        if(n==100) {
+            yave = ysum/100;
             yave = yave;
             ysum = 0;
             n = 0;