For BIOROBOTICS PROJECT

Dependencies:   HIDScope MODSERIAL QEI mbed

Revision:
1:3bae5ab25e20
Parent:
0:8ccd4c66e07f
Child:
2:ac98d055a6cd
--- a/main.cpp	Wed Oct 07 20:52:18 2015 +0000
+++ b/main.cpp	Wed Oct 21 12:31:55 2015 +0000
@@ -1,21 +1,21 @@
 #include "mbed.h"
 #include "HIDScope.h"
 #include "QEI.h"
-AnalogIn    emg(A0)
-HIDScope scope(1);
+AnalogIn    emg(A0);
+HIDScope scope(5);
 Ticker get;
 AnalogIn pot(A1);
 Serial pc(USBTX, USBRX); // tx, rx
-
+const int N = 10;
 volatile bool fn_go = false;
 double y_notch_1;
 double y_notch_2;
 double y_high;
 double y_low;
-
+double y_rect;
 const double Fs = 500;
 const double Ts = 0.002;
-
+double a;
 const double gain_notch_1 = 0.912483;
 const double b0_notch_1 = 1.0*gain_notch_1;
 const double b1_notch_1 = -1.62829098849*gain_notch_1;
@@ -33,20 +33,20 @@
 const double a2_notch_2 =  0.91813588764;
 double v1_notch_2 = 0, v2_notch_2 = 0;
 
-const double gain_high = 0.956602;
+const double gain_high = 0.981587;
 const double b0_high = 1.0*gain_high;
-const double b1_high = -1.99999962667*gain_high;
+const double b1_high = -1.99999992457*gain_high;
 const double b2_high = 1.0*gain_high;
-const double a1_high = -1.91152224950;
-const double a2_high =  0.91532727281;
+const double a1_high = -1.96306054568;
+const double a2_high =  0.96374056522;
 double v1_high = 0, v2_high = 0;
 
-const double gain_low = 0.003428;
+const double gain_low = 0.000561;
 const double b0_low = 1.0*gain_low;
-const double b1_low = 2.00000000000*gain_low;
+const double b1_low = 2.000*gain_low;
 const double b2_low = 1.0*gain_low;
-const double a1_low = -1.86528269522;
-const double a2_low =  0.87380140464;
+const double a1_low =   -1.93191036285;
+const double a2_low =   0.93415335760;
 double v1_low = 0, v2_low = 0;
 
 
@@ -65,14 +65,38 @@
     fn_go = true;
 }
 
+double sliding_average(double u,const int f_N)
+{
+    double f_x[f_N];
+    double f_sum=0;
+    f_x[1]=abs(u);
+    for (int i=f_N; i>=1; i--){
+        f_x[i]=f_x[i-1];
+        }
+        
+      
+    for (int i=f_N; i>=0; i--){
+        f_sum=f_x[i]+f_sum;
+       }
+        a=f_sum/double(f_N);
+        f_sum=0;
+    return a;
+}
+double z1;
 void scopeSend()
 {
   y_high = biquad(emg.read(), v1_high, v1_high, a1_high, a2_high, b0_high, b1_high, b2_high); 
   y_notch_1 = biquad(y_high, v1_notch_1, v1_notch_1, a1_notch_1,a2_notch_1,b0_notch_1, b1_notch_1, b2_notch_1);
-           y_notch_2 = biquad(y_notch_1, v1_notch_2, v1_notch_2, a1_notch_2, a2_notch_2, b0_notch_2, b1_notch_2, b2_notch_2);  
-               
-            y_low = biquad(y_high,  v1_low, v1_low, a1_low, a2_low, b0_low, b1_low, b2_low);
-  scope.set(0,y_low);
+    y_notch_2 = biquad(y_notch_1, v1_notch_2, v1_notch_2, a1_notch_2, a2_notch_2, b0_notch_2, b1_notch_2, b2_notch_2);  
+  y_rect = fabs(y_notch_2);             
+            y_low = biquad(y_rect,  v1_low, v1_low, a1_low, a2_low, b0_low, b1_low, b2_low);
+// z1 = 6*sliding_average(emg.read(), N); //moving average
+scope.set(0,emg.read());
+scope.set(1,y_high);
+  scope.set(2,y_rect);
+  scope.set(3,y_low);
+ // scope.set(4,z1);
+
     scope.send();
 }