Code for emg filtering and thus controlling the robotic movement.

Dependencies:   HIDScope biquadFilter mbed

Fork of EMG by Tom Tom

Revision:
18:3175fbe48b40
Parent:
16:9f7797ffd0fb
--- 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) {}