
emg trial
Dependencies: FastPWM HIDScope MODSERIAL mbed biquadFilter
Revision 8:39519b33f767, committed 2018-10-30
- Comitter:
- s1680897
- Date:
- Tue Oct 30 14:20:49 2018 +0000
- Parent:
- 7:d72cbd7055af
- Commit message:
- hjhlkj
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Oct 26 13:58:47 2018 +0000 +++ b/main.cpp Tue Oct 30 14:20:49 2018 +0000 @@ -14,7 +14,7 @@ // Define the HIDScope and Ticker objects -HIDScope scope(4); +HIDScope scope(2); Ticker scopeTimer; Ticker EMGTicker; @@ -37,12 +37,6 @@ BiQuad Notch_emg3(1,-1.225251386743515e-16,1,-1.187919512117619e-16,0.939062505817492); BiQuad Notch_emg4(1,-1.225251386743515e-16,1,-1.187919512117619e-16,0.939062505817492); - //Low pass filters 25 Hz -BiQuad LP_emg1(1,2,1,-0.942809041582063,0.333333333333333); -BiQuad LP_emg2(1,2,1,-0.942809041582063,0.333333333333333); -BiQuad LP_emg3(1,2,1,-0.942809041582063,0.333333333333333); -BiQuad LP_emg4(1,2,1,-0.942809041582063,0.333333333333333); - // Global variables float EMGdata1; @@ -88,43 +82,7 @@ return fabs(HP_abs_EMGdata); } - -/* -// Lowpass filters - -// LP 1 -float LP_EMG1(float HP_abs_EMGdata) -{ - float EMG_filt = LP_emg1.step(HP_abs_EMGdata); - - return EMG_filt; -} - -// LP 2 -float LP_EMG2(float HP_abs_EMGdata) -{ - float EMG_filt = LP_emg2.step(HP_abs_EMGdata); - - return EMG_filt; -} - -// LP 3 -float LP_EMG3(float HP_abs_EMGdata) -{ - float EMG_filt = LP_emg3.step(HP_abs_EMGdata); - - return EMG_filt; -} - -// LP 4 -float LP_EMG4(float HP_abs_EMGdata) -{ - float EMG_filt = LP_emg4.step(HP_abs_EMGdata); - - return EMG_filt; -} -*/ - +// EMG moving filter float EMG_mean (float EMGarray[100]) { float sum = 0.0; @@ -139,103 +97,6 @@ return EMG_filt; } -// Moving mean of EMG data 1 -/* float Moving_mean1(float HP_abs_EMGdata1) -{ - int P1 = 200; - static float EMGarray1[200]; - - for(int i1 = P1-1; i1 >= 1; i1--) - { - EMGarray1[i1] = EMGarray1[i1-1]; - } - EMGarray1[0] = HP_abs_EMGdata1; - - float sum1 = 0.0; - - for(int j1=0; j1<200; j1++) - { - sum1 += EMGarray1[j1]; - } - - float EMG_filt1 = sum1 / (float) P1; - - return EMG_filt1; -} - -// Moving mean of EMG data 2 -float Moving_mean2(float HP_abs_EMGdata2) -{ - int P2 = 200; - static float EMGarray2[200]; - - for(int i2 = P2-1; i2 >= 1; i2--) - { - EMGarray2[i2] = EMGarray2[i2-1]; - } - EMGarray2[0] = HP_abs_EMGdata2; - - float sum2; - - for(int j2=0; j2<200; j2++) - { - sum2 += EMGarray2[j2]; - } - - float EMG_filt2 = sum2 / (float) P2; - - return EMG_filt2; -} - -// Moving mean of EMG data 3 -float Moving_mean3(float HP_abs_EMGdata3) -{ - int P3 = 200; - static float EMGarray3[200]; - - for(int i3 = P3-1; i3 >= 1; i3--) - { - EMGarray3[i3] = EMGarray3[i3-1]; - } - EMGarray3[0] = HP_abs_EMGdata3; - - float sum3; - - for(int j3=0; j3<200; j3++) - { - sum3 += EMGarray3[j3]; - } - - float EMG_filt3 = sum3 / (float) P3; - - return EMG_filt3; -} - -// Moving mean of EMG data 4 -float Moving_mean4(float HP_abs_EMGdata) -{ - int P = 200; - static float EMGarray[200]; - - for(int i = P-1; i >= 1; i--) - { - EMGarray[i] = EMGarray[i-1]; - } - EMGarray[0] = HP_abs_EMGdata; - - float sum; - - for(int j=0; j<200; j++) - { - sum += EMGarray[j]; - } - - float EMG_filt = sum / (float) P; - - return EMG_filt; -} -*/ - // Filtered signal to output between -1 and 1 float filt2kin (float EMG_filt1, float EMG_filt2, float max1, float max2) { @@ -295,37 +156,32 @@ EMG_array4[i] = EMG_array4[i-1]; } EMG_array4[0] = HP_abs_EMGdata4; - - /* float EMG_filt1 = Moving_mean1(HP_abs_EMGdata1); - float EMG_filt2 = Moving_mean2(HP_abs_EMGdata2); - float EMG_filt3 = Moving_mean3(HP_abs_EMGdata3); - float EMG_filt4 = Moving_mean4(HP_abs_EMGdata4); */ float EMG_filt1 = EMG_mean(EMG_array1); float EMG_filt2 = EMG_mean(EMG_array2); float EMG_filt3 = EMG_mean(EMG_array3); float EMG_filt4 = EMG_mean(EMG_array4); - float max1 = 0.45; - float max2 = 0.43; - float max3 = 0.45; - float max4 = 0.43; + float max1 = 0.01; + float max2 = 0.03; + float max3 = 0.02; + float max4 = 0.01; float kin_input_horizontal = filt2kin (EMG_filt1, EMG_filt2, max1, max2); float kin_input_vertical = filt2kin (EMG_filt3, EMG_filt4, max3, max4); - scope.set(0, EMG_filt1); - scope.set(1, EMG_filt2); - scope.set(2, EMG_filt3); - scope.set(3, EMG_filt4); + scope.set(0, kin_input_horizontal); + scope.set(1, kin_input_vertical); + //scope.set(2, EMG_filt3); + //scope.set(3, EMG_filt4); count++; - if (count == 50) + if (count == 100) { - pc.printf("EMG filt 1 = %lf \t EMG filt 2 = %lf \n\r", EMG_filt1, EMG_filt2); + pc.printf("EMG filt 1 = %lf \t EMG filt 2 = %lf \t EMG filt 3 = %lf \t EMG filt 4 = %lf \n\r", EMG_filt1, EMG_filt2, EMG_filt3, EMG_filt4); count = 0; } }