emg2

Dependencies:   HIDScope biquadFilter mbed QEI

Fork of EMG by Tom Tom

Revision:
23:dec549767006
Parent:
22:bcfee9594007
Child:
24:6bdc50e21805
diff -r bcfee9594007 -r dec549767006 main.cpp
--- a/main.cpp	Mon Oct 29 19:38:48 2018 +0000
+++ b/main.cpp	Mon Oct 29 19:49:23 2018 +0000
@@ -5,30 +5,29 @@
 HIDScope scope( 2 );
 Ticker sample_timer;
 
-// inputs EMG
+// 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;
+// Constants 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;
 
-
+// Variables EMG
 double notchFitler1 = 0;
 double highpassFilter1 = 0;
 double lowpassFilter1 = 0;
@@ -36,7 +35,6 @@
 double highpassFilter2 = 0;
 double lowpassFilter2 = 0;
 
-
 // BiQuad values
 BiQuadChain notch;
 BiQuad N1( m1, m2, n0, n1, n2);
@@ -51,7 +49,6 @@
 BiQuad L2( c1, c2, d0, d1, d2);
 BiQuad L3( c1, c2, d0, d1, d2);
 
-
 // Filter of the first EMG signal
 void filter0()
 {
@@ -60,28 +57,36 @@
     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
+    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
+    
+    scope.set(0,emg0);
+    scope.set(1,low);
+    scope.send(); 
 }
 
-//Filter of the second EMG signal
+// Filter of the second EMG signal
 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
+    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
+    
+    //scope.set(3,emg1); 
+    //scope.set(4,low);
+    //scope.send(); 
 }
 
-//Filter of the third EMG signal
+// Filter of the third EMG signal
 void filter2()
 {
     double emg2;
@@ -89,14 +94,18 @@
     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
+    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
+    
+    //scope.set(5,emg2);
+    //scope.set(6,low);
+    //scope.send(); 
 }
 
-//Combining the filters in one fuction
+// Combining the filters in one fuction
 void filtered_emg()
 {
     filter0();
@@ -104,11 +113,9 @@
     filter2();
 }
 
-
 int main() 
 {  
-    sample_timer.attach(&filter0, 0.002);
+    sample_timer.attach(&filter0, 0.002); //filter0 can be changed to signal 1 of 2
 
-    while(1) {
-        }
+    while(1) {}
 }
\ No newline at end of file