De EMG Lowpass maakt alle signalen gelijk

Dependencies:   HIDScope biquadFilter mbed

Fork of EMGfilter by Pascal van Baardwijk

Revision:
7:a928724ef731
Parent:
6:da06585e106c
Child:
8:dc0858fead9f
Child:
9:81637351bbd1
--- a/main.cpp	Tue Oct 25 20:38:53 2016 +0000
+++ b/main.cpp	Thu Oct 27 09:57:26 2016 +0000
@@ -8,31 +8,25 @@
 states state = STATE_DEFAULT;
 
 //Creating two scope channels
-HIDScope scope(3);
-
-//Low-pass filter at 200Hz to avoid alliasing
-BiQuadChain low_pass_200;
-BiQuad bq1(  0.73638326364, 1.47272205824, 0.73638326364, 1.36239603912, 0.48048795767);
-BiQuad bq2(  0.83856791742, 1.67684080778, 0.83856791742, 1.68114429812, 0.7942832489);
+HIDScope scope(4);
 
 //Notch filter
 BiQuadChain notch_50;
-BiQuad bq3( 1.00007369335,-1.61815834791, 1.00007369335, -1.60983662066, 0.98986119869);
-BiQuad bq4( 1.00000000000,-1.61803910919, 1.00000000000, -1.60936554071, 0.99545624832);
-BiQuad bq5( 0.99035034846,-1.60242559561, 0.99035034846, -1.61934542233, 0.9955088075);
+BiQuad bq3( 0.98116526140, 0.00000000044, 0.98116526140, 0.00000000043, 0.95391787621);
+BiQuad bq4( 0.97224232015, 0.00000000043, 0.97224232015, -0.04036799459, 0.97670000725);
+BiQuad bq5( 1.00000000000, 0.00000000044, 1.00000000000, 0.04036799547, 0.9767000072);
 
 //High pass filter
 BiQuadChain high_pass;
-BiQuad bq6( 0.83315051810,-1.66630103620, 0.83315051810, -1.55025104412, 0.60696783282);
-BiQuad bq7( 0.86554941044,-1.73109882088, 0.86554941044, -1.74142633961, 0.78400451004);
-BiQuad bq8( 0.92490714701,-1.84981429401, 0.92490714701, -1.90032503529, 0.9352152620);
+BiQuad bq6( 0.80254782780,-1.60509565560, 0.80254782780, -1.58011656361, 0.63006219630);
+BiQuad bq7( 0.90006571973,-1.80013143945, 0.900065719734, -1.77213098592, 0.8281459694);
+//BiQuad bq8( 0.92490714701,-1.84981429401, 0.92490714701, -1.90032503529, 0.9352152620);
 
 //Low pass filter
 BiQuadChain low_pass;
-BiQuad bq9( 0.00040400257, 0.00080800515, 0.00040400257,-1.92223307595, 0.92384908624);
-BiQuad bq10( 0.00040816681, 0.00081633362, 0.00040816681,-1.94204639240, 0.94367905964);
-BiQuad bq11( 0.00041558628, 0.00083117256, 0.00041558628,-1.97734803172, 0.9790103768);
-
+BiQuad bq9( 0.00801840797, 0.01603681594, 0.00801840797,-1.65212256130, 0.68416767240);
+BiQuad bq10( 0.00836524486, 0.01673048973, 0.00836524486,-1.72511837232, 0.75857933411);
+BiQuad bq11( 0.00905039996, 0.01810079992, 0.00905039996,-1.86807725180, 0.9043110909);
 //Ticker
 Ticker emgSampleTicker;
 
@@ -60,7 +54,7 @@
 double min_emg[3];
 double max_emg[3];
 
-const int n = 200;
+const int n = 100;
 int counter = 0;
 double RMSArray0[n] = {0};
 double RMSArray1[n] = {0};
@@ -97,15 +91,14 @@
 
 int main() {
     //combine biquads in biquad chains for notch/high- low-pass filters
-    low_pass_200.add( &bq1 ).add( &bq2 );
     notch_50.add( &bq3 ).add( &bq4 ).add( &bq5 );
-    high_pass.add( &bq6 ).add( &bq7 ).add( &bq8 );
+    high_pass.add( &bq6 ).add( &bq7 );
     low_pass.add( &bq9 ).add( &bq10 ).add( &bq11 );
     led.write(1);
     
     change_state.attach( &calibrate,5);
     change_state2.attach( &run,15);
-    emgSampleTicker.attach( &emgSample, 0.002);
+    emgSampleTicker.attach( &emgSample, 0.005); //200Hz
     while( true ){
         if(go_emgSample == true){
             EMG_filter();
@@ -121,19 +114,14 @@
             emg_sample[1] = emg1.read();
             emg_sample[2] = emg2.read();
             
-            for (int i = 0; i < 3; i++){
-                //low pass at 200Hz to avoid alliasing
-                emg_low_passed_200[i] = low_pass_200.step(emg_sample[i]);
-                
-                //filter out the 50Hz components with a notch filter
-                emg_notch[i] = notch_50.step(emg_low_passed_200[i]);
+            //filter out the 50Hz components with a notch filter
+            emg_notch[0] = notch_50.step(emg_sample[0]);
             
-                //high pass the signal (removing motion artifacts and offset)
-                emg_high_passed[i] = high_pass.step(emg_notch[i]);
+            //high pass the signal (removing motion artifacts and offset)
+            emg_high_passed[0] = high_pass.step(emg_notch[0]);
                 
-                //low pass the rectified emg signal
-                emg_low_passed[i] = low_pass.step(fabs(emg_high_passed[i]));
-            }
+            //low pass the rectified emg signal
+            emg_low_passed[0] = low_pass.step(fabs(emg_high_passed[0]));
             
             //Calculating RMS
             SumRMS0 -= pow(RMSArray0[counter],2);
@@ -203,8 +191,10 @@
             
             //Send scope data
             scope.set(0,emg_sample[0]);
-            scope.set(1,RMS0);
-            scope.set(2,emg_low_passed[0]);
+            scope.set(1,emg_notch[0]);
+            scope.set(2,emg_high_passed[0]);
+            scope.set(3,emg_low_passed[0]);
+            //scope.set(2,emg_low_passed[0]);
             //scope.set(3,input_force2);
             scope.send();