Bandpass, notch, abs en laagdoorlaat 3Hz

Dependencies:   HIDScope MODSERIAL mbed-dsp mbed TextLCD

Files at this revision

API Documentation at this revision

Comitter:
lauradeheus
Date:
Wed Oct 29 16:12:34 2014 +0000
Parent:
3:c82170d8b6c8
Child:
5:f93b7068c202
Commit message:
Bandpass-notch-abs-laagdoorlaat-pieken tellen werkt

Changed in this revision

EMGmeten.cpp Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
--- a/EMGmeten.cpp	Wed Oct 29 08:57:43 2014 +0000
+++ b/EMGmeten.cpp	Wed Oct 29 16:12:34 2014 +0000
@@ -2,28 +2,46 @@
 #include "HIDScope.h"
 #include "arm_math.h"
 #include "MODSERIAL.h"
+#include "TextLCD.h"
+
+#define EMG_treshhold 0,05
 
 //MODSERIAL pc(USBTX,USBRX);
 AnalogIn    emg(PTB1); //Analog input
-HIDScope scope(2);
+HIDScope scope(2); // Twee kanalen op de HIDScope
+DigitalIn knop(PTD4); /*Digital input pin (knop) definieren*/
+TextLCD lcd(PTD2, PTA12, PTB2, PTB3, PTC2, PTA13, TextLCD::LCD16x2);
 
-arm_biquad_casd_df1_inst_f32 lowpass_1; //99Hz
-arm_biquad_casd_df1_inst_f32 lowpass_2; //3Hz
-arm_biquad_casd_df1_inst_f32 highpass; //20Hz
-arm_biquad_casd_df1_inst_f32 notch; //50Hz
+arm_biquad_casd_df1_inst_f32 lowpass_1; //2e orde lowpass biquad butterworthfilter 99Hz
+arm_biquad_casd_df1_inst_f32 lowpass_2; //2e orde lowpass biquad butterworthfilter 3Hz
+arm_biquad_casd_df1_inst_f32 highpass; //2e orde highpass biquad butterworthfilter 20Hz
+arm_biquad_casd_df1_inst_f32 notch; //2e orde lowpass biquad butterworthfilter 50Hz
 float lowpass_1_const[] = {0.978030479206560 , 1.956060958413119 , 0.978030479206560 , -1.955578240315036 , -0.956543676511203};
 float lowpass_1_states[4];
-float lowpass_2_const[] = {0.002080567135492 , 0.004161134270985 , 0.002080567135492 , 1.866892279711715 , -0.875214548253684};
+float lowpass_2_const[] = {0.002080567135492 , 0.004161134270985 , 0.002080567135492 , 1.866892279711715 , -0.875214548253684}; //3Hz
+    //{0.0009446914586925257 , 0.0018893829173850514 , 0.0009446914586925257 , 1.911196288237583 , -0.914975054072353};//2Hz
+    //{0.00024135899874854145 , 0.0004827179974970829 , 0.00024135899874854145 , 1.9555778328194147 , -0.9565432688144089}; 1Hz
 float lowpass_2_states[4];
 float highpass_const[] = {0.638945525159022 , -1.277891050318045 ,  0.638945525159022 , 1.142980502539901 , -0.412801598096189};
 float highpass_states[4];
 float notch_const[] = {0.978048948305681 , 0.000000000000000 , 0.978048948305681 , 0.000000000000000 , -0.956097896611362};
 float notch_states[4];
+float filtered_emg;
+float EMG_max = 0.16;
+float EMG_treshhold_laag = 0.3*EMG_max;
+float EMG_treshhold_hoog = 0.7*EMG_max;
+
+bool aanspan;
+int aantal_pieken;
+
+void looper();
+void pieken_tellen();
+//char *lcd_r1 = new char[16];
+//char *lcd_r2 = new char[16];
 
 void looper()
 {
     uint16_t emg_value;
-    float filtered_emg;
     float emg_value_f32;
     emg_value = emg.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V)
     emg_value_f32 = emg.read();
@@ -34,6 +52,19 @@
     filtered_emg = fabs(filtered_emg);
     //emg_value_f32 = fabs(emg_value_f32);
     arm_biquad_cascade_df1_f32(&lowpass_2, &filtered_emg, &filtered_emg, 1 );
+      
+    void pieken_tellen();
+    {
+        if (filtered_emg>=EMG_treshhold_hoog) 
+        {
+            aanspan=true; //maak een variabele waarin je opslaat dat het signaal hoog is.
+        }
+        if (aanspan==true && filtered_emg<=EMG_treshhold_laag)//== ipv =, anders wordt aanspan true gemaakt
+        {
+            aanspan=false;
+            aantal_pieken++;
+        }
+    }
     
     scope.set(0,emg_value);     //uint value
     scope.set(1,filtered_emg);  //processed float
@@ -53,10 +84,12 @@
     
     while(1) //Loop
     {
+        lcd.cls();
+        lcd.printf("Aantal pieken =\n%d", aantal_pieken);
+        wait(0.02);
       /*Empty!*/
       /*Everything is handled by the interrupt routine now!*/
       //pc.baud(9600);
-      //pc.printf("filtered_emg=%f\n\r",filtered_emg);
     }
 }
     
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Oct 29 16:12:34 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#e4cb7ddee0d3