EMG script met 2e signaal, invalid build system

Dependencies:   HIDScope MODSERIAL biquadFilter mbed

Fork of EMG by Margreeth de Breij

Committer:
Margreeth95
Date:
Mon Oct 12 16:52:13 2015 +0000
Revision:
26:4c867b04c0d8
Parent:
25:5e9cc994cd1f
Child:
27:aa5ffd7227a5
EMG programma, 2 signalen. 2e signaal van A(0) lijkt invloed te hebben op gefilterde signaal A(1), oorzaak onbekend.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:32bb76391d89 1 #include "mbed.h"
vsluiter 11:ce72ec658a95 2 #include "HIDScope.h"
Margreeth95 19:34456a1effc4 3 #include "MODSERIAL.h"
Margreeth95 19:34456a1effc4 4 #include "biquadFilter.h"
vsluiter 0:32bb76391d89 5
vsluiter 4:8b298dfada81 6 //Define objects
Margreeth95 18:12250e88037f 7 AnalogIn EMG_left(A0); //Analog input
Margreeth95 18:12250e88037f 8 AnalogIn EMG_right(A1);
Margreeth95 18:12250e88037f 9 Ticker SampleEMG;
Margreeth95 18:12250e88037f 10 Ticker ScopeTimer;
Margreeth95 19:34456a1effc4 11 Ticker serial;
Margreeth95 24:6661dd6a1718 12 Ticker MovingAverage;
Margreeth95 24:6661dd6a1718 13 HIDScope scope(6);
Margreeth95 19:34456a1effc4 14 DigitalOut led(LED_RED);
Margreeth95 19:34456a1effc4 15 MODSERIAL pc(USBTX, USBRX);
Margreeth95 19:34456a1effc4 16
Margreeth95 18:12250e88037f 17
Margreeth95 19:34456a1effc4 18 // Declaring variables
Margreeth95 18:12250e88037f 19 double EMG_L_f_v1 = 0, EMG_L_f_v2 = 0;
Margreeth95 19:34456a1effc4 20 double EMG_L_fh=0;
Margreeth95 19:34456a1effc4 21 double EMG_left_value;
Margreeth95 22:207d314523ef 22 double EMG_left_f1;
Margreeth95 22:207d314523ef 23 double EMG_left_f2;
Margreeth95 24:6661dd6a1718 24 double EMG_left_f3;
Margreeth95 24:6661dd6a1718 25 double EMG_left_f4;
Margreeth95 24:6661dd6a1718 26 double EMG_left_f5;
Margreeth95 24:6661dd6a1718 27 double EMG_left_f6;
Margreeth95 22:207d314523ef 28 double EMG_left_abs;
Margreeth95 22:207d314523ef 29 double EMG_right_value;
Margreeth95 22:207d314523ef 30 double EMG_right_f1;
Margreeth95 22:207d314523ef 31 double EMG_right_f2;
Margreeth95 25:5e9cc994cd1f 32 double EMG_right_f3;
Margreeth95 25:5e9cc994cd1f 33 double EMG_right_f4;
Margreeth95 25:5e9cc994cd1f 34 double EMG_right_f5;
Margreeth95 25:5e9cc994cd1f 35 double EMG_right_f6;
Margreeth95 25:5e9cc994cd1f 36 double EMG_right_MAF;
Margreeth95 22:207d314523ef 37 double EMG_right_abs;
Margreeth95 25:5e9cc994cd1f 38 double Threshold1 = 0.02;
Margreeth95 24:6661dd6a1718 39 double Threshold2 = 0.06;
Margreeth95 24:6661dd6a1718 40
Margreeth95 25:5e9cc994cd1f 41 int N = 50;
Margreeth95 25:5e9cc994cd1f 42 double MAF_left[50];
Margreeth95 24:6661dd6a1718 43 double EMG_left_MAF;
Margreeth95 24:6661dd6a1718 44
Margreeth95 18:12250e88037f 45 // coëfficiënten
Margreeth95 24:6661dd6a1718 46 const double BiGainEMG_H1 = 0.795375, BiGainEMG_H2 = 0.895763;
Margreeth95 24:6661dd6a1718 47 const double EMGH1_a1 = -1.56308931068*BiGainEMG_H1, EMGH1_a2 = 0.61765749583*BiGainEMG_H1, EMGH1_b0 = 1.0*BiGainEMG_H1, EMGH1_b1 = -1.99909075151*BiGainEMG_H1, EMGH1_b2 = 1.0*BiGainEMG_H1; //coefficients for high-pass filter
Margreeth95 24:6661dd6a1718 48 const double EMGH2_a1 = -1.75651417587*BiGainEMG_H2, EMGH2_a2 = 0.82183182692*BiGainEMG_H2, EMGH2_b0 = 1.0*BiGainEMG_H2, EMGH2_b1 = -1.99470632157*BiGainEMG_H2, EMGH2_b2 = 1.0*BiGainEMG_H2; //coefficients for high-pass filter
Margreeth95 24:6661dd6a1718 49
Margreeth95 24:6661dd6a1718 50 const double BiGainEMG_L1=0.959332, BiGainEMG_L2 = 0.223396;
Margreeth95 24:6661dd6a1718 51 const double EMGL1_a1 = -1.55576653052*BiGainEMG_L1, EMGL1_a2 = 0.61374320375*BiGainEMG_L1, EMGL1_b0 = 1.0*BiGainEMG_L1, EMGL1_b1 = -0.90928276835*BiGainEMG_L1, EMGL1_b2 = 1.0*BiGainEMG_L1; // coefficients for low-pass filter
Margreeth95 24:6661dd6a1718 52 const double EMGL2_a1 = -1.79696141922*BiGainEMG_L2, EMGL2_a2 = 0.85096669383*BiGainEMG_L2, EMGL2_b0 = 1.0*BiGainEMG_L2, EMGL2_b1 = -1.75825311060*BiGainEMG_L2, EMGL2_b2 = 1.0*BiGainEMG_L2; // coefficients for low-pass filter
Margreeth95 24:6661dd6a1718 53
Margreeth95 24:6661dd6a1718 54 const double BiGainEMG_N1 = 1.0, BiGainEMG_N2 = 0.965081;
Margreeth95 24:6661dd6a1718 55 const double EMGN1_a1 = -1.56858163035*BiGainEMG_N1, EMGN1_a2 = 0.96424138362*BiGainEMG_N1, EMGN1_b0 = 1.0*BiGainEMG_N1, EMGN1_b1 = -1.61854514265*BiGainEMG_N1, EMGN1_b2 = 1.0*BiGainEMG_N1; //coefficients for high-pass filter
Margreeth95 24:6661dd6a1718 56 const double EMGN2_a1 = -1.61100357722*BiGainEMG_N2, EMGN2_a2 = 0.96592170538*BiGainEMG_N2, EMGN2_b0 = 1.0*BiGainEMG_N2, EMGN2_b1 = -1.61854514265*BiGainEMG_N2, EMGN2_b2 = 1.0*BiGainEMG_N2; //coefficients for high-pass filter
Margreeth95 24:6661dd6a1718 57
Margreeth95 20:a0642e983da9 58 // Filter creation
Margreeth95 24:6661dd6a1718 59 biquadFilter EMG_highpass1 (EMGH1_a1, EMGH1_a2, EMGH1_b0, EMGH1_b1, EMGH1_b2); // creates the high pass filter
Margreeth95 24:6661dd6a1718 60 biquadFilter EMG_highpass2 (EMGH2_a1, EMGH2_a2, EMGH2_b0, EMGH2_b1, EMGH2_b2);
Margreeth95 24:6661dd6a1718 61 biquadFilter EMG_lowpass1 (EMGL1_a1, EMGL1_a2, EMGL1_b0, EMGL1_b1, EMGL1_b2); // creates the low pass filter
Margreeth95 24:6661dd6a1718 62 biquadFilter EMG_lowpass2 (EMGL2_a1, EMGL2_a2, EMGL2_b0, EMGL2_b1, EMGL2_b2);
Margreeth95 24:6661dd6a1718 63 biquadFilter EMG_notch1 (EMGN1_a1, EMGN1_a2, EMGN1_b0, EMGN1_b1, EMGN1_b2); // creates the notch filter
Margreeth95 24:6661dd6a1718 64 biquadFilter EMG_notch2 (EMGN2_a1, EMGN2_a2, EMGN2_b0, EMGN2_b1, EMGN2_b2);
Margreeth95 24:6661dd6a1718 65
Margreeth95 19:34456a1effc4 66 // EMG filtering function
Margreeth95 22:207d314523ef 67 void EMGfilter() // Both EMG signals are filtered in one function and with the same filters
Margreeth95 19:34456a1effc4 68 {
Margreeth95 19:34456a1effc4 69 EMG_left_value = EMG_left.read();
Margreeth95 24:6661dd6a1718 70 EMG_left_f1 = EMG_highpass1.step(EMG_left_value);
Margreeth95 24:6661dd6a1718 71 EMG_left_f2 = EMG_highpass2.step(EMG_left_f1);
Margreeth95 22:207d314523ef 72 EMG_left_abs = fabs(EMG_left_f2);
Margreeth95 24:6661dd6a1718 73 EMG_left_f3 = EMG_lowpass1.step(EMG_left_abs);
Margreeth95 24:6661dd6a1718 74 EMG_left_f4 = EMG_lowpass2.step(EMG_left_f3);
Margreeth95 24:6661dd6a1718 75 EMG_left_f5 = EMG_notch1.step(EMG_left_f4);
Margreeth95 24:6661dd6a1718 76 EMG_left_f6 = EMG_notch1.step(EMG_left_f5);
Margreeth95 24:6661dd6a1718 77
Margreeth95 25:5e9cc994cd1f 78 EMG_right_value = EMG_right.read();
Margreeth95 25:5e9cc994cd1f 79 EMG_right_f1 = EMG_highpass1.step(EMG_right_value);
Margreeth95 25:5e9cc994cd1f 80 EMG_right_f2 = EMG_highpass2.step(EMG_right_f1);
Margreeth95 25:5e9cc994cd1f 81 EMG_right_abs = fabs(EMG_right_f2);
Margreeth95 25:5e9cc994cd1f 82 EMG_right_f3 = EMG_lowpass1.step(EMG_right_abs);
Margreeth95 25:5e9cc994cd1f 83 EMG_right_f4 = EMG_lowpass2.step(EMG_right_f3);
Margreeth95 25:5e9cc994cd1f 84 EMG_right_f5 = EMG_notch1.step(EMG_right_f4);
Margreeth95 25:5e9cc994cd1f 85 EMG_right_f6 = EMG_notch1.step(EMG_right_f5);
Margreeth95 19:34456a1effc4 86 }
vsluiter 2:e314bb3b2d99 87
Margreeth95 24:6661dd6a1718 88 // Movingaverage Filter
Margreeth95 24:6661dd6a1718 89 void MovingAverageFilter()
Margreeth95 24:6661dd6a1718 90 {
Margreeth95 25:5e9cc994cd1f 91 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;
Margreeth95 25:5e9cc994cd1f 92 MAF_left[49] = MAF_left[48];
Margreeth95 25:5e9cc994cd1f 93 MAF_left[48] = MAF_left[47];
Margreeth95 25:5e9cc994cd1f 94 MAF_left[47] = MAF_left[46];
Margreeth95 25:5e9cc994cd1f 95 MAF_left[46] = MAF_left[45];
Margreeth95 25:5e9cc994cd1f 96 MAF_left[45] = MAF_left[44];
Margreeth95 25:5e9cc994cd1f 97 MAF_left[44] = MAF_left[43];
Margreeth95 25:5e9cc994cd1f 98 MAF_left[43] = MAF_left[42];
Margreeth95 25:5e9cc994cd1f 99 MAF_left[42] = MAF_left[41];
Margreeth95 25:5e9cc994cd1f 100 MAF_left[41] = MAF_left[40];
Margreeth95 25:5e9cc994cd1f 101 MAF_left[40] = MAF_left[39];
Margreeth95 25:5e9cc994cd1f 102 MAF_left[39] = MAF_left[38];
Margreeth95 25:5e9cc994cd1f 103 MAF_left[38] = MAF_left[37];
Margreeth95 25:5e9cc994cd1f 104 MAF_left[37] = MAF_left[36];
Margreeth95 25:5e9cc994cd1f 105 MAF_left[36] = MAF_left[35];
Margreeth95 25:5e9cc994cd1f 106 MAF_left[35] = MAF_left[34];
Margreeth95 25:5e9cc994cd1f 107 MAF_left[34] = MAF_left[33];
Margreeth95 25:5e9cc994cd1f 108 MAF_left[33] = MAF_left[32];
Margreeth95 25:5e9cc994cd1f 109 MAF_left[32] = MAF_left[31];
Margreeth95 25:5e9cc994cd1f 110 MAF_left[31] = MAF_left[30];
Margreeth95 25:5e9cc994cd1f 111 MAF_left[30] = MAF_left[29];
Margreeth95 25:5e9cc994cd1f 112 MAF_left[29] = MAF_left[28];
Margreeth95 25:5e9cc994cd1f 113 MAF_left[28] = MAF_left[27];
Margreeth95 25:5e9cc994cd1f 114 MAF_left[27] = MAF_left[26];
Margreeth95 25:5e9cc994cd1f 115 MAF_left[26] = MAF_left[25];
Margreeth95 25:5e9cc994cd1f 116 MAF_left[25] = MAF_left[24];
Margreeth95 25:5e9cc994cd1f 117 MAF_left[24] = MAF_left[23];
Margreeth95 25:5e9cc994cd1f 118 MAF_left[23] = MAF_left[22];
Margreeth95 25:5e9cc994cd1f 119 MAF_left[22] = MAF_left[21];
Margreeth95 25:5e9cc994cd1f 120 MAF_left[21] = MAF_left[20];
Margreeth95 25:5e9cc994cd1f 121 MAF_left[20] = MAF_left[19];
Margreeth95 24:6661dd6a1718 122 MAF_left[19] = MAF_left[18];
Margreeth95 24:6661dd6a1718 123 MAF_left[18] = MAF_left[17];
Margreeth95 24:6661dd6a1718 124 MAF_left[17] = MAF_left[16];
Margreeth95 24:6661dd6a1718 125 MAF_left[16] = MAF_left[15];
Margreeth95 24:6661dd6a1718 126 MAF_left[15] = MAF_left[14];
Margreeth95 24:6661dd6a1718 127 MAF_left[14] = MAF_left[13];
Margreeth95 24:6661dd6a1718 128 MAF_left[13] = MAF_left[12];
Margreeth95 24:6661dd6a1718 129 MAF_left[12] = MAF_left[11];
Margreeth95 24:6661dd6a1718 130 MAF_left[11] = MAF_left[10];
Margreeth95 24:6661dd6a1718 131 MAF_left[10] = MAF_left[9];
Margreeth95 24:6661dd6a1718 132 MAF_left[9] = MAF_left[8];
Margreeth95 24:6661dd6a1718 133 MAF_left[8] = MAF_left[7];
Margreeth95 24:6661dd6a1718 134 MAF_left[7] = MAF_left[6];
Margreeth95 24:6661dd6a1718 135 MAF_left[6] = MAF_left[5];
Margreeth95 24:6661dd6a1718 136 MAF_left[5] = MAF_left[4];
Margreeth95 24:6661dd6a1718 137 MAF_left[4] = MAF_left[3];
Margreeth95 24:6661dd6a1718 138 MAF_left[3] = MAF_left[2];
Margreeth95 24:6661dd6a1718 139 MAF_left[2] = MAF_left[1];
Margreeth95 24:6661dd6a1718 140 MAF_left[1] = MAF_left[0];
Margreeth95 24:6661dd6a1718 141 MAF_left[0] = EMG_left_f6;
Margreeth95 24:6661dd6a1718 142 }
Margreeth95 24:6661dd6a1718 143
Margreeth95 18:12250e88037f 144 // HIDScope
Margreeth95 18:12250e88037f 145 void ScopeSend()
Margreeth95 18:12250e88037f 146 {
Margreeth95 19:34456a1effc4 147 scope.set(0, EMG_left_value);
Margreeth95 25:5e9cc994cd1f 148 scope.set(1, EMG_left_MAF);
Margreeth95 25:5e9cc994cd1f 149 scope.set(2, EMG_right_value);
Margreeth95 25:5e9cc994cd1f 150 scope.set(3, EMG_right_f2);
Margreeth95 25:5e9cc994cd1f 151 scope.set(4, EMG_right_f4);
Margreeth95 25:5e9cc994cd1f 152 scope.set(5, EMG_right_f6);
Margreeth95 18:12250e88037f 153 scope.send();
Margreeth95 18:12250e88037f 154 }
Margreeth95 18:12250e88037f 155
vsluiter 0:32bb76391d89 156 int main()
vsluiter 0:32bb76391d89 157 {
Margreeth95 18:12250e88037f 158 SampleEMG.attach(&EMGfilter, 0.002);
Margreeth95 18:12250e88037f 159 ScopeTimer.attach(&ScopeSend, 0.002);
Margreeth95 25:5e9cc994cd1f 160 MovingAverage.attach(&MovingAverageFilter, 0.005);
Margreeth95 19:34456a1effc4 161 while(1)
Margreeth95 19:34456a1effc4 162 {
Margreeth95 24:6661dd6a1718 163 if (EMG_left_f6 > Threshold1)
Margreeth95 19:34456a1effc4 164 {
Margreeth95 19:34456a1effc4 165 led.write(0);
Margreeth95 19:34456a1effc4 166 }
Margreeth95 19:34456a1effc4 167
Margreeth95 19:34456a1effc4 168 else
Margreeth95 19:34456a1effc4 169 {
Margreeth95 19:34456a1effc4 170 led.write(1);
Margreeth95 19:34456a1effc4 171 }
Margreeth95 19:34456a1effc4 172 }
vsluiter 0:32bb76391d89 173 }