Changed some stuff

Fork of EMG by Kevin Hetterscheid

Revision:
21:49362a17495b
Parent:
19:34c129b055b6
Child:
22:8c9dda710584
--- a/emg.cpp	Tue Oct 20 08:09:01 2015 +0000
+++ b/emg.cpp	Tue Oct 20 09:42:03 2015 +0000
@@ -3,16 +3,13 @@
 #include "emg.h"
 
 //Define objects
-AnalogIn    emg(A0); //Analog input
-Ticker      sample_timer;
+AnalogIn    emgIn0(A0); //Analog input
+AnalogIn    emgIn1(A1); //Analog input
+AnalogIn    emgIn2(A2); //Analog input
 HIDScope    scope(2);
 
 double highV[4];
 double lowV[4];
-// An array which stores the last MOV_AVG_NUM outputs
-double lastOutputs[MOV_AVG_NUM-1];
-// The sum of the last MOV_AVG_NUM outputs
-double outputSum;
 
 double filter(double input, double coeff_input[], double coeff_output[], double prev_outputs[])
 {
@@ -38,43 +35,25 @@
     return filter(u, fh_a, fh_b, highV);
 }
 
-double fl_b[]= {0.00000658, 0.00002631, 0.00003947, 0.00002631, 0.00000658};
-double fl_a[]= {1.0000, -3.7264, 5.2160, -3.2500, 0.7605};
+double fl_b[]= {0.00001329,    0.00005317,    0.00007976,   0.00005317,    0.00001329};
+double fl_a[]= {1.0000,   -3.6717,    5.0680,   -3.1160,    0.7199};
 double lowpass_filter(double u)
 {
     return filter(u, fl_a, fl_b, lowV);
 }
 
-void sample()
+/** Sample function
+ * this function samples the emg and sends it to HIDScope
+ **/
+double sample(int emgNum)
 {
-    double input = emg.read();
+    double input = 0.0;
+    if(emgNum == 1) input = emgIn1.read();
+    if(emgNum == 2) input = emgIn2.read();
+    else input = emgIn0.read();
     double output1 = highpass_filter(input);
     double output2 = fabs(output1);
     double output3 = lowpass_filter(output2);
     
-    /* Calculate the average of the last MOV_AVG_NUM outputs and the new input */
-    outputSum = outputSum - lastOutputs[MOV_AVG_NUM-2] + output3;
-    for(int i=0; i<MOV_AVG_NUM-1; i++) {
-        if(i != 0) lastOutputs[i] = lastOutputs[i-1];
-    }
-    lastOutputs[0] = output3;
-    output3 = outputSum/MOV_AVG_NUM;
-    
-    /* Second, set the sampled emg value in channel zero (the first channel) in the 'HIDScope' variable named 'scope' */
-    scope.set(0,input);
-    scope.set(1,output3);
-    /* Repeat the step above if required for more channels (channel 0 up to 5 = 6 channels) */
-    /* Finally, send all channels to the PC at once */
-    scope.send();
-}
-
-/*
-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);
-
-    //empty loop, sample() is executed periodically
-    while(1) {}
-}*/
\ No newline at end of file
+    return output3;
+}
\ No newline at end of file