working version but stripped of most unnecessary code like print statements

Dependencies:   HIDScope MODSERIAL biquadFilter mbed FastPWM QEI

Files at this revision

API Documentation at this revision

Comitter:
RiP
Date:
Tue Oct 18 15:29:45 2016 +0000
Parent:
20:97059009a491
Child:
22:f38a15e851d2
Commit message:
3 emg signals+ filtering;

Changed in this revision

EMG.lib Show annotated file Show diff for this revision Revisions of this file
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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EMG.lib	Tue Oct 18 15:29:45 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/tomlankhorst/code/EMG/#97059009a491
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/biquadFilter.lib	Tue Oct 18 15:29:45 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/tomlankhorst/code/biquadFilter/#26861979d305
--- a/main.cpp	Thu Sep 22 08:53:50 2016 +0000
+++ b/main.cpp	Tue Oct 18 15:29:45 2016 +0000
@@ -1,37 +1,91 @@
 #include "mbed.h"
 #include "HIDScope.h"
+#include "BiQuad.h"
 
 //Define objects
-AnalogIn    emg0( A0 );
-AnalogIn    emg1( A1 );
+AnalogIn    emg1( A0 );
+AnalogIn    emg2( A1 );
+AnalogIn    emg3( A2 );
 
 Ticker      sample_timer;
-HIDScope    scope( 2 );
+HIDScope    scope( 6 );
 DigitalOut  led(LED1);
 
-/** Sample function
- * this function samples the emg and sends it to HIDScope
- **/
+BiQuadChain bqc11;
+BiQuadChain bqc13;
+BiQuadChain bqc21;
+BiQuadChain bqc23;
+BiQuadChain bqc31;
+BiQuadChain bqc33;
+//BiQuad bq11( 9.87589e-01, -1.59795e+00, 9.87589e-01, -1.59795e+00, 9.75178e-01 ); //oude BiQuad waardes
+/*  BiQuads for filter emg1
+    notch filter*/
+BiQuad bq111(0.9795,   -1.5849,    0.9795,    1.0000,   -1.5849,    0.9589);
+BiQuad bq112(0.9833,   -1.5912,    0.9833,    1.0000,   -1.5793,    0.9787);
+BiQuad bq113(0.9957,   -1.6111,    0.9957,    1.0000,   -1.6224,    0.9798);
+/*  High pass filter*/
+BiQuad bq121( 9.56543e-01, -1.91309e+00, 9.56543e-01, -1.91120e+00, 9.14976e-01 );
+/*  low pass filter*/
+BiQuad bq131( 3.91302e-05, 7.82604e-05, 3.91302e-05, -1.98223e+00, 9.82385e-01 );
+
+
+/*  BiQuads for filter emg2
+    notch filter*/
+BiQuad bq211(0.9795,   -1.5849,    0.9795,    1.0000,   -1.5849,    0.9589);
+BiQuad bq212(0.9833,   -1.5912,    0.9833,    1.0000,   -1.5793,    0.9787);
+BiQuad bq213(0.9957,   -1.6111,    0.9957,    1.0000,   -1.6224,    0.9798);
+/*  High pass filter*/
+BiQuad bq221( 9.56543e-01, -1.91309e+00, 9.56543e-01, -1.91120e+00, 9.14976e-01 );
+/*  low pass filter*/
+BiQuad bq231( 3.91302e-05, 7.82604e-05, 3.91302e-05, -1.98223e+00, 9.82385e-01 );
+
+/*  BiQuads for filter emg3
+    notch filter*/
+BiQuad bq311(0.9795,   -1.5849,    0.9795,    1.0000,   -1.5849,    0.9589);
+BiQuad bq312(0.9833,   -1.5912,    0.9833,    1.0000,   -1.5793,    0.9787);
+BiQuad bq313(0.9957,   -1.6111,    0.9957,    1.0000,   -1.6224,    0.9798);
+/*  High pass filter*/
+BiQuad bq321( 9.56543e-01, -1.91309e+00, 9.56543e-01, -1.91120e+00, 9.14976e-01 );
+/*  low pass filter*/
+BiQuad bq331( 3.91302e-05, 7.82604e-05, 3.91302e-05, -1.98223e+00, 9.82385e-01 );
+
 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() );
-    /* 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 */
+    /* Read the emg signals and filter it*/
+    
+    scope.set(0, emg1.read());    //original signal
+    double emg02=bqc13.step(fabs(bqc11.step(emg1.read())));
+    scope.set(1, emg02);
+    /* Read the second emg signal and filter it*/
+    scope.set(2, emg2.read());    //original signal
+    double emg12=bqc23.step(fabs(bqc21.step(emg2.read())));
+    scope.set(3, emg12);
+    /* Read the third emg signal and filter it*/
+    scope.set(4, emg3.read());    //original signal
+    double emg22=bqc33.step(fabs(bqc31.step(emg3.read())));
+    scope.set(5, emg22);
+
+    /*   Ensure that enough channels are available (HIDScope scope( 2 ))
+     *   Finally, send all channels to the PC at once */
     scope.send();
-    /* To indicate that the function is working, the LED is toggled */
+    /*   To indicate that the function is working, the LED is toggled */
     led = !led;
 }
 
 int main()
-{   
-    /**Attach the 'sample' function to the timer 'sample_timer'.
-    * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
+{
+    //de biquad chains instellen
+    bqc11.add( &bq111 ).add( &bq112 ).add( &bq113 ).add( &bq121 );
+    bqc13.add( &bq131);
+    bqc21.add( &bq211 ).add( &bq212 ).add( &bq213 ).add( &bq221 );
+    bqc23.add( &bq231);
+    bqc31.add( &bq311 ).add( &bq312 ).add( &bq313 ).add( &bq321 );
+    bqc33.add( &bq331);
+    /*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);
 
-    /*empty loop, sample() is executed periodically*/
+    /* empty loop, sample() is executed periodically*/
     while(1) {}
 }
\ No newline at end of file
--- a/mbed.bld	Thu Sep 22 08:53:50 2016 +0000
+++ b/mbed.bld	Tue Oct 18 15:29:45 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/abea610beb85
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92
\ No newline at end of file