Bandpass, notch, abs en laagdoorlaat 3H
Dependencies: HIDScope MODSERIAL TextLCD mbed-dsp mbed
Fork of EMGmeten by
Revision 8:4b275b1667d8, committed 2014-10-31
- Comitter:
- lauradeheus
- Date:
- Fri Oct 31 17:15:22 2014 +0000
- Parent:
- 7:0e76120eb7ad
- Commit message:
- Werkend_EMG plus pieken meten;
Changed in this revision
EMGmeten.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/EMGmeten.cpp Thu Oct 30 17:51:08 2014 +0000 +++ b/EMGmeten.cpp Fri Oct 31 17:15:22 2014 +0000 @@ -6,9 +6,9 @@ #define EMG_treshhold 0,05 -//MODSERIAL pc(USBTX,USBRX); +//Serial pc(USBTX,USBRX); AnalogIn emg(PTB1); //Analog input -HIDScope scope(2); // Twee kanalen op de HIDScope +HIDScope scope(3); // Twee kanalen op de HIDScope DigitalIn knop(PTD4); /*Digital input pin (knop) definieren*/ TextLCD lcd(PTD2, PTA12, PTB2, PTB3, PTC2, PTA13, TextLCD::LCD16x2); @@ -26,45 +26,94 @@ 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.15; -float EMG_treshhold_laag = 0.3*EMG_max; -float EMG_treshhold_hoog = 0.7*EMG_max; +float emg_filtered; +float emg_max=0.15; +float emg_treshhold_laag = 0.3*emg_max; +float emg_treshhold_hoog = 0.7*emg_max; bool aanspan; int aantal_pieken; int doel; -void looper(); +void emg_filtering(); void pieken_tellen(); -void EMG_max_meting(); +void emg_max_meting(); + +//void emg_max_meting(){ +// if (emg_filtered>=emg_max) +// { +// emg_max=emg_filtered; +// } +// emg_treshhold_laag = 0.3*emg_max; +// emg_treshhold_hoog = 0.7*emg_max; +//} + +void emg_filtering() { + uint16_t emg_value; + 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(); + + arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32, &emg_filtered, 1 ); + arm_biquad_cascade_df1_f32(&lowpass_1, &emg_filtered, &emg_filtered, 1 ); + arm_biquad_cascade_df1_f32(¬ch, &emg_filtered, &emg_filtered, 1); + emg_filtered = fabs(emg_filtered); + arm_biquad_cascade_df1_f32(&lowpass_2, &emg_filtered, &emg_filtered, 1 ); + + pieken_tellen(); + doel = aantal_pieken-((aantal_pieken/3)*3)+1; + + scope.set(0,emg_value); //uint value + scope.set(1,emg_filtered); //processed float + scope.set(2,doel); + scope.send(); + + lcd.cls(); + lcd.printf("Hallo"); +} + +void pieken_tellen(){ + if (emg_filtered>=emg_treshhold_hoog) + { + aanspan=true; //maak een variabele waarin je opslaat dat het signaal hoog is. + } + if (aanspan==true && emg_filtered<=emg_treshhold_laag)//== ipv =, anders wordt aanspan true gemaakt + { + aanspan=false; + aantal_pieken++; + doel = aantal_pieken-((aantal_pieken/3)*3)+1; + } +} //char *lcd_r1 = new char[16]; //char *lcd_r2 = new char[16]; -void looper() +/* +void emg_filtering() { uint16_t emg_value; 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(); - arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32, &filtered_emg, 1 ); - arm_biquad_cascade_df1_f32(&lowpass_1, &filtered_emg, &filtered_emg, 1 ); - arm_biquad_cascade_df1_f32(¬ch, &filtered_emg, &filtered_emg, 1); - filtered_emg = fabs(filtered_emg); + arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32, &emg_filtered, 1 ); + arm_biquad_cascade_df1_f32(&lowpass_1, &emg_filtered, &emg_filtered, 1 ); + arm_biquad_cascade_df1_f32(¬ch, &emg_filtered, &emg_filtered, 1); + emg_filtered = fabs(emg_filtered); //emg_value_f32 = fabs(emg_value_f32); - arm_biquad_cascade_df1_f32(&lowpass_2, &filtered_emg, &filtered_emg, 1 ); + arm_biquad_cascade_df1_f32(&lowpass_2, &emg_filtered, &emg_filtered, 1 ); //EMG_max_meting(); pieken_tellen(); doel = aantal_pieken-((aantal_pieken/3)*3)+1; + //pc.printf("%d",doel); scope.set(0,emg_value); //uint value - scope.set(1,filtered_emg); //processed float + scope.set(1,emg_filtered); //processed float + scope.set(2,doel); scope.send(); } -void EMG_max_meting() +void emg_max_meting() { //int i=0; // tijdspad //lcd.cls(); @@ -72,30 +121,32 @@ //for(i=0; i<300; i++) //{ // wait(0.1); - if (filtered_emg>=EMG_max) + if (emg_filtered>=emg_max) { - EMG_max=filtered_emg; + emg_max=emg_filtered; } //} //lcd.cls(); //lcd.printf("Maximale EMG\nbepaald"); //wait(3); - EMG_treshhold_laag = 0.3*EMG_max; - EMG_treshhold_hoog = 0.7*EMG_max; + emg_treshhold_laag = 0.3*emg_max; + emg_treshhold_hoog = 0.7*emg_max; } void pieken_tellen() { - if (filtered_emg>=EMG_treshhold_hoog) + if (emg_filtered>=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 + if (aanspan==true && emg_filtered<=emg_treshhold_laag)//== ipv =, anders wordt aanspan true gemaakt { aanspan=false; aantal_pieken++; } } +*/ + int main() { @@ -106,13 +157,14 @@ arm_biquad_cascade_df1_init_f32(¬ch,1 , notch_const, notch_states); arm_biquad_cascade_df1_init_f32(&lowpass_2,1 , lowpass_2_const, lowpass_2_states); - log_timer.attach(looper, 0.005); + log_timer.attach(emg_filtering, 0.005); while(1) //Loop { - lcd.cls(); - lcd.printf("Te raken doel =\n%d", doel); - wait(0.02); + //lcd.cls(); + //lcd.printf("Te raken doel =\n%d", doel); + //pc.baud(9600); + //(0.02); /*Empty!*/ /*Everything is handled by the interrupt routine now!*/ //pc.baud(9600);