Filterd vier EMG signalen en zend naar HIDscope
Dependencies: MovingAverage mbed HIDScope biquadFilter
main.cpp@31:4011beb5a03c, 2019-04-20 (annotated)
- Committer:
- aschut
- Date:
- Sat Apr 20 20:08:23 2019 +0000
- Revision:
- 31:4011beb5a03c
- Parent:
- 30:0988a637a342
Code om 4 EMG signalen te filteren en met hidscope af te lezen
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vsluiter | 0:32bb76391d89 | 1 | #include "mbed.h" |
aschut | 26:874d50f440d0 | 2 | #include "HIDScope.h" |
aschut | 23:f01a1bd3b3c4 | 3 | #include "BiQuad.h" |
aschut | 28:21746a69e96a | 4 | #include <iostream> |
aschut | 26:874d50f440d0 | 5 | |
aschut | 28:21746a69e96a | 6 | //test |
aschut | 28:21746a69e96a | 7 | double emg1_highpassed; |
aschut | 28:21746a69e96a | 8 | |
aschut | 23:f01a1bd3b3c4 | 9 | DigitalOut led1(LED_GREEN); |
aschut | 23:f01a1bd3b3c4 | 10 | DigitalOut led2(LED_RED); |
aschut | 23:f01a1bd3b3c4 | 11 | DigitalOut led3(LED_BLUE); |
aschut | 26:874d50f440d0 | 12 | |
aschut | 28:21746a69e96a | 13 | // Tickers |
aschut | 28:21746a69e96a | 14 | Ticker sample_ticker; //ticker voor filteren met 1000Hz |
aschut | 28:21746a69e96a | 15 | Ticker threshold_check_ticker; //ticker voor het checken van de threshold met 1000Hz |
aschut | 28:21746a69e96a | 16 | Timer timer_calibration; //timer voor EMG Kalibratie |
aschut | 30:0988a637a342 | 17 | double ts = 0.001; //tijdsstap !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
aschut | 28:21746a69e96a | 18 | double calibration_time = 37; //Kalibratie tijd |
aschut | 22:2405d2be193d | 19 | |
aschut | 23:f01a1bd3b3c4 | 20 | //Input |
aschut | 30:0988a637a342 | 21 | AnalogIn emg1( A1 ); //Duim |
aschut | 30:0988a637a342 | 22 | AnalogIn emg2( A2 ); //Bicep |
aschut | 30:0988a637a342 | 23 | AnalogIn emg3( A3 ); //Dorsaal |
aschut | 30:0988a637a342 | 24 | AnalogIn emg4( A4 ); //Palmair |
tomlankhorst | 19:2bf824669684 | 25 | |
aschut | 23:f01a1bd3b3c4 | 26 | // GLOBALS EMG |
aschut | 28:21746a69e96a | 27 | //Gefilterde EMG signalen |
aschut | 23:f01a1bd3b3c4 | 28 | volatile double emg1_filtered, emg2_filtered, emg3_filtered, emg4_filtered; |
aschut | 23:f01a1bd3b3c4 | 29 | |
aschut | 28:21746a69e96a | 30 | bool thresholdreach1 = false; |
aschut | 28:21746a69e96a | 31 | bool thresholdreach2 = false; |
aschut | 28:21746a69e96a | 32 | bool thresholdreach3 = false; |
aschut | 28:21746a69e96a | 33 | bool thresholdreach4 = false; |
aschut | 23:f01a1bd3b3c4 | 34 | |
aschut | 28:21746a69e96a | 35 | volatile double temp_highest_emg1 = 0; //Hoogste waarde gevonden tijdens kalibratie |
aschut | 23:f01a1bd3b3c4 | 36 | volatile double temp_highest_emg2 = 0; |
aschut | 23:f01a1bd3b3c4 | 37 | volatile double temp_highest_emg3 = 0; |
aschut | 23:f01a1bd3b3c4 | 38 | volatile double temp_highest_emg4 = 0; |
aschut | 23:f01a1bd3b3c4 | 39 | |
aschut | 28:21746a69e96a | 40 | //Percentage van de hoogste waarde waar de bovenste treshold gezet moet worden |
aschut | 28:21746a69e96a | 41 | double Duim_p_t = 0.5; |
aschut | 28:21746a69e96a | 42 | double Bicep_p_t = 0.5; |
aschut | 28:21746a69e96a | 43 | double Dorsaal_p_t = 0.5; |
aschut | 28:21746a69e96a | 44 | double Palmair_p_t = 0.5; |
aschut | 25:56f5c2786f11 | 45 | |
aschut | 28:21746a69e96a | 46 | //Percentage van de hoogste waarde waar de onderste treshold gezet moet worden |
aschut | 28:21746a69e96a | 47 | double Duim_p_tL = 0.5; |
aschut | 28:21746a69e96a | 48 | double Bicep_p_tL = 0.5; |
aschut | 28:21746a69e96a | 49 | double Dorsaal_p_tL = 0.5; |
aschut | 28:21746a69e96a | 50 | double Palmair_p_tL = 0.5; |
aschut | 28:21746a69e96a | 51 | |
aschut | 28:21746a69e96a | 52 | // Waarde bovenste treshold waar het signaal overheen moet om de arm te activeren |
aschut | 23:f01a1bd3b3c4 | 53 | volatile double threshold1; |
aschut | 23:f01a1bd3b3c4 | 54 | volatile double threshold2; |
aschut | 23:f01a1bd3b3c4 | 55 | volatile double threshold3; |
aschut | 23:f01a1bd3b3c4 | 56 | volatile double threshold4; |
aschut | 23:f01a1bd3b3c4 | 57 | |
aschut | 28:21746a69e96a | 58 | // Waarde onderste treshold waar het signaal onder moet om de arm te deactiveren |
aschut | 28:21746a69e96a | 59 | volatile double threshold1L; |
aschut | 28:21746a69e96a | 60 | volatile double threshold2L; |
aschut | 28:21746a69e96a | 61 | volatile double threshold3L; |
aschut | 28:21746a69e96a | 62 | volatile double threshold4L; |
aschut | 28:21746a69e96a | 63 | |
aschut | 23:f01a1bd3b3c4 | 64 | // thresholdreads bools |
aschut | 25:56f5c2786f11 | 65 | int Duim; |
aschut | 25:56f5c2786f11 | 66 | int Bicep; |
aschut | 28:21746a69e96a | 67 | int Dorsaal; |
aschut | 28:21746a69e96a | 68 | int Palmair; |
aschut | 23:f01a1bd3b3c4 | 69 | |
aschut | 23:f01a1bd3b3c4 | 70 | // EMG OUTPUT |
aschut | 23:f01a1bd3b3c4 | 71 | int EMGxplus; |
aschut | 23:f01a1bd3b3c4 | 72 | int EMGxmin ; |
aschut | 23:f01a1bd3b3c4 | 73 | int EMGyplus; |
aschut | 23:f01a1bd3b3c4 | 74 | int EMGymin ; |
aschut | 23:f01a1bd3b3c4 | 75 | |
aschut | 26:874d50f440d0 | 76 | |
aschut | 24:0db52d2e1d2a | 77 | //EMG1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
aschut | 28:21746a69e96a | 78 | //Highpass vierde orde cutoff 20Hz, Band filter om 49, 50, 51Hz eruit te filteren |
aschut | 30:0988a637a342 | 79 | BiQuadChain highp1; |
aschut | 28:21746a69e96a | 80 | BiQuad highp1_1( 0.8485, -1.6969, 0.8485, 1.0000, -1.7783, 0.7924 ); |
aschut | 28:21746a69e96a | 81 | BiQuad highp1_2( 1.0000, -2.0000, 1.0000, 1.0000, -1.8934, 0.9085 ); |
aschut | 28:21746a69e96a | 82 | BiQuad notch1_1( 0.9907, -1.8843, 0.9907, 1.0000, -1.8843, 0.9813 ); |
aschut | 24:0db52d2e1d2a | 83 | |
aschut | 28:21746a69e96a | 84 | //Lowpass first order cutoff 0.4Hz |
aschut | 28:21746a69e96a | 85 | BiQuad lowp1( 0.0013, 0.0013, 0, 1.0000, -0.9975, 0 ); |
aschut | 24:0db52d2e1d2a | 86 | |
aschut | 24:0db52d2e1d2a | 87 | //EMG2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
aschut | 30:0988a637a342 | 88 | //Highpass vierde orde cutoff 20Hz, Band filter om 49, 50, 51Hz eruit te filteren |
aschut | 24:0db52d2e1d2a | 89 | BiQuadChain highp2; |
aschut | 30:0988a637a342 | 90 | BiQuad highp2_1( 0.8485, -1.6969, 0.8485, 1.0000, -1.7783, 0.7924 ); |
aschut | 30:0988a637a342 | 91 | BiQuad highp2_2( 1.0000, -2.0000, 1.0000, 1.0000, -1.8934, 0.9085 ); |
aschut | 30:0988a637a342 | 92 | BiQuad notch2_1( 0.9907, -1.8843, 0.9907, 1.0000, -1.8843, 0.9813 ); |
aschut | 24:0db52d2e1d2a | 93 | |
aschut | 30:0988a637a342 | 94 | //Lowpass first order cutoff 0.4Hz |
aschut | 30:0988a637a342 | 95 | BiQuad lowp2( 0.0013, 0.0013, 0, 1.0000, -0.9975, 0 ); |
aschut | 24:0db52d2e1d2a | 96 | |
aschut | 24:0db52d2e1d2a | 97 | //EMG3!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
aschut | 30:0988a637a342 | 98 | //Highpass vierde orde cutoff 20Hz, Band filter om 49, 50, 51Hz eruit te filteren |
aschut | 24:0db52d2e1d2a | 99 | BiQuadChain highp3; |
aschut | 30:0988a637a342 | 100 | BiQuad highp3_1( 0.8485, -1.6969, 0.8485, 1.0000, -1.7783, 0.7924 ); |
aschut | 30:0988a637a342 | 101 | BiQuad highp3_2( 1.0000, -2.0000, 1.0000, 1.0000, -1.8934, 0.9085 ); |
aschut | 30:0988a637a342 | 102 | BiQuad notch3_1( 0.9907, -1.8843, 0.9907, 1.0000, -1.8843, 0.9813 ); |
aschut | 24:0db52d2e1d2a | 103 | |
aschut | 30:0988a637a342 | 104 | //Lowpass first order cutoff 0.4Hz |
aschut | 30:0988a637a342 | 105 | BiQuad lowp3( 0.0013, 0.0013, 0, 1.0000, -0.9975, 0 ); |
aschut | 24:0db52d2e1d2a | 106 | |
aschut | 24:0db52d2e1d2a | 107 | //EMG4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
aschut | 30:0988a637a342 | 108 | //Highpass vierde orde cutoff 20Hz, Band filter om 49, 50, 51Hz eruit te filteren |
aschut | 24:0db52d2e1d2a | 109 | BiQuadChain highp4; |
aschut | 30:0988a637a342 | 110 | BiQuad highp4_1( 0.8485, -1.6969, 0.8485, 1.0000, -1.7783, 0.7924 ); |
aschut | 30:0988a637a342 | 111 | BiQuad highp4_2( 1.0000, -2.0000, 1.0000, 1.0000, -1.8934, 0.9085 ); |
aschut | 30:0988a637a342 | 112 | BiQuad notch4_1( 0.9907, -1.8843, 0.9907, 1.0000, -1.8843, 0.9813 ); |
aschut | 24:0db52d2e1d2a | 113 | |
aschut | 30:0988a637a342 | 114 | //Lowpass first order cutoff 0.4Hz |
aschut | 30:0988a637a342 | 115 | BiQuad lowp4( 0.0013, 0.0013, 0, 1.0000, -0.9975, 0 ); |
aschut | 24:0db52d2e1d2a | 116 | |
aschut | 23:f01a1bd3b3c4 | 117 | // ~~~~~~~~~~~~~~~~~~~EMG FUNCTIONS~~~~~~~~~~~~~~~~~~ |
aschut | 23:f01a1bd3b3c4 | 118 | void emgsample() |
aschut | 23:f01a1bd3b3c4 | 119 | { |
aschut | 25:56f5c2786f11 | 120 | |
aschut | 30:0988a637a342 | 121 | // EMG signaal lezen |
aschut | 23:f01a1bd3b3c4 | 122 | double emgread1 = emg1.read(); |
aschut | 30:0988a637a342 | 123 | double emgread2 = emg2.read(); |
aschut | 23:f01a1bd3b3c4 | 124 | double emgread3 = emg3.read(); |
aschut | 23:f01a1bd3b3c4 | 125 | double emgread4 = emg4.read(); |
aschut | 30:0988a637a342 | 126 | |
aschut | 30:0988a637a342 | 127 | // Vierde orde highpass filter + notch filter |
aschut | 30:0988a637a342 | 128 | double emg1_highpassed = highp1.step(emgread1); |
aschut | 23:f01a1bd3b3c4 | 129 | double emg2_highpassed = highp2.step(emgread2); |
aschut | 23:f01a1bd3b3c4 | 130 | double emg3_highpassed = highp3.step(emgread3); |
aschut | 23:f01a1bd3b3c4 | 131 | double emg4_highpassed = highp4.step(emgread4); |
aschut | 23:f01a1bd3b3c4 | 132 | |
aschut | 30:0988a637a342 | 133 | //Rectificatie |
aschut | 28:21746a69e96a | 134 | double emg1_abs = abs(emg1_highpassed); |
aschut | 30:0988a637a342 | 135 | double emg2_abs = abs(emg2_highpassed); |
aschut | 30:0988a637a342 | 136 | double emg3_abs = abs(emg3_highpassed); |
aschut | 30:0988a637a342 | 137 | double emg4_abs = abs(emg4_highpassed); |
aschut | 23:f01a1bd3b3c4 | 138 | |
aschut | 23:f01a1bd3b3c4 | 139 | //All EMG abs into lowpass |
aschut | 30:0988a637a342 | 140 | emg1_filtered = lowp1.step(emg1_abs); |
aschut | 30:0988a637a342 | 141 | emg2_filtered = lowp2.step(emg2_abs); |
aschut | 30:0988a637a342 | 142 | emg3_filtered = lowp3.step(emg3_abs); |
aschut | 30:0988a637a342 | 143 | emg4_filtered = lowp4.step(emg4_abs); |
aschut | 25:56f5c2786f11 | 144 | |
aschut | 23:f01a1bd3b3c4 | 145 | } |
aschut | 23:f01a1bd3b3c4 | 146 | |
aschut | 23:f01a1bd3b3c4 | 147 | void CalibrationEMG() |
aschut | 23:f01a1bd3b3c4 | 148 | { |
aschut | 28:21746a69e96a | 149 | |
aschut | 28:21746a69e96a | 150 | while(timer_calibration<55) { //Duim |
aschut | 28:21746a69e96a | 151 | if(timer_calibration>0 && timer_calibration<7) { |
aschut | 23:f01a1bd3b3c4 | 152 | led1=!led1; |
aschut | 23:f01a1bd3b3c4 | 153 | if(emg1_filtered>temp_highest_emg1) { |
aschut | 23:f01a1bd3b3c4 | 154 | temp_highest_emg1= emg1_filtered; |
aschut | 26:874d50f440d0 | 155 | |
aschut | 23:f01a1bd3b3c4 | 156 | } |
aschut | 23:f01a1bd3b3c4 | 157 | } |
aschut | 28:21746a69e96a | 158 | if(timer_calibration>7 && timer_calibration<10) { |
aschut | 23:f01a1bd3b3c4 | 159 | led1=0; |
aschut | 23:f01a1bd3b3c4 | 160 | led2=0; |
aschut | 23:f01a1bd3b3c4 | 161 | led3=0; |
aschut | 23:f01a1bd3b3c4 | 162 | } |
aschut | 28:21746a69e96a | 163 | if(timer_calibration>10 && timer_calibration<17) { //Bicep |
aschut | 23:f01a1bd3b3c4 | 164 | led2=!led2; |
aschut | 23:f01a1bd3b3c4 | 165 | if(emg2_filtered>temp_highest_emg2) { |
aschut | 23:f01a1bd3b3c4 | 166 | temp_highest_emg2= emg2_filtered; |
aschut | 26:874d50f440d0 | 167 | |
aschut | 23:f01a1bd3b3c4 | 168 | } |
aschut | 23:f01a1bd3b3c4 | 169 | } |
aschut | 28:21746a69e96a | 170 | if(timer_calibration>17 && timer_calibration<20) { |
aschut | 23:f01a1bd3b3c4 | 171 | led1=0; |
aschut | 23:f01a1bd3b3c4 | 172 | led2=0; |
aschut | 23:f01a1bd3b3c4 | 173 | led3=0; |
aschut | 23:f01a1bd3b3c4 | 174 | } |
aschut | 28:21746a69e96a | 175 | if(timer_calibration>20 && timer_calibration<27) { //Dorsaal |
aschut | 23:f01a1bd3b3c4 | 176 | led3=!led3; |
aschut | 23:f01a1bd3b3c4 | 177 | if(emg3_filtered>temp_highest_emg3) { |
aschut | 23:f01a1bd3b3c4 | 178 | temp_highest_emg3= emg3_filtered; |
aschut | 26:874d50f440d0 | 179 | |
aschut | 23:f01a1bd3b3c4 | 180 | } |
aschut | 23:f01a1bd3b3c4 | 181 | } |
aschut | 28:21746a69e96a | 182 | if(timer_calibration>27 && timer_calibration<30) { |
aschut | 23:f01a1bd3b3c4 | 183 | led1=0; |
aschut | 23:f01a1bd3b3c4 | 184 | led2=0; |
aschut | 23:f01a1bd3b3c4 | 185 | led3=0; |
aschut | 23:f01a1bd3b3c4 | 186 | } |
aschut | 28:21746a69e96a | 187 | if(timer_calibration>30 && timer_calibration<37) { //Palmair |
aschut | 23:f01a1bd3b3c4 | 188 | led2=!led2; |
aschut | 23:f01a1bd3b3c4 | 189 | led3=!led3; |
aschut | 23:f01a1bd3b3c4 | 190 | if(emg4_filtered>temp_highest_emg4) { |
aschut | 23:f01a1bd3b3c4 | 191 | temp_highest_emg4= emg4_filtered; |
aschut | 26:874d50f440d0 | 192 | |
aschut | 23:f01a1bd3b3c4 | 193 | } |
aschut | 23:f01a1bd3b3c4 | 194 | } |
aschut | 23:f01a1bd3b3c4 | 195 | led1=1; |
aschut | 23:f01a1bd3b3c4 | 196 | led2=1; |
aschut | 23:f01a1bd3b3c4 | 197 | led3=1; |
aschut | 23:f01a1bd3b3c4 | 198 | |
aschut | 23:f01a1bd3b3c4 | 199 | |
aschut | 23:f01a1bd3b3c4 | 200 | } |
aschut | 23:f01a1bd3b3c4 | 201 | |
aschut | 28:21746a69e96a | 202 | threshold1 = temp_highest_emg1*Duim_p_t; |
aschut | 28:21746a69e96a | 203 | threshold2 = temp_highest_emg2*Bicep_p_t; |
aschut | 28:21746a69e96a | 204 | threshold3 = temp_highest_emg3*Dorsaal_p_t; |
aschut | 28:21746a69e96a | 205 | threshold4 = temp_highest_emg4*Palmair_p_t; |
aschut | 28:21746a69e96a | 206 | |
aschut | 28:21746a69e96a | 207 | threshold1L = temp_highest_emg1*Duim_p_tL; |
aschut | 28:21746a69e96a | 208 | threshold2L = temp_highest_emg2*Bicep_p_tL; |
aschut | 28:21746a69e96a | 209 | threshold3L = temp_highest_emg3*Dorsaal_p_tL; |
aschut | 28:21746a69e96a | 210 | threshold4L = temp_highest_emg4*Palmair_p_tL; |
aschut | 23:f01a1bd3b3c4 | 211 | } |
aschut | 23:f01a1bd3b3c4 | 212 | |
aschut | 28:21746a69e96a | 213 | //Check of emg_filtered boven de threshold is |
aschut | 23:f01a1bd3b3c4 | 214 | void threshold_check() |
aschut | 23:f01a1bd3b3c4 | 215 | { |
aschut | 28:21746a69e96a | 216 | // EMG1 Check |
aschut | 28:21746a69e96a | 217 | if (thresholdreach1 == false){ //Als emg_filtered nog niet boven de bovenste threshold is geweest |
aschut | 28:21746a69e96a | 218 | //bovenste threshold check |
aschut | 23:f01a1bd3b3c4 | 219 | if(emg1_filtered>threshold1) { |
aschut | 25:56f5c2786f11 | 220 | Duim = 1; |
aschut | 28:21746a69e96a | 221 | thresholdreach1 = true; |
aschut | 28:21746a69e96a | 222 | |
aschut | 23:f01a1bd3b3c4 | 223 | } else { |
aschut | 25:56f5c2786f11 | 224 | Duim= 0; |
aschut | 23:f01a1bd3b3c4 | 225 | } |
aschut | 28:21746a69e96a | 226 | } |
aschut | 28:21746a69e96a | 227 | else{ //Als emg_filtered boven de bovenste threshold is geweest |
aschut | 28:21746a69e96a | 228 | //onderste threshold check |
aschut | 28:21746a69e96a | 229 | if(emg1_filtered<threshold1L) { |
aschut | 28:21746a69e96a | 230 | Duim = 0; |
aschut | 28:21746a69e96a | 231 | thresholdreach1 = false; |
aschut | 28:21746a69e96a | 232 | |
aschut | 28:21746a69e96a | 233 | } else { |
aschut | 28:21746a69e96a | 234 | Duim= 1; |
aschut | 28:21746a69e96a | 235 | } |
aschut | 28:21746a69e96a | 236 | } |
aschut | 28:21746a69e96a | 237 | |
aschut | 28:21746a69e96a | 238 | // EMG2 Check |
aschut | 28:21746a69e96a | 239 | if (thresholdreach2 == false){ //Als emg_filtered nog niet boven de bovenste threshold is geweest |
aschut | 28:21746a69e96a | 240 | //bovenste threshold check |
aschut | 23:f01a1bd3b3c4 | 241 | if(emg2_filtered>threshold2) { |
aschut | 25:56f5c2786f11 | 242 | Bicep = 1; |
aschut | 28:21746a69e96a | 243 | thresholdreach2 = true; |
aschut | 23:f01a1bd3b3c4 | 244 | } else { |
aschut | 25:56f5c2786f11 | 245 | Bicep= 0; |
aschut | 23:f01a1bd3b3c4 | 246 | } |
aschut | 23:f01a1bd3b3c4 | 247 | } |
aschut | 28:21746a69e96a | 248 | else{ //Als emg_filtered boven de bovenste threshold is geweest |
aschut | 28:21746a69e96a | 249 | //onderste threshold check |
aschut | 28:21746a69e96a | 250 | if(emg2_filtered<threshold2L) { |
aschut | 28:21746a69e96a | 251 | Bicep = 0; |
aschut | 28:21746a69e96a | 252 | thresholdreach2 = false; |
aschut | 28:21746a69e96a | 253 | |
aschut | 23:f01a1bd3b3c4 | 254 | } else { |
aschut | 28:21746a69e96a | 255 | Bicep= 1; |
aschut | 28:21746a69e96a | 256 | } |
aschut | 23:f01a1bd3b3c4 | 257 | } |
aschut | 23:f01a1bd3b3c4 | 258 | |
aschut | 28:21746a69e96a | 259 | // EMG3 Check |
aschut | 28:21746a69e96a | 260 | if (thresholdreach3 == false){ //Als emg_filtered nog niet boven de bovenste threshold is geweest |
aschut | 28:21746a69e96a | 261 | //bovenste threshold check |
aschut | 28:21746a69e96a | 262 | if(emg3_filtered>threshold3) { |
aschut | 28:21746a69e96a | 263 | Dorsaal = 1; |
aschut | 28:21746a69e96a | 264 | thresholdreach3 = true; |
aschut | 28:21746a69e96a | 265 | } else { |
aschut | 28:21746a69e96a | 266 | Dorsaal= 0; |
aschut | 28:21746a69e96a | 267 | } |
aschut | 28:21746a69e96a | 268 | } |
aschut | 28:21746a69e96a | 269 | else{ //Als emg_filtered boven de bovenste threshold is geweest |
aschut | 28:21746a69e96a | 270 | //onderste threshold check |
aschut | 28:21746a69e96a | 271 | if(emg3_filtered<threshold3L) { |
aschut | 28:21746a69e96a | 272 | Dorsaal = 0; |
aschut | 28:21746a69e96a | 273 | thresholdreach3 = false; |
aschut | 28:21746a69e96a | 274 | |
aschut | 28:21746a69e96a | 275 | } else { |
aschut | 28:21746a69e96a | 276 | Dorsaal= 1; |
aschut | 28:21746a69e96a | 277 | } |
aschut | 28:21746a69e96a | 278 | } |
aschut | 23:f01a1bd3b3c4 | 279 | |
aschut | 28:21746a69e96a | 280 | // EMG4 Check |
aschut | 28:21746a69e96a | 281 | if (thresholdreach4 == false){ //Als emg_filtered nog niet boven de bovenste threshold is geweest |
aschut | 28:21746a69e96a | 282 | //bovenste threshold check |
aschut | 28:21746a69e96a | 283 | if(emg4_filtered>threshold4) { |
aschut | 28:21746a69e96a | 284 | Palmair = 1; |
aschut | 28:21746a69e96a | 285 | thresholdreach4 = true; |
aschut | 28:21746a69e96a | 286 | } else { |
aschut | 28:21746a69e96a | 287 | Palmair= 0; |
aschut | 28:21746a69e96a | 288 | } |
aschut | 28:21746a69e96a | 289 | } |
aschut | 28:21746a69e96a | 290 | else{ //Als emg_filtered boven de bovenste threshold is geweest |
aschut | 28:21746a69e96a | 291 | //onderste threshold check |
aschut | 28:21746a69e96a | 292 | if(emg4_filtered<threshold4L) { |
aschut | 28:21746a69e96a | 293 | Palmair = 0; |
aschut | 28:21746a69e96a | 294 | thresholdreach4 = false; |
aschut | 28:21746a69e96a | 295 | |
aschut | 28:21746a69e96a | 296 | } else { |
aschut | 28:21746a69e96a | 297 | Palmair= 1; |
aschut | 28:21746a69e96a | 298 | } |
aschut | 28:21746a69e96a | 299 | } |
aschut | 28:21746a69e96a | 300 | |
aschut | 28:21746a69e96a | 301 | } |
aschut | 28:21746a69e96a | 302 | |
aschut | 23:f01a1bd3b3c4 | 303 | |
aschut | 23:f01a1bd3b3c4 | 304 | |
aschut | 27:c0d748b7d5d1 | 305 | |
aschut | 27:c0d748b7d5d1 | 306 | |
aschut | 27:c0d748b7d5d1 | 307 | |
aschut | 27:c0d748b7d5d1 | 308 | |
aschut | 27:c0d748b7d5d1 | 309 | |
tomlankhorst | 14:f83354387756 | 310 | Ticker sample_timer; |
aschut | 30:0988a637a342 | 311 | HIDScope scope( 2 ); |
aschut | 27:c0d748b7d5d1 | 312 | DigitalOut led(LED1); |
vsluiter | 2:e314bb3b2d99 | 313 | |
aschut | 22:2405d2be193d | 314 | |
aschut | 31:4011beb5a03c | 315 | void sample() //Send to HIDscope |
vsluiter | 2:e314bb3b2d99 | 316 | { |
aschut | 27:c0d748b7d5d1 | 317 | |
aschut | 31:4011beb5a03c | 318 | |
aschut | 31:4011beb5a03c | 319 | scope.set(0, emg1_filtered ); |
aschut | 31:4011beb5a03c | 320 | scope.set(1, emg2_filtered); |
aschut | 30:0988a637a342 | 321 | scope.set(2, emg3_filtered ); |
aschut | 30:0988a637a342 | 322 | scope.set(3, emg4_filtered); |
aschut | 27:c0d748b7d5d1 | 323 | |
aschut | 31:4011beb5a03c | 324 | scope.send(); |
vsluiter | 2:e314bb3b2d99 | 325 | } |
vsluiter | 0:32bb76391d89 | 326 | |
aschut | 27:c0d748b7d5d1 | 327 | |
vsluiter | 0:32bb76391d89 | 328 | int main() |
tomlankhorst | 19:2bf824669684 | 329 | { |
aschut | 30:0988a637a342 | 330 | // Ticker voor EMG filtering |
aschut | 30:0988a637a342 | 331 | sample_ticker.attach(&emgsample, ts); |
aschut | 26:874d50f440d0 | 332 | |
aschut | 24:0db52d2e1d2a | 333 | //BiQuad Chain add |
aschut | 30:0988a637a342 | 334 | highp1.add( &highp1_1 ).add( &highp1_2 ).add( ¬ch1_1 ); |
aschut | 30:0988a637a342 | 335 | highp2.add( &highp2_1 ).add( &highp2_2 ).add( ¬ch2_1 ); |
aschut | 30:0988a637a342 | 336 | highp3.add( &highp3_1 ).add( &highp3_2 ).add( ¬ch3_1 ); |
aschut | 30:0988a637a342 | 337 | highp4.add( &highp4_1 ).add( &highp4_2 ).add( ¬ch4_1 ); |
aschut | 30:0988a637a342 | 338 | |
aschut | 30:0988a637a342 | 339 | // Ticker voor EMG uitlezen |
aschut | 30:0988a637a342 | 340 | |
aschut | 28:21746a69e96a | 341 | |
aschut | 28:21746a69e96a | 342 | temp_highest_emg1 = 0; //highest detected value right Biceps |
aschut | 23:f01a1bd3b3c4 | 343 | temp_highest_emg2 = 0; |
aschut | 23:f01a1bd3b3c4 | 344 | temp_highest_emg3 = 0; |
aschut | 23:f01a1bd3b3c4 | 345 | temp_highest_emg4 = 0; |
aschut | 23:f01a1bd3b3c4 | 346 | |
aschut | 23:f01a1bd3b3c4 | 347 | timer_calibration.reset(); |
aschut | 23:f01a1bd3b3c4 | 348 | timer_calibration.start(); |
aschut | 23:f01a1bd3b3c4 | 349 | |
aschut | 24:0db52d2e1d2a | 350 | |
aschut | 30:0988a637a342 | 351 | CalibrationEMG(); |
aschut | 27:c0d748b7d5d1 | 352 | |
aschut | 30:0988a637a342 | 353 | threshold_check_ticker.attach(&threshold_check, 0.001); |
aschut | 30:0988a637a342 | 354 | led1 = 1; |
aschut | 30:0988a637a342 | 355 | led2 = 1; |
aschut | 30:0988a637a342 | 356 | led3 = 1; |
aschut | 30:0988a637a342 | 357 | sample_timer.attach(&sample, 0.001); |
aschut | 30:0988a637a342 | 358 | sample_ticker.detach(); |
aschut | 30:0988a637a342 | 359 | timer_calibration.stop(); |
aschut | 24:0db52d2e1d2a | 360 | |
aschut | 25:56f5c2786f11 | 361 | |
aschut | 23:f01a1bd3b3c4 | 362 | |
tomlankhorst | 15:0da764eea774 | 363 | |
tomlankhorst | 14:f83354387756 | 364 | /*empty loop, sample() is executed periodically*/ |
aschut | 24:0db52d2e1d2a | 365 | while(1) { |
aschut | 24:0db52d2e1d2a | 366 | wait(0.01); |
aschut | 24:0db52d2e1d2a | 367 | } |
vsluiter | 0:32bb76391d89 | 368 | } |