Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of EMG_converter_code by
Revision 12:86b3885a6308, committed 2015-10-28
- Comitter:
- Technical_Muffin
- Date:
- Wed Oct 28 13:14:16 2015 +0000
- Parent:
- 11:8196434745b4
- Commit message:
- Working emg movement code. Apparently biquads need to be doubled and at seperate locations
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8196434745b4 -r 86b3885a6308 main.cpp
--- a/main.cpp Wed Oct 28 11:46:55 2015 +0000
+++ b/main.cpp Wed Oct 28 13:14:16 2015 +0000
@@ -11,7 +11,7 @@
Ticker motor_timer1;
Ticker motor_timer2;
Ticker cal_timer;
-HIDScope scope(4); // Instantize a 2-channel HIDScope object
+HIDScope scope(5); // Instantize a 2-channel HIDScope object
DigitalIn button1(PTA4);//test button for starting motor 1
DigitalOut led1(LED_RED);
DigitalOut led2(LED_BLUE);
@@ -29,7 +29,13 @@
biquadFilter filterhigh1(-1.4542, 0.5741, 0.7571, -1.5142, 0.7571);
biquadFilter filterlow1(0.4395, 0.2059, 0.4114, 0.8227, 0.4114);
biquadFilter notch(-1.0958, 0.9723, 0.9862, -1.0958, 0.9862);
-biquadFilter filterlow2(-1.4542, 0.5741, 0.0300, 0.0599, 0.0300);
+biquadFilter filterlow2(-1.9722, 0.9726, 9.50600294492288e-05, 0.000190120058898458, 9.50600294492288e-05);
+
+biquadFilter filterhigh12(-1.4542, 0.5741, 0.7571, -1.5142, 0.7571);
+biquadFilter filterlow12(0.4395, 0.2059, 0.4114, 0.8227, 0.4114);
+biquadFilter notch2(-1.0958, 0.9723, 0.9862, -1.0958, 0.9862);
+biquadFilter filterlow22(-1.9722, 0.9726, 9.50600294492288e-05, 0.000190120058898458, 9.50600294492288e-05);
+
double emg_value1;
double signalpart11;
double signalpart12;
@@ -46,6 +52,8 @@
double signalfinal2;
double onoffsignal2;
+double test;
+
double maxcal=1;
bool calyes=1;
@@ -72,46 +80,51 @@
emg_value1 = emg1.read();//read the emg value from the elektrodes
signalpart11 = notch.step(emg_value1);//Highpass filter for removing offset and artifacts
signalpart12 = filterhigh1.step(signalpart11);//rectify the filtered signal
- signalpart13 = abs(signalpart12);//low pass filter to envelope the emg
+ signalpart13 = fabs(signalpart12);//low pass filter to envelope the emg
signalpart14 = filterlow1.step(signalpart13);//notch filter to remove 50Hz signal
signalfinal1 = filterlow2.step(signalpart14);//2nd low pass filter to envelope the emg
onoffsignal1=signalfinal1/maxcal;//divide the emg signal by the max EMG to calibrate the signal per person
//pc.printf("the emg 1 signal is: %f \n",onoffsignal1);
- emg_value2 = emg2.read();//read the emg value from the elektrodes
+ /*emg_value2 = emg2.read();//read the emg value from the elektrodes
signalpart21 = notch.step(emg_value2);//Highpass filter for removing offset and artifacts
signalpart22 = filterhigh1.step(signalpart21);//rectify the filtered signal
signalpart23 = abs(signalpart22);//low pass filter to envelope the emg
signalpart24 = filterlow1.step(signalpart23);//notch filter to remove 50Hz signal
signalfinal2 = filterlow2.step(signalpart24);//2nd low pass filter to envelope the emg
- onoffsignal2=signalfinal2/maxcal;//divide the emg signal by the max EMG to calibrate the signal per person
-
+ onoffsignal2=signalfinal2/maxcal;*///divide the emg signal by the max EMG to calibrate the signal per person
+ //test=onoffsignal2-onoffsignal1;
scope.set(0,emg_value1);//set emg signal to scope in channel 1
scope.set(1,onoffsignal1);//set filtered signal to scope in channel 2
- scope.set(2,emg_value2);//set emg signal to scope in channel 1
- scope.set(3,onoffsignal2);//set filtered signal to scope in channel 2
- scope.send();//send the signals to the scope
- //pc.printf("the emg 2 signal is: %f \n",onoffsignal2);
+ //scope.set(2,emg_value2);//set emg signal to scope in channel 3
+ //scope.set(3,onoffsignal2);//set filtered signal to scope in channel 4
+ //scope.set(4,test);
+ //scope.send();//send the signals to the scope
+
+ //pc.printf("the difference between the 2 signals is: %f \n",test);
//pc.printf("emg signal %f, filtered signal %f \n",emg_value,onoffsignal);
}
}
-/*
+
+
void filter2(){
if(calyes==1){
emg_value2 = emg2.read();//read the emg value from the elektrodes
- signalpart21 = notch.step(emg_value2);//Highpass filter for removing offset and artifacts
- signalpart22 = filterhigh1.step(signalpart21);//rectify the filtered signal
- signalpart23 = abs(signalpart22);//low pass filter to envelope the emg
- signalpart24 = filterlow1.step(signalpart23);//notch filter to remove 50Hz signal
- signalfinal2 = filterlow2.step(signalpart24);//2nd low pass filter to envelope the emg
+ signalpart21 = notch2.step(emg_value2);//Highpass filter for removing offset and artifacts
+ signalpart22 = filterhigh12.step(signalpart21);//rectify the filtered signal
+ signalpart23 = fabs(signalpart22);//low pass filter to envelope the emg
+ signalpart24 = filterlow12.step(signalpart23);//notch filter to remove 50Hz signal
+ signalfinal2 = filterlow22.step(signalpart24);//2nd low pass filter to envelope the emg
onoffsignal2=signalfinal2/maxcal;//divide the emg signal by the max EMG to calibrate the signal per person
scope.set(2,emg_value2);//set emg signal to scope in channel 1
scope.set(3,onoffsignal2);//set filtered signal to scope in channel 2
- pc.printf("the emg 2 signal is: %f \n",onoffsignal2);
- scope.send();//send the signals to the scope
+ //pc.printf("the emg 2 signal is: %f \n",onoffsignal2);
+ scope.send();//send the signals to the scope
//pc.printf("emg signal %f, filtered signal %f \n",emg_value,onoffsignal);
}
-}*/
+}
+
+
/*
void checkmotor1(){//check the normalized signal and set actions if a threshold is passed not needed in ticker move to main function
@@ -193,7 +206,7 @@
speed1.write(0);
speed2.write(0);
sample_timer1.attach(filter1, 0.003125);//continously execute the EMG reader and filter
-// sample_timer2.attach(&filter2, 0.005);//continously execute the EMG reader and filter
+ sample_timer2.attach(filter2, 0.003125);//continously execute the EMG reader and filter
//motor_timer1.attach(&checkmotor1, 0.002);//continously execute the motor controller
//motor_timer2.attach(&checkmotor2, 0.002);//continously execute the motor controller
// cal_timer.attach(&calibri, 0.002);//ticker to check if motor is being calibrated
