filters aangepast en bepaling threshold
Dependencies: HIDScope MODSERIAL biquadFilter mbed
Fork of EMGV3 by
Diff: main.cpp
- Revision:
- 25:5e9cc994cd1f
- Parent:
- 24:6661dd6a1718
- Child:
- 26:4c867b04c0d8
diff -r 6661dd6a1718 -r 5e9cc994cd1f main.cpp --- a/main.cpp Mon Oct 12 09:24:44 2015 +0000 +++ b/main.cpp Mon Oct 12 13:32:26 2015 +0000 @@ -30,12 +30,17 @@ double EMG_right_value; double EMG_right_f1; double EMG_right_f2; + double EMG_right_f3; + double EMG_right_f4; + double EMG_right_f5; + double EMG_right_f6; + double EMG_right_MAF; double EMG_right_abs; - double Threshold1 = 0.03; + double Threshold1 = 0.02; double Threshold2 = 0.06; - int N = 20; - double MAF_left[20]; + int N = 50; + double MAF_left[50]; double EMG_left_MAF; // coëfficiënten @@ -71,22 +76,50 @@ EMG_left_f5 = EMG_notch1.step(EMG_left_f4); EMG_left_f6 = EMG_notch1.step(EMG_left_f5); -// EMG_right_value = EMG_right.read(); -// EMG_right_f1 = EMG_highpass.step(EMG_right_value); -// EMG_right_f1 = EMG_lowpass.step(EMG_right_f1); -// EMG_right_abs = fabs(EMG_right_f2); + EMG_right_value = EMG_right.read(); + EMG_right_f1 = EMG_highpass1.step(EMG_right_value); + EMG_right_f2 = EMG_highpass2.step(EMG_right_f1); + EMG_right_abs = fabs(EMG_right_f2); + EMG_right_f3 = EMG_lowpass1.step(EMG_right_abs); + EMG_right_f4 = EMG_lowpass2.step(EMG_right_f3); + EMG_right_f5 = EMG_notch1.step(EMG_right_f4); + EMG_right_f6 = EMG_notch1.step(EMG_right_f5); } // Movingaverage Filter void MovingAverageFilter() { - int ArraySum; - for (int a = 0; a<N; a++) - { - ArraySum = ArraySum + MAF_left[a]; - } - EMG_left_MAF = ArraySum/N; - // EMG_left_MAF = (MAF_left[0]+MAF_left[1]+MAF_left[2]+MAF_left[3]+MAF_left[5]+MAF_left[6]+MAF_left[7]+MAF_left[8]+MAF_left[9]+MAF_left[10]+MAF_left[11]+MAF_left[12]+MAF_left[13]+MAF_left[14]+MAF_left[15]+MAF_left[16]+MAF_left[17]+MAF_left[18]+MAF_left[19])/20; + EMG_left_MAF = (MAF_left[0]+MAF_left[1]+MAF_left[2]+MAF_left[3]+MAF_left[4]+MAF_left[5]+MAF_left[6]+MAF_left[7]+MAF_left[8]+MAF_left[9]+MAF_left[10]+MAF_left[11]+MAF_left[12]+MAF_left[13]+MAF_left[14]+MAF_left[15]+MAF_left[16]+MAF_left[17]+MAF_left[18]+MAF_left[19]+MAF_left[20]+MAF_left[21]+MAF_left[22]+MAF_left[23]+MAF_left[24]+MAF_left[25]+MAF_left[26]+MAF_left[27]+MAF_left[28]+MAF_left[29]+MAF_left[30]+MAF_left[31]+MAF_left[32]+MAF_left[33]+MAF_left[34]+MAF_left[35]+MAF_left[36]+MAF_left[37]+MAF_left[38]+MAF_left[39]+MAF_left[40]+MAF_left[41]+MAF_left[42]+MAF_left[43]+MAF_left[44]+MAF_left[45]+MAF_left[46]+MAF_left[47]+MAF_left[48]+MAF_left[49])/N; + MAF_left[49] = MAF_left[48]; + MAF_left[48] = MAF_left[47]; + MAF_left[47] = MAF_left[46]; + MAF_left[46] = MAF_left[45]; + MAF_left[45] = MAF_left[44]; + MAF_left[44] = MAF_left[43]; + MAF_left[43] = MAF_left[42]; + MAF_left[42] = MAF_left[41]; + MAF_left[41] = MAF_left[40]; + MAF_left[40] = MAF_left[39]; + MAF_left[39] = MAF_left[38]; + MAF_left[38] = MAF_left[37]; + MAF_left[37] = MAF_left[36]; + MAF_left[36] = MAF_left[35]; + MAF_left[35] = MAF_left[34]; + MAF_left[34] = MAF_left[33]; + MAF_left[33] = MAF_left[32]; + MAF_left[32] = MAF_left[31]; + MAF_left[31] = MAF_left[30]; + MAF_left[30] = MAF_left[29]; + MAF_left[29] = MAF_left[28]; + MAF_left[28] = MAF_left[27]; + MAF_left[27] = MAF_left[26]; + MAF_left[26] = MAF_left[25]; + MAF_left[25] = MAF_left[24]; + MAF_left[24] = MAF_left[23]; + MAF_left[23] = MAF_left[22]; + MAF_left[22] = MAF_left[21]; + MAF_left[21] = MAF_left[20]; + MAF_left[20] = MAF_left[19]; MAF_left[19] = MAF_left[18]; MAF_left[18] = MAF_left[17]; MAF_left[17] = MAF_left[16]; @@ -113,11 +146,11 @@ void ScopeSend() { scope.set(0, EMG_left_value); - scope.set(1, EMG_left_f2); - scope.set(2, EMG_left_abs); - scope.set(3, EMG_left_f4); - scope.set(4, EMG_left_f6); - scope.set(5, EMG_left_MAF); + scope.set(1, EMG_left_MAF); + scope.set(2, EMG_right_value); + scope.set(3, EMG_right_f2); + scope.set(4, EMG_right_f4); + scope.set(5, EMG_right_f6); scope.send(); } @@ -125,7 +158,7 @@ { SampleEMG.attach(&EMGfilter, 0.002); ScopeTimer.attach(&ScopeSend, 0.002); - MovingAverage.attach(&MovingAverageFilter, 0.002); + MovingAverage.attach(&MovingAverageFilter, 0.005); while(1) { if (EMG_left_f6 > Threshold1)