script zover

Dependencies:   HIDScope MODSERIAL mbed

Revision:
13:23130c3a37b1
Parent:
12:8604a4c1c708
Child:
14:4c33f6240118
--- a/main.cpp	Wed Oct 22 10:42:46 2014 +0000
+++ b/main.cpp	Wed Oct 22 10:46:51 2014 +0000
@@ -3,15 +3,15 @@
 #include "HIDScope.h"
 #include <iostream>
 
-#define A1LP1    0.018180963222803
-#define A0LP1     0.016544013176248
-#define B1LP1    -1.718913340044714
-#define B0LP1     0.753638316443765
+#define A1LP    0.018180963222803
+#define A0LP     0.016544013176248
+#define B1LP    -1.718913340044714
+#define B0LP     0.753638316443765
 
-#define A1HP1  -1.999801878951505
-#define A0HP1   0.999801878951505
-#define B1HP1   -1.971717601075000
-#define B0HP1  0.972111984032897
+#define A1HP    -1.999801878951505
+#define A0HP   0.999801878951505
+#define B1HP   -1.971717601075000
+#define B0HP  0.972111984032897
 
 #define A0N 0.99436777112
 #define A1N -1.89139989664
@@ -23,16 +23,19 @@
 
 AnalogIn    emg1(PTB1);
 AnalogIn    emg2(PTB0);
+
 MODSERIAL pc(USBTX,USBRX);
 HIDScope scope(5);
 Ticker timer;
+volatile bool looptimerflag;
+
 float emg_value2, ylp2, yhp2, yn2;
 float emg_value1, ylp1, yhp1, yn1;
-volatile bool looptimerflag;
+
 float ysum1 = 0, yave1=0 ;
 float ysum2 = 0, yave2=0 ;
 
-float readEMG()
+float readEMG1()
 {
 
     emg_value1=emg1.read();
@@ -71,12 +74,11 @@
     return yn1;
 }
 
-
 float hpfilter2(float yn2)
 {
     static float x1=0,y1=0,x2=0, y2=0,x;
     x = yn2;
-    yhp2 = x + A1HP1*x1 + A0HP1*x2 - B1HP1*y1 - B0HP1*y2;
+    yhp2 = x + A1HP*x1 + A0HP*x2 - B1HP*y1 - B0HP*y2;
     x2 = x1;
     x1 = x;
     y2 = y1;
@@ -87,7 +89,7 @@
 {
     static float x1=0,y1=0,x2=0, y2=0,x;
     x = yn1;
-    yhp1 = x + A1HP1*x1 + A0HP1*x2 - B1HP1*y1 - B0HP1*y2;
+    yhp1 = x + A1HP*x1 + A0HP*x2 - B1HP*y1 - B0HP*y2;
     x2 = x1;
     x1 = x;
     y2 = y1;
@@ -99,7 +101,7 @@
 {
     static float x1=0,y1=0,x2=0, y2=0,x;
     x = yhp2;
-    ylp2 = A1LP1*x1-B1LP1*y1+A0LP1*x2-B0LP1*y2;
+    ylp2 = A1LP*x1-B1LP*y1+A0LP*x2-B0LP*y2;
     x2 = x1;
     x1 = x;
     y2 = y1;
@@ -111,7 +113,7 @@
 {
     static float x1=0,y1=0,x2=0, y2=0,x;
     x = yhp1;
-    ylp1 = A1LP1*x1-B1LP1*y1+A0LP1*x2-B0LP1*y2;
+    ylp1 = A1LP*x1-B1LP*y1+A0LP*x2-B0LP*y2;
     x2 = x1;
     x1 = x;
     y2 = y1;
@@ -119,8 +121,6 @@
     return ylp1;
 }
 
-
-
 void viewer()
 {
     scope.set(0,emg_value1);
@@ -146,15 +146,16 @@
     int m = 0;
     while(1) {
 
-        while(!looptimerflag) /* do nothing */;
+        while(!looptimerflag);
         looptimerflag = false;
-        emg_value1 =  readEMG();
+        emg_value1 =  readEMG1();
+        
         yn1 = notchfilter1(emg_value1);
-        yhp1 = hpfilter1(yn1);  //function hpfilter
-        ylp1 = lpfilter1(yhp1);       //function filter
-       
+        yhp1 = hpfilter1(yn1);  
+        ylp1 = lpfilter1(yhp1);      
         ysum1 = ysum1+sqrt(ylp1*ylp1);
         n++;
+        
         if(n==100) {
             yave1 = abs(ysum1/100);
             ysum1 = 0;
@@ -163,9 +164,8 @@
 
         emg_value2 =  readEMG2();
         yn2 = notchfilter2(emg_value2);
-        yhp2 = hpfilter2(yn2);  //function hpfilter
-        ylp2 = lpfilter2(yhp2);       //function filter
-       
+        yhp2 = hpfilter2(yn2);  
+        ylp2 = lpfilter2(yhp2);       
         ysum2 = ysum2 +sqrt(ylp2*ylp2);
         m++;
        
@@ -175,8 +175,6 @@
             m = 0;
             }
 
-         viewer();                  //functie hidscope
-        
-
+         viewer();               
     }
 }
\ No newline at end of file