![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Code for emg filtering and thus controlling the robotic movement.
Dependencies: HIDScope biquadFilter mbed
Fork of EMG by
Revision 18:3175fbe48b40, committed 2015-10-21
- Comitter:
- Technical_Muffin
- Date:
- Wed Oct 21 06:45:08 2015 +0000
- Parent:
- 17:290d0b765a96
- Commit message:
- implemented biquad code, not yet tested if working
Changed in this revision
biquadFilter.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 290d0b765a96 -r 3175fbe48b40 biquadFilter.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biquadFilter.lib Wed Oct 21 06:45:08 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/tomlankhorst/code/biquadFilter/#e3bf917ae0a3
diff -r 290d0b765a96 -r 3175fbe48b40 main.cpp --- a/main.cpp Tue Sep 22 07:00:54 2015 +0000 +++ b/main.cpp Wed Oct 21 06:45:08 2015 +0000 @@ -1,10 +1,16 @@ #include "mbed.h" #include "HIDScope.h" +#include "biquadFilter.h" // Require the HIDScope library //Define objects AnalogIn emg(A0); //Analog input Ticker sample_timer; -HIDScope scope(1); +Ticker filter_timer +HIDScope scope(2); +biquadFilter filterhigh1(-1.1430 0.4128 0.6389 -1.2779 0.6389); +biquadFilter filterlow1(1.9556 0.9565 0.9780 1.9561 0.9780); +biquadFilter notch(-1.1978e-16 0.9561 0.9780 -1.1978e-16 0.9780); +biquadFilter filterlow2(-1.9645 0.9651 1.5515e-4 3.1030e-4 1.5515e-4); /** Sample function * this function samples the emg and sends it to HIDScope @@ -19,13 +25,21 @@ /* Finally, send all channels to the PC at once */ scope.send(); } - +void filtering() +{ +double signalpart1 = filterhigh1(emg.read()); +double signalpart2 = abs(signalpart1); +double signalpart3 = filterlow1(signalpart2); +double signalpart4 = notch(signalpart3); +double signalfinal = filterlow2(signalpart4); +scope.set(1,signalfinal); int main() { /**Attach the 'sample' function to the timer 'sample_timer'. * this ensures that 'sample' is executed every... 0.002 seconds */ sample_timer.attach(&sample, 0.002); + filter_timer.attach(&filtering, 0.002); /*empty loop, sample() is executed periodically*/ while(1) {}