emg

Dependencies:   HIDScope MODSERIAL mbed-dsp mbed TouchButton

Fork of test by BMT M9 Groep01

Files at this revision

API Documentation at this revision

Comitter:
s1340735
Date:
Fri Oct 24 12:46:26 2014 +0000
Parent:
20:5cd52a0daab0
Child:
22:0be5dfa04f75
Commit message:
moving average bicep 30->60. tweede void tricep in de if loop

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Oct 24 12:18:58 2014 +0000
+++ b/main.cpp	Fri Oct 24 12:46:26 2014 +0000
@@ -7,8 +7,9 @@
 
 HIDScope scope(4);
 
-AnalogIn emgB(PTB1);//biceps
-AnalogIn emgT(PTB2); // tricep
+AnalogIn emgB(PTB1); //biceps
+AnalogIn emgT(PTB2); //tricep
+
 
 //*** OBJECTS ***
 //bicep
@@ -17,7 +18,8 @@
 float filtered_emgB;
 float drempelwaardeB1, drempelwaardeB2, drempelwaardeB3;//B1=snelheidsstand 1, B2=snelheidsstand 2, B3=snelheidsstand 3
 int yB1, yB2, yB3;
-float B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14, B15, B16, B17, B18, B19, B20, B21, B22, B23, B24, B25, B26, B27, B28, B29,MOVAVG_B; //moving average objects
+float B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14, B15, B16, B17, B18, B19, B20, B21, B22, B23, B24, B25, B26, B27, B28, B29, MOVAVG_B; //moving average objects
+float B30, B31, B32, B33, B34, B35, B36, B37, B38, B39, B40, B41, B42, B43, B44, B45, B46, B47, B48, B49, B50, B51, B52, B53, B54, B55, B56, B57, B58, B59;
 int snelheidsstand;
 //tricep
 uint16_t emg_valueT;
@@ -33,8 +35,8 @@
 //*** FILTERS ***
 arm_biquad_casd_df1_inst_f32 notchT;
 arm_biquad_casd_df1_inst_f32 notchB;
-//constants for 50Hz 
-float notch_const[]={0.5857841106784856, -1.3007020142696517e-16, 0.5857841106784856, 1.3007020142696517e-16, -0.17156822135697122};//{a0 a1 a2 -b1 -b2}
+//constants for 50Hz
+float notch_const[]= {0.5857841106784856, -1.3007020142696517e-16, 0.5857841106784856, 1.3007020142696517e-16, -0.17156822135697122}; //{a0 a1 a2 -b1 -b2}
 float notch_states[4];
 
 arm_biquad_casd_df1_inst_f32 lowpassT;
@@ -63,7 +65,7 @@
     filtered_emgT = fabs(filtered_emgT);
     arm_biquad_cascade_df1_f32(&highpassT, &filtered_emgT, &filtered_emgT, 1 );
     filtered_emgT = fabs(filtered_emgT);
-    
+
     //Triceps moving average
     T0=filtered_emgT;
     MOVAVG_T=T0*0.03333+T1*0.03333+T2*0.03333+T3*0.03333+T4*0.03333+T5*0.03333+T6*0.03333+T7*0.03333+T8*0.03333+T9*0.03333+T10*0.03333+T11*0.03333+T12*0.03333+T13*0.03333+T14*0.03333+T15*0.03333+T16*0.03333+T17*0.03333+T18*0.03333+T19*0.03333+T20*0.03333+T21*0.03333+T22*0.03333+T23*0.03333+T24*0.03333+T25*0.03333+T26*0.03333+T27*0.03333+T28*0.03333+T29*0.03333;
@@ -76,6 +78,7 @@
     T23=T22;
     T22=T21;
     T21=T20;
+    T20=T19;
     T19=T18;
     T18=T17;
     T17=T16;
@@ -95,7 +98,7 @@
     T3=T2;
     T2=T1;
     T1=T0;
-    
+
     //sturen naar scherm (Realterm)
     pc.printf("%f\r\n",MOVAVG_T);
 
@@ -117,10 +120,40 @@
     filtered_emgB = fabs(filtered_emgB);
     arm_biquad_cascade_df1_f32(&highpassB, &filtered_emgB, &filtered_emgB, 1 );
     filtered_emgB = fabs(filtered_emgB);
-    
+
     //Biceps moving average
     B0=filtered_emgB;
-    MOVAVG_B=B0*0.03333+B1*0.03333+B2*0.03333+B3*0.03333+B4*0.03333+B5*0.03333+B6*0.03333+B7*0.03333+B8*0.03333+B9*0.03333+B10*0.03333+B11*0.03333+B12*0.03333+B13*0.03333+B14*0.03333+B15*0.03333+B16*0.03333+B17*0.03333+B18*0.03333+B19*0.03333+B20*0.03333+B21*0.03333+B22*0.03333+B23*0.03333+B24*0.03333+B25*0.03333+B26*0.03333+B27*0.03333+B28*0.03333+B29*0.03333;
+    MOVAVG_B=B0*0.01667+B1*0.01667+B2*0.01667+B3*0.01667+B4*0.01667+B5*0.01667+B6*0.01667+B7*0.01667+B8*0.01667+B9*0.01667+B10*0.01667+B11*0.01667+B12*0.01667+B13*0.01667+B14*0.01667+B15*0.01667+B16*0.01667+B17*0.01667+B18*0.01667+B19*0.01667+B20*0.01667+B21*0.01667+B22*0.01667+B23*0.01667+B24*0.01667+B25*0.01667+B26*0.01667+B27*0.01667+B28*0.01667+B29*0.01667+B30*0.01667+B31*0.01667+B32*0.01667+B33*0.01667+B34*0.01667+B35*0.01667+B36*0.01667+B37*0.01667+B38*0.01667+B39*0.01667+B40*0.01667+B41*0.01667+B42*0.01667+B43*0.01667+B44*0.01667+B45*0.01667+B46*0.01667+B47*0.01667+B48*0.01667+B49*0.01667+B50*0.01667+B51*0.01667+B52*0.01667+B53*0.01667+B54*0.01667+B55*0.01667+B56*0.01667+B57*0.01667+B58*0.01667+B59*0.01667;
+    B59=B58;
+    B58=B57;
+    B57=B56;
+    B56=B55;
+    B55=B54;
+    B54=B53;
+    B53=B52;
+    B52=B51;
+    B51=B50;
+    B50=B48;
+    B49=B49;
+    B48=B47;
+    B47=B46;
+    B46=B45;
+    B45=B44;
+    B44=B43;
+    B43=B42;
+    B42=B41;
+    B41=B40;
+    B40=B39;
+    B39=B38;
+    B38=B37;
+    B37=B36;
+    B36=B35;
+    B35=B34;
+    B34=B33;
+    B33=B32;
+    B32=B31;
+    B31=B30;
+    B30=B29;
     B29=B28;
     B28=B27;
     B27=B26;
@@ -130,6 +163,7 @@
     B23=B22;
     B22=B21;
     B21=B20;
+    B20=B19;
     B19=B18;
     B18=B17;
     B17=B16;
@@ -167,31 +201,32 @@
 
     //bepaling van positie met triceps 1
     Ticker log_timerT1;
-    
+
     arm_biquad_cascade_df1_init_f32(&notchT,1,notch_const,notch_states);
     arm_biquad_cascade_df1_init_f32(&lowpassT,1,lowpass_const,lowpass_states);
     arm_biquad_cascade_df1_init_f32(&highpassT,1,highpass_const,highpass_states);
 
     log_timerT1.attach(Triceps, 0.005);
-    wait(30); //log_timerT wordt 2000 keer uitgevoerd
+    wait(30);
     log_timerT1.detach();
 
     MOVAVG_T=MOVAVG_Positie1;
 
-    //bepaling van positie met tricep 2
-    Ticker log_timerT2;
-
-    log_timerT2.attach(Triceps, 0.005);
-    wait(30);
-    log_timerT2.detach();
-
-    MOVAVG_T=MOVAVG_Positie2;
-
     // positie van batje met behulp van Triceps
     drempelwaardeT=0.0001;
 
     if (MOVAVG_Positie1 >= drempelwaardeT) {
         yT1=1;
+
+        //bepaling van positie met tricep 2
+        Ticker log_timerT2;
+
+        log_timerT2.attach(Triceps, 0.005);
+        wait(30);
+        log_timerT2.detach();
+
+        MOVAVG_T=MOVAVG_Positie2;
+
         if (MOVAVG_Positie2 >= drempelwaardeT) {
             yT2=1;
         } else {
@@ -220,7 +255,7 @@
     wait(5);
 
     Ticker log_timerB;
-    
+
     arm_biquad_cascade_df1_init_f32(&notchB,1,notch_const,notch_states);
     arm_biquad_cascade_df1_init_f32(&lowpassB,1,lowpass_const,lowpass_states);
     arm_biquad_cascade_df1_init_f32(&highpassB,1,highpass_const,highpass_states);