code for converting EMG signal to an usable signal for controlling the motors
Dependencies: HIDScope biquadFilter mbed MODSERIAL
Diff: main.cpp
- Revision:
- 7:87d9904c1c19
- Parent:
- 6:ec965bb75d40
diff -r ec965bb75d40 -r 87d9904c1c19 main.cpp --- a/main.cpp Tue Oct 27 10:35:00 2015 +0000 +++ b/main.cpp Tue Oct 27 10:49:59 2015 +0000 @@ -44,7 +44,7 @@ //pc.printf("emg signal %f, filtered signal %f \n",emg_value,onoffsignal); } } -void checkmotor(){ +void checkmotor(){//check the normalized signal and set actions if a threshold is passed if(calyes==1){ if(onoffsignal<=0.25){ led1.write(1); @@ -57,9 +57,9 @@ } } -void calibri(){ +void calibri(){//calibration function if(button1.read()==false){ - for(int n =0; n<5000;n++){ + for(int n =0; n<5000;n++){//read for 5000 samples as calibration emg_value = emg.read();//read the emg value from the elektrodes signalpart1 = notch.step(emg_value);//Highpass filter for removing offset and artifacts signalpart2 = filterhigh1.step(signalpart1);//rectify the filtered signal @@ -67,13 +67,11 @@ signalpart4 = filterlow1.step(signalpart3);//notch filter to remove 50Hz signal signalfinal = filterlow2.step(signalpart4);//2nd low pass filter to envelope the emg double signalmeasure = signalfinal; - pc.printf("%f \n", signalmeasure); - if (signalmeasure > maxcal){ + if (signalmeasure > maxcal){//determine what the highest reachable emg signal is maxcal = signalmeasure; } } calyes=1; - pc.printf("the max emg value is %f and calyes is %d", maxcal, calyes); } } int main() @@ -88,6 +86,6 @@ while(1){ - + //random while loop to keep system going } } \ No newline at end of file