emg2

Dependencies:   HIDScope biquadFilter mbed QEI

Fork of EMG by Tom Tom

Revision:
21:931fe86dbf5a
Parent:
20:97059009a491
Child:
22:bcfee9594007
--- a/main.cpp	Thu Sep 22 08:53:50 2016 +0000
+++ b/main.cpp	Mon Oct 29 19:09:11 2018 +0000
@@ -1,37 +1,119 @@
 #include "mbed.h"
 #include "HIDScope.h"
+#include "BiQuad.h"
 
-//Define objects
-AnalogIn    emg0( A0 );
-AnalogIn    emg1( A1 );
+// inputs EMG
+AnalogIn emg0_in( A0 );
+AnalogIn emg1_in( A1 );
+AnalogIn emg2_in( A2 );
+
+ 
+// Variabelen EMG
+const double m1 =0.5000;
+const double m2 =-0.8090;
+const double n0 =0.5000;
+const double n1 =-0.8090;
+const double n2 =0;
+const double a1 =0.9565;
+const double a2 =-1.9131;
+const double b0 =0.9565;
+const double b1 =-1.9112;
+const double b2 =0.9150;
+const double c1 =0.0675;
+const double c2 =0.1349;
+const double d0 =0.0675;
+const double d1 =-1.1430;
+const double d2 =0.4128;
+
 
-Ticker      sample_timer;
-HIDScope    scope( 2 );
-DigitalOut  led(LED1);
+double notchFitler1 = 0;
+double highpassFilter1 = 0;
+double lowpassFilter1 = 0;
+double notchFilter2 = 0;
+double highpassFilter2 = 0;
+double lowpassFilter2 = 0;
+
+
+// BiQuad values
+BiQuadChain notch;
+BiQuad N1( m1, m2, n0, n1, n2);
+BiQuad N2( m1, m2, n0, n1, n2);
+BiQuad N3( m1, m2, n0, n1, n2);
+BiQuadChain highpass;
+BiQuad H1( a1, a2, b0, b1, b2);
+BiQuad H2( a1, a2, b0, b1, b2);
+BiQuad H3( a1, a2, b0, b1, b2);
+BiQuadChain lowpass;
+BiQuad L1( c1, c2, d0, d1, d2);
+BiQuad L2( c1, c2, d0, d1, d2);
+BiQuad L3( c1, c2, d0, d1, d2);
+
+
+
 
-/** Sample function
- * this function samples the emg and sends it to HIDScope
- **/
-void sample()
+// Filteren
+void filter0()
 {
-    /* 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 */
+    double emg0;
+    double notch;
+    double high;
+    double absolute;
+    double low;
+    emg0 = emg0_in.read(); //reading the EMG signal
+    notch = N1.step(emg0); //Applying a notch filter over the EMG data
+    high = H1.step(notch); //Applying a high pass filter
+    absolute = fabs(high); //Rectifying the data
+    low = L1.step(absolute); //Applying low pass filter
+    filter0();
+
+    Ticker      sample_timer;
+    HIDScope    scope( 2 );
+
+    scope.set(0, emg0_in.read() );
+    scope.set(1, low);
     scope.send();
-    /* To indicate that the function is working, the LED is toggled */
-    led = !led;
+
+}
+ 
+
+void filter1()
+{
+    double emg1;
+    double notch;
+    double high;
+    double absolute;
+    double low;
+    emg1 = emg1_in.read(); //reading the EMG signal
+    notch = N2.step(emg1); //Applying a notch filter over the EMG data
+    high = H2.step(notch); //Applying a high pass filter
+    absolute = fabs(high); //Rectifying the data
+    low = L2.step(absolute); //Applying low pass filter
+}
+void filter2()
+{
+    double emg2;
+    double notch;
+    double high;
+    double absolute;
+    double low;
+    emg2 = emg2_in.read(); //reading the EMG signal
+    notch = N3.step(emg2); //Applying a notch filter over the EMG data
+    high = H3.step(notch); //Applying a high pass filter
+    absolute = fabs(high); //Rectifying the data
+    low = L3.step(absolute); //Applying low pass filter
 }
 
-int main()
-{   
-    /**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);
+void filtered_emg()
+{
+}
+
 
-    /*empty loop, sample() is executed periodically*/
-    while(1) {}
+int main() 
+{  
+    Ticker sample_timer;
+    filter0();
+    sample_timer.attach(filter0, 0.002);
+
+    while(1) {
+        }
 }
\ No newline at end of file