Working with all filters, all filter results are low amplitude.

Dependencies:   HIDScope biquadFilter mbed

Fork of frdm_calibratie_maximum by Marieke M

Revision:
1:278677bb6b99
Parent:
0:4d69864f1002
Child:
2:27081b83a58e
diff -r 4d69864f1002 -r 278677bb6b99 main.cpp
--- a/main.cpp	Thu Oct 20 20:44:51 2016 +0000
+++ b/main.cpp	Fri Oct 21 10:15:43 2016 +0000
@@ -58,11 +58,16 @@
 
 volatile int time_passed = 0;
 volatile bool filter_timer_go=false;
+
+double EMGright;
+double EMGleft;
 //average_timer_go=false,
  // Activates go-flags
 //void average_timer_act(){average_timer_go=true;};
 /*void filter_timer_act(){filter_timer_go=true;};
 
+
+
 BiQuadChain bcq;
 // Notch filter wo=50; bw=wo/35
 BiQuad bq1(9.7805e-01,-1.1978e-16,9.7805e-01,1.0000e+00,-1.1978e-16,9.5610e-01);
@@ -79,9 +84,11 @@
     time_passed++;
 }
 
-/*void sample()
+void sample()
 {
-    scope.set(0, emg0.read() );
+    double EMGright = emg0;
+    double EMGleft = emg1;
+    /*.set(0, emg0.read() );
     scope.set(1, emg1.read() );
     
     scope.send();
@@ -89,8 +96,8 @@
     led1 = 0;
     wait(0.5f);
     led1 = 1;
-    wait(0.5f);
-}*/
+    wait(0.5f);*/
+}
 
 // In the following: R is used for right arm, L is used for left arm!
 /*void FilteredSample()
@@ -144,14 +151,14 @@
     return averageR=sumR/sizeR;
     return averageL(sumL,sizeL);*/
     
-double averageR(int sumR, int size)
+float averageR(int sumR, int size)
 {
-    return (double) sumR/size;
+    return (float) sumR/size;
 }
 
-double averageL(int sumL, int size)
+float averageL(int sumL, int size)
 {
-    return (double) sumL/size;
+    return (float) sumL/size;
 }
 
 
@@ -162,36 +169,52 @@
     led2=1;
     t.attach(&KeepTrackOfTime,1.0); //taking the time in seconds
 
-    for (;;) {
-        if (time_passed<=30) 
-        {
-        led1 =!led1;
-        wait(0.5f);//sample_timer.attach(&sample, 0.002); //500Hz
+    //for (;;) {
+        //if (time_passed<=10) 
+        //{
+        //sample_timer.attach(&sample, 0.002); //500Hz
         
-        double averageR(int,int);
-        double averageL(int,int);
+        /*float averageR(float,int);
+        float averageL(float,int);
         int size = 500; //10/0.002
         int arrayR[size]; //declaring array
         int arrayL[size];
         int sumR = 0;
         int sumL = 0;
-        double EMGright = emg0.read();
-        double EMGleft = emg1.read();
+        float EMGright = emg0.read();
+        float EMGleft = emg1.read();
         
             for (int i=0;i<size;i++)
             {
-            EMGright = arrayR[i];
-            EMGleft = arrayL[i];
-            sumL = sumL+arrayR[i];
+            emg0.read() = arrayR[i];
+            arrayL[i]= emg1.read();
+            sumL = sumL+arrayL[i];
             sumR = sumR+arrayR[i];
             }
             // Calibration step with the gained averages
             //double CalibrationFactorR = 0.5/averageR(sumR,size);
             //double CalibrationFactorL = 0.5/averageL(sumL,size);
-        double averageEMGr = sumR/size;
-        double averageEMGl = sumL/size;
-        double InRcal = emg0.read()-averageR(sumR,size);
-        double InLcal = emg1.read()-averageL(sumL,size);
+            */
+            int size = 12500;
+            int i; 
+            double EMGsumR;
+            double EMGsumL; 
+            
+            while(i<size){
+            sample();
+            EMGsumR = emg0.read()+EMGsumR;
+            EMGsumL = EMGleft+EMGsumL;
+            i++;
+            wait(0.0004);
+            }
+            
+        double averageEMGr = (double) EMGsumR/size;
+        double averageEMGl = (double) EMGsumL/size;
+        double InRcal = emg0.read()-averageEMGr;
+        double InLcal = emg1.read()-averageEMGl;
+        
+        led1 =!led1;
+        //wait(0.5f);
         
         /*scope.set(0, emg0.read() );
         scope.set(1, 1 );
@@ -201,19 +224,23 @@
         scope.set(6, InLcal );
         
         scope.send();*/
-        pc.printf("EMG-signal = %f\n\r",emg0.read());
+        //pc.printf("EMG-signal = %f\n\r",emg0.read());
         pc.printf("averageR = %f\n\r",averageEMGr);
-        pc.printf("averageRvoid = %f\n\r",averageR(sumR,size));
-        pc.printf("Detrend EMG = %f\n\r",InRcal);
-        }
+        pc.printf("averageR = %f\n\r",averageEMGl);
+        //pc.printf("averageRvoid = %f\n\r",averageR(sumR,size));
+        //pc.printf("Detrend EMG = %f\n\r",InRcal);
+        //pc.printf("array value = %f\n\r",arrayR[3]);
+        pc.printf("test\n\r");
+        pc.printf("EMG sum = %f\n\r",EMGsumR);
+        pc.printf("EMG signal  = %f\n\r",EMGright);
         
-        else
+        /*else
         {
                    
         led1 = 1; 
         led2=!led2;
         
-        /*bcq.add(&bq3).add(&bq4).add(&bq5);
+        bcq.add(&bq3).add(&bq4).add(&bq5);
       
         filter_timer.attach(&filter_timer_act, 0.0004); //2500Hz (same as with filter coefficients on matlab!!! Thus adjust!)
         
@@ -222,8 +249,8 @@
             if (filter_timer_go){
                 filter_timer_go=false;
                 FilteredSample();}
-            }*/
+            }
         
-        }
-}
+        }*/
+
 }
\ No newline at end of file