EMG filteren

Dependencies:   HIDScope biquadFilter mbed

Revision:
1:082004527d2e
Parent:
0:55a2b57fd35d
Child:
2:5a5a54374f80
--- a/main.cpp	Wed Oct 10 14:44:04 2018 +0000
+++ b/main.cpp	Thu Oct 11 07:56:45 2018 +0000
@@ -8,8 +8,9 @@
 
 Ticker      sample_timer;
 HIDScope    scope( 4 );
-DigitalOut  led(LED1);
-//DigitalOut  ledgreen(LED_GREEN);
+DigitalOut  ledred(LED1);
+DigitalOut  ledgreen(LED_GREEN);
+
 
 //------------Filter parameters----------------------
 
@@ -39,14 +40,23 @@
 BiQuadChain BiQuad_filter;
 float Signal;
 float Signal_filtered;
- 
+float Signal_filtered_HP;
+float Signal_filtered_fabs;
+
+
 
 /** Sample function
  * this function samples the emg and sends it to HIDScope
  **/
-void sample()
-{   
-//Hierna kijken !
+void sample_filter()
+{
+    Signal = emg0;
+    Signal_filtered_HP = HP2.step(Signal);
+    Signal_filtered_fabs = fabs(Signal_filtered_HP);
+    Signal_filtered = LP1.step(Signal_filtered_fabs);
+
+ 
+//Poging tot goed filter
     //Signal = emg0-emg1;
 //    BiQuad_filter.add(&LP);
 //    Signal_filtered = BiQuad_filter.step(Signal);
@@ -65,7 +75,7 @@
     *  Finally, send all channels to the PC at once */
     scope.send();
     /* To indicate that the function is working, the LED is toggled */
-    led = !led;
+    ledred = !ledred;
 }
 
 //----------Parameters voor filter----------
@@ -85,12 +95,21 @@
     /**Attach the 'sample' function to the timer 'sample_timer'.
     * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
     */
-    BiQuad_filter.add( &LP1 ).add( &HP2 );//.add( &NO3);
+    
+    sample_timer.attach(&sample_filter, 0.002);
     
-    sample_timer.attach(&sample, 0.002);
-
     /*empty loop, sample() is executed periodically*/
-    while(1) {}
+    while(1) {
+        
+        if (Signal_filtered > 0.1)
+        {   ledgreen = 0;
+        }
+        else {
+            ledgreen = 1;
+            }
+        
+        
+        }
     }
     
        
\ No newline at end of file