EMG filtered

Dependencies:   HIDScope mbed

Fork of EMG by Tom Tom

Files at this revision

API Documentation at this revision

Comitter:
poephoofd
Date:
Mon Oct 09 10:32:30 2017 +0000
Parent:
22:c7ccfe13d168
Commit message:
Added abs and Low Pass Filter

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c7ccfe13d168 -r 5c304175d791 main.cpp
--- a/main.cpp	Mon Oct 09 10:10:15 2017 +0000
+++ b/main.cpp	Mon Oct 09 10:32:30 2017 +0000
@@ -2,16 +2,24 @@
 #include "HIDScope.h"
 
 //Define objects
-AnalogIn    EMGData1( A0 );
+AnalogIn    EMGData_1( A0 );
 AnalogIn    emg1( A1 );
 
 Ticker      sample_timer;
 HIDScope    scope( 2 );
 DigitalOut  led(LED1);
-volatile float EMGData_f1=0;
-double f_v1_EMG=0, f_v2_EMG=0; // set filter variables EMG 1
-const double M1_F_A1_EMG=-1.561018075800718, M1_F_A2_EMG=0.641351538057563, M1_F_B0_EMG=0.800592403464570, 
-M1_F_B1_EMG=-1.601184806929141, M1_F_B2_EMG=0.800592403464570;// set EMG filter coefficients 
+
+volatile float EMGData_1_HiFil=0;   //EMG Hi Filtered
+volatile float EMGData_1_HiFilAbs=0;    //EMG Hi Filtered abs
+volatile float EMGData_1_HiLoFil=0;   //EMG HiLo Filtered
+
+double f_v1_EMG_1_Hi=0, f_v2_EMG_1_Hi=0; // set Hi filter variables EMG 1
+const double M1_F_A1_EMG_Hi=-1.561018075800718, M1_F_A2_EMG_Hi=0.641351538057563, M1_F_B0_EMG_Hi=0.800592403464570, 
+M1_F_B1_EMG_Hi=-1.601184806929141, M1_F_B2_EMG_Hi=0.800592403464570;// set EMG filter coefficients 
+
+double f_v1_EMG_1_Lo=0, f_v2_EMG_1_Lo=0; // set Lo filter variables EMG 1
+const double M1_F_A1_EMG_Lo=-1.561018075800718, M1_F_A2_EMG_Lo=0.641351538057563, M1_F_B0_EMG_Lo=0.800592403464570, 
+M1_F_B1_EMG_Lo=-1.601184806929141, M1_F_B2_EMG_Lo=0.800592403464570;    // set EMG filter coefficients 
 
 /** Sample function
  * this function samples the emg and sends it to HIDScope
@@ -29,11 +37,12 @@
 
 void sample()
 {
-    EMGData_f1 = IIRFilter(EMGData1, f_v1_EMG, f_v2_EMG, M1_F_A1_EMG, M1_F_A2_EMG, M1_F_B0_EMG, M1_F_B1_EMG, M1_F_B2_EMG);
-
+    EMGData_1_HiFil = IIRFilter(EMGData_1, f_v1_EMG_1_Hi, f_v2_EMG_1_Hi, M1_F_A1_EMG_Hi, M1_F_A2_EMG_Hi, M1_F_B0_EMG_Hi, M1_F_B1_EMG_Hi, M1_F_B2_EMG_Hi);
+    EMGData_1_HiFilAbs = abs(EMGData_1_HiFil);
+    EMGData_1_HiLoFil = IIRFilter(EMGData_1_HiFilAbs, f_v1_EMG_1_Lo, f_v2_EMG_1_Lo, M1_F_A1_EMG_Lo, M1_F_A2_EMG_Lo, M1_F_B0_EMG_Lo, M1_F_B1_EMG_Lo, M1_F_B2_EMG_Lo);
     /* 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, EMGData1);                            // set scope channel 0 EMG
-    scope.set(1, EMGData_f1);                           // set scope channel 1 EMG filtered
+    scope.set(0, EMGData_1);                            // set scope channel 0 EMG
+    scope.set(1, EMGData_1_HiLoFil);                           // set scope channel 1 EMG filtered
     /* 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 */