Chris Verhoeven / Mbed 2 deprecated Filter

Dependencies:   HIDScope MODSERIAL biquadFilter mbed

Fork of Filter by Rick Koetsier

Revision:
8:237b1e262ebd
Parent:
7:7c6a9bb2d30e
Child:
9:76bc987121d3
--- a/Calibrationscript.cpp	Wed Nov 01 13:36:54 2017 +0000
+++ b/Calibrationscript.cpp	Wed Nov 01 14:54:24 2017 +0000
@@ -34,9 +34,9 @@
 
 //Define filters and define the floats which contains the values.
 BiQuadChain bqc;
-BiQuad bq1_low(0.00182, 0.0036417, 0.0018208, -1.8764998, 0.883783);
-BiQuad bq2_high( 0.973868, -1.947737,   0.97386, -1.947737, 0.948429);
-BiQuad bq3_notch(0.91859, -1.82269, 0.91859, -1.82269, 0.83718);
+BiQuad bq2_high(0.875182, -1.750364, 0.87518, -1.73472, 0.766004);
+BiQuad bq3_notch(-1.1978e-16, 0.9561, 0.9780, -1.1978e-16, 0.9780);
+BiQuad bq1_low(3.65747e-2, 7.31495e-2, 3.65747e-2, -1.390892, 0.537191);
 
 
 
@@ -97,7 +97,7 @@
         emgFiltered_l = bqc.step( emg_value_l );
         filteredAbs_l = abs( emgFiltered_l );
     if (avg_emg_l != 0){
-        onoffsignal_l=filteredAbs_l/avg_emg_l;             //divide the emg_r signal by the max emg_r to calibrate the signal per person
+        onoffsignal_l=filteredAbs_l/avg_emg_l;             //divide the emg_r signal by the avg_emg_l wat staat voor avg emg in gespannen toestand
       }
  
     }
@@ -109,23 +109,23 @@
 void check_emg_r(){           
 double filteredAbs_temp_r;
           
-    if(check_calibration_r==1){ 
-    for( int i = 0; i<1000;i++){
+    if((check_calibration_l==1) &&(check_calibration_r==1)){ 
+    for( int i = 0; i<500;i++){
                filter_r();
                filteredAbs_temp_r = filteredAbs_temp_r + onoffsignal_r;
                wait(0.0004);
                }    
-               filteredAbs_temp_r = filteredAbs_temp_r/1000;                                 
-            if(filteredAbs_temp_r<=0.55){                         //if signal is lower then 0.5 the blue light goes on
+               filteredAbs_temp_r = filteredAbs_temp_r/500;                                 
+            if(filteredAbs_temp_r<=0.3){                         //if signal is lower then 0.5 the blue light goes on
                  led1.write(1);          //led 1 is rood en uit
-                    led2.write(0);          //led 2 is blauw en aan
+                    
                     rechterarm_positief_r = false;
                     rechterarm_negatief_r = true;
                    
             }
-            else if(filteredAbs_temp_r > 0.55){                //if signal does not pass threshold value, blue light goes on
+            else if(filteredAbs_temp_r > 0.3){                //if signal does not pass threshold value, blue light goes on
                     led1.write(0);
-                    led2.write(1);
+                    
                     rechterarm_negatief_r = false;
                     rechterarm_positief_r = true;
             }
@@ -138,23 +138,23 @@
 void check_emg_l(){           
 double filteredAbs_temp_l;
           
-    if(check_calibration_l==1){ 
-    for( int i = 0; i<1000;i++){
+    if((check_calibration_l)==1 &&(check_calibration_r==1) ){ 
+    for( int i = 0; i<500;i++){
                filter_l();
                filteredAbs_temp_l = filteredAbs_temp_l + onoffsignal_l;
                wait(0.0004);
                }    
-               filteredAbs_temp_l = filteredAbs_temp_l/1000;                                 
-            if(filteredAbs_temp_l<=0.55){                         //if signal is lower then 0.5 the blue light goes on
-                 led1.write(1);          //led 1 is rood en uit
-                    led2.write(0);          //led 2 is blauw en aan
+               filteredAbs_temp_l = filteredAbs_temp_l/500;                                 
+            if(filteredAbs_temp_l<=0.3){                         //if signal is lower then 0.5 the blue light goes on
+             //    led1.write(1);          //led 1 is rood en uit
+                   led2.write(1);          //led 2 is blauw en aan
                     linkerarm_positief_l = false;
                     linkerarm_negatief_l = true;
                    
             }
-            else if(filteredAbs_temp_l > 0.55){                //if signal does not pass threshold value, blue light goes on
-                    led1.write(0);
-                    led2.write(1);
+            else if(filteredAbs_temp_l > 0.3){                //if signal does not pass threshold value, blue light goes on
+                 //   led1.write(0);
+                   led2.write(0);
                     linkerarm_negatief_l = false;
                     linkerarm_positief_l = true;
             }
@@ -194,6 +194,7 @@
             }  
           
              led3.write(1);
+                 pc.printf("calibratie rechts compleet\n\r");
            // double lengte_array = sizeof(signal_verzameling);
       //     pc.printf("lengte_array = %f\n\r",lengte_array);
             
@@ -209,7 +210,7 @@
         
         
         check_calibration_r=1;
-        led3.write(1);
+        
    // }
     return 0;  
 }
@@ -244,11 +245,8 @@
                   }
             }  
           
-             led3.write(1);
-           // double lengte_array = sizeof(signal_verzameling);
-      //     pc.printf("lengte_array = %f\n\r",lengte_array);
             
-        //    for(int i = 0; i < lengte_array; i++){
+        
       
      
       //    sum_array = sum_array + signal_verzameling[i] ;
@@ -261,6 +259,7 @@
         
         check_calibration_l=1;
         led3.write(1);
+        pc.printf("calibratie links compleet\n\r");
    // }
     return 0;  
 }