Alle drie de signalen gefilterd en binair gemaakt
Dependencies: mbed HIDScope biquadFilter
Diff: main.cpp
- Revision:
- 25:cfd422c3cf4d
- Parent:
- 23:a6f18aee31cd
- Child:
- 26:1eb3c3b04b80
diff -r a6f18aee31cd -r cfd422c3cf4d main.cpp --- a/main.cpp Wed Oct 30 12:11:18 2019 +0000 +++ b/main.cpp Thu Oct 31 18:25:53 2019 +0000 @@ -5,25 +5,27 @@ #include "numeric" #include "BiQuad.h" + //Define objects -AnalogIn emg0( A0 ); -AnalogIn emg1( A1 ); -//AnalogIn emg2( A2 ); -//AnalogIn emg3( A3 ); +AnalogIn emg0( A0 ); // 1e +AnalogIn emg2( A2 ); // 2e +AnalogIn emg4( A4 ); // 3e + float A; float B; Ticker sample_timer; -HIDScope scope( 5 ); +HIDScope scope( 3 ); DigitalOut led(LED1); const int leng_filt = 60; -const int box_length = 100; -const int box_lengthC = 200; -const int box_checkC = 150; -const float grenswaardeA = 0.01; -const float grenswaardeB = 0.02; -const float grenswaardeC = 0.28; - +const int box_length = 50; +const int box_lengthC = 150; +const int box_checkC = 50; +const float grenswaardeA0 = 0.025; +const float grenswaardeB0 = 0.015; +//const float grenswaardeA1 = 0.022; +//const float grenswaardeB1 = 0.018; +const float grenswaardeC = 0.015; float Ay1; float Ay2; float A_array[leng_filt] = {0}; @@ -43,21 +45,21 @@ float C_array[leng_filt] = {0}; float C_ar[leng_filt] = {0}; float C_ar2[leng_filt] = {0}; -float C_ar3[box_length] = {0}; +float C_ar3[box_lengthC] = {0}; float result = 0; float Asum = 0; const int Fs = 2000; //Sample Frequency -const double b0 = 0.206572; -const double b1 = 0.413144; -const double b2 = 0.206572; +const double b0 = 0.292893; +const double b1 = 0.585786; +const double b2 = 0.292893; const double a0 = 1.000000; -const double a1 = -0.369527; -const double a2 = 0.195816; +const double a1 = -0.00000; +const double a2 = 0.171573; void sample() { - BiQuad lowpass(b0,b1, b2, a0, a1, a2); + BiQuad lowpassA(b0,b1, b2, a0, a1, a2); // Signaal 1 (A) float A = emg0.read(); float Amean = 0; @@ -73,7 +75,7 @@ Ay1 = A - Amean; Ay1 = fabs(Ay1); - Ay1 = lowpass.step(Ay1); // First signal, after Butterworth + Ay1 = lowpassA.step(Ay1); // First signal, after Butterworth for (int j=leng_filt-1; j>=1; j--) { A_ar2[j] = A_ar2[j-1]; } @@ -84,10 +86,14 @@ { Ay2 += A_ar2[i]*1/leng_filt; } float Ay3; - if(Ay2>grenswaardeA) + if(Ay2>grenswaardeA0) { Ay3 = 1; } - if(Ay2<=grenswaardeA) + //if(Ay2<=grenswaardeA0) + //{ if(Ay2>grenswaardeA1) + // { Ay3 = 0.5; } } + + if(Ay2<=grenswaardeA0) { Ay3 = 0; } for (int j=box_length-1; j>=1; j--) @@ -100,9 +106,13 @@ { if(A_ar3[j] == 1) { boxcheckA = 1;} } - // Signaal 2 (B) - - float B = emg0.read(); + //for (int j=0; j<=box_length-1; j++) + // { if(A_ar3[j] == 0.5) + // { boxcheckA = 0.5;} } + + // Signaal 2 (B) + BiQuad lowpassB(b0,b1, b2, a0, a1, a2); + float B = emg2.read(); float Bmean = 0; float By2 = 0; @@ -116,7 +126,7 @@ By1 = B - Bmean; By1 = fabs(By1); - By1 = lowpass.step(By1); // First signal, after Butterworth + By1 = lowpassB.step(By1); // First signal, after Butterworth for (int j=leng_filt-1; j>=1; j--) { B_ar2[j] = B_ar2[j-1]; } @@ -127,10 +137,14 @@ { By2 += B_ar2[i]*1/leng_filt; } float By3; - if(By2>grenswaardeB) + if(By2>grenswaardeB0) { By3 = 1; } - if(By2<=grenswaardeB) + //if(By2<=grenswaardeB0) + //{ if(By2>grenswaardeB1) + // { By3 = 0.5; } } + + if(By2<=grenswaardeB0) { By3 = 0; } for (int j=box_length-1; j>=1; j--) @@ -143,9 +157,14 @@ { if(B_ar3[j] == 1) { boxcheckB = 1;} } - // Signaal 3 (C) + //for (int j=0; j<=box_length-1; j++) + //{ if(B_ar3[j] == 0.5) + // { boxcheckB = 0.5;} } - float C = emg0.read(); + + // Signaal 3 (C) + BiQuad lowpassC(b0,b1, b2, a0, a1, a2); + float C = emg4.read(); float Cmean = 0; float Cy2 = 0; @@ -159,15 +178,15 @@ Cy1 = C - Cmean; Cy1 = fabs(Cy1); - Cy1 = lowpass.step(Cy1); // First signal, after Butterworth - + Cy1 = lowpassC.step(Cy1); // First signal, after Butterworth + for (int j=leng_filt-1; j>=1; j--) { C_ar2[j] = C_ar2[j-1]; } C_ar2[0] = Cy1; for(int i=0; i<=leng_filt-1; i++) - { Cy2 += C_ar2[i]*1/leng_filt; } + { Cy2 += C_ar2[i]*1/leng_filt; } float Cy3; if(Cy2>grenswaardeC) @@ -185,14 +204,12 @@ for (int j=0; j<=box_length-1; j++) { C_sum += C_ar3[j]; if(C_sum >= box_checkC) - { boxcheckC = 1;} } - - - scope.set(0, emg0.read()); - scope.set(1, Cy1); - scope.set(2, Cy2); - scope.set(3, Cy3); - scope.set(4, boxcheckC); + { boxcheckC = 1;} + } + + scope.set(0, boxcheckA); + scope.set(1, boxcheckB); + scope.set(2, boxcheckC); scope.send(); led = !led; @@ -200,6 +217,6 @@ int main() { - sample_timer.attach(&sample, 0.001); + sample_timer.attach(&sample, 0.005); while(1) {} } \ No newline at end of file