not checked because compiler was down, but this should do everything!!!!

Dependencies:   FastPWM HIDScope MODSERIAL QEI biquadFilter mbed

Fork of EMG4 by Remi van Veen

Revision:
21:136a1ab8163c
Parent:
20:97059009a491
Child:
22:68ab712b62b2
diff -r 97059009a491 -r 136a1ab8163c main.cpp
--- a/main.cpp	Thu Sep 22 08:53:50 2016 +0000
+++ b/main.cpp	Wed Nov 02 09:39:07 2016 +0000
@@ -1,22 +1,59 @@
 #include "mbed.h"
 #include "HIDScope.h"
+#include "BiQuad.h"
+#include "MODSERIAL.h"
 
 //Define objects
-AnalogIn    emg0( A0 );
-AnalogIn    emg1( A1 );
+AnalogIn    emg1_in( A0 );
+AnalogIn    emg2_in( A1 );
 
 Ticker      sample_timer;
-HIDScope    scope( 2 );
-DigitalOut  led(LED1);
+HIDScope    scope( 4 );
+DigitalOut  red(LED_RED);
+DigitalOut  blue(LED_BLUE);
+DigitalOut  green(LED_GREEN);
+MODSERIAL   pc(USBTX, USBRX);
+
+
+// EMG variables
+double emg1;
+double emg1highfilter;
+double emg1notchfilter;
+double emg1abs
+double emg1lowfilter;
+
+double emg2;
+double emg2highfilter;
+double emg2notchfilter;
+double emg2abs
+double emg2lowfilter;
 
-/** Sample function
- * this function samples the emg and sends it to HIDScope
- **/
+// Filter settings
+BiQuad filterhigh(9.704e-01,-1.9408,9.704e-01,-1.9389,9.427e-01);
+BiQuad filternotch(9.495e-01,-1.8062,9.495e-01,-1.8062,8.992e-01)
+BiQuad filterlow(8.883e-01,1.7671,8.835e-01,1.7227,8.114e-01)
+
+// Filtering
+void filter() {
+    emg1=emg1_in.read();
+    emg1highfilter=filterhigh.step(emg1);
+    emg1notchfilter=filternotch.step(emg1highfilter);
+    emg1abs=fabs(emg1notchfilter);
+    emg1lowfilter=filterlow(emg1abs);
+
+    emg2=emg2_in.read();
+    emg2highfilter=filterhigh.step(emg2);
+    emg2notchfilter=filternotch.step(emg2highfilter);
+    emg2abs=fabs(emg2notchfilter);
+    emg2lowfilter=filterlow(emg2abs);
+
 void sample()
 {
     /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
-    scope.set(0, emg0.read() );
-    scope.set(1, emg1.read() );
+    scope.set(0, emg1_in.read() );
+    scope.set(1, emg1lowfilter.read() );
+    scope.set(2, emg2_in.read() );
+    scope.set() emg2lowfilter.read() );
     /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) 
     *  Ensure that enough channels are available (HIDScope scope( 2 ))
     *  Finally, send all channels to the PC at once */
@@ -30,7 +67,7 @@
     /**Attach the 'sample' function to the timer 'sample_timer'.
     * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
     */
-    sample_timer.attach(&sample, 0.002);
+    sample_timer.attach(&sample, 0.001);
 
     /*empty loop, sample() is executed periodically*/
     while(1) {}