Bandpass, notch, abs en laagdoorlaat 3H
Dependencies: HIDScope MODSERIAL TextLCD mbed-dsp mbed
Fork of EMGmeten by
EMGmeten.cpp@5:f93b7068c202, 2014-10-29 (annotated)
- Committer:
- lauradeheus
- Date:
- Wed Oct 29 16:34:45 2014 +0000
- Revision:
- 5:f93b7068c202
- Parent:
- 4:7150ed6ce984
- Child:
- 6:740f08fad2c3
Bandpass, notch, absoluut, laagdoorlaat, pieken en te raken doel werkt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lauradeheus | 0:b68a6d0451b8 | 1 | #include "mbed.h" |
lauradeheus | 0:b68a6d0451b8 | 2 | #include "HIDScope.h" |
lauradeheus | 2:5d64e4c95f5c | 3 | #include "arm_math.h" |
lauradeheus | 2:5d64e4c95f5c | 4 | #include "MODSERIAL.h" |
lauradeheus | 4:7150ed6ce984 | 5 | #include "TextLCD.h" |
lauradeheus | 4:7150ed6ce984 | 6 | |
lauradeheus | 4:7150ed6ce984 | 7 | #define EMG_treshhold 0,05 |
lauradeheus | 0:b68a6d0451b8 | 8 | |
lauradeheus | 2:5d64e4c95f5c | 9 | //MODSERIAL pc(USBTX,USBRX); |
lauradeheus | 0:b68a6d0451b8 | 10 | AnalogIn emg(PTB1); //Analog input |
lauradeheus | 4:7150ed6ce984 | 11 | HIDScope scope(2); // Twee kanalen op de HIDScope |
lauradeheus | 4:7150ed6ce984 | 12 | DigitalIn knop(PTD4); /*Digital input pin (knop) definieren*/ |
lauradeheus | 4:7150ed6ce984 | 13 | TextLCD lcd(PTD2, PTA12, PTB2, PTB3, PTC2, PTA13, TextLCD::LCD16x2); |
lauradeheus | 0:b68a6d0451b8 | 14 | |
lauradeheus | 4:7150ed6ce984 | 15 | arm_biquad_casd_df1_inst_f32 lowpass_1; //2e orde lowpass biquad butterworthfilter 99Hz |
lauradeheus | 4:7150ed6ce984 | 16 | arm_biquad_casd_df1_inst_f32 lowpass_2; //2e orde lowpass biquad butterworthfilter 3Hz |
lauradeheus | 4:7150ed6ce984 | 17 | arm_biquad_casd_df1_inst_f32 highpass; //2e orde highpass biquad butterworthfilter 20Hz |
lauradeheus | 4:7150ed6ce984 | 18 | arm_biquad_casd_df1_inst_f32 notch; //2e orde lowpass biquad butterworthfilter 50Hz |
lauradeheus | 1:b7a9fcf50776 | 19 | float lowpass_1_const[] = {0.978030479206560 , 1.956060958413119 , 0.978030479206560 , -1.955578240315036 , -0.956543676511203}; |
lauradeheus | 1:b7a9fcf50776 | 20 | float lowpass_1_states[4]; |
lauradeheus | 4:7150ed6ce984 | 21 | float lowpass_2_const[] = {0.002080567135492 , 0.004161134270985 , 0.002080567135492 , 1.866892279711715 , -0.875214548253684}; //3Hz |
lauradeheus | 4:7150ed6ce984 | 22 | //{0.0009446914586925257 , 0.0018893829173850514 , 0.0009446914586925257 , 1.911196288237583 , -0.914975054072353};//2Hz |
lauradeheus | 4:7150ed6ce984 | 23 | //{0.00024135899874854145 , 0.0004827179974970829 , 0.00024135899874854145 , 1.9555778328194147 , -0.9565432688144089}; 1Hz |
lauradeheus | 1:b7a9fcf50776 | 24 | float lowpass_2_states[4]; |
lauradeheus | 1:b7a9fcf50776 | 25 | float highpass_const[] = {0.638945525159022 , -1.277891050318045 , 0.638945525159022 , 1.142980502539901 , -0.412801598096189}; |
lauradeheus | 0:b68a6d0451b8 | 26 | float highpass_states[4]; |
lauradeheus | 2:5d64e4c95f5c | 27 | float notch_const[] = {0.978048948305681 , 0.000000000000000 , 0.978048948305681 , 0.000000000000000 , -0.956097896611362}; |
lauradeheus | 2:5d64e4c95f5c | 28 | float notch_states[4]; |
lauradeheus | 4:7150ed6ce984 | 29 | float filtered_emg; |
lauradeheus | 4:7150ed6ce984 | 30 | float EMG_max = 0.16; |
lauradeheus | 4:7150ed6ce984 | 31 | float EMG_treshhold_laag = 0.3*EMG_max; |
lauradeheus | 4:7150ed6ce984 | 32 | float EMG_treshhold_hoog = 0.7*EMG_max; |
lauradeheus | 4:7150ed6ce984 | 33 | |
lauradeheus | 4:7150ed6ce984 | 34 | bool aanspan; |
lauradeheus | 4:7150ed6ce984 | 35 | int aantal_pieken; |
lauradeheus | 5:f93b7068c202 | 36 | int doel; |
lauradeheus | 4:7150ed6ce984 | 37 | |
lauradeheus | 4:7150ed6ce984 | 38 | void looper(); |
lauradeheus | 4:7150ed6ce984 | 39 | void pieken_tellen(); |
lauradeheus | 4:7150ed6ce984 | 40 | //char *lcd_r1 = new char[16]; |
lauradeheus | 4:7150ed6ce984 | 41 | //char *lcd_r2 = new char[16]; |
lauradeheus | 0:b68a6d0451b8 | 42 | |
lauradeheus | 0:b68a6d0451b8 | 43 | void looper() |
lauradeheus | 0:b68a6d0451b8 | 44 | { |
lauradeheus | 0:b68a6d0451b8 | 45 | uint16_t emg_value; |
lauradeheus | 0:b68a6d0451b8 | 46 | float emg_value_f32; |
lauradeheus | 0:b68a6d0451b8 | 47 | emg_value = emg.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V) |
lauradeheus | 0:b68a6d0451b8 | 48 | emg_value_f32 = emg.read(); |
lauradeheus | 0:b68a6d0451b8 | 49 | |
lauradeheus | 0:b68a6d0451b8 | 50 | arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32, &filtered_emg, 1 ); |
lauradeheus | 1:b7a9fcf50776 | 51 | arm_biquad_cascade_df1_f32(&lowpass_1, &filtered_emg, &filtered_emg, 1 ); |
lauradeheus | 2:5d64e4c95f5c | 52 | arm_biquad_cascade_df1_f32(¬ch, &filtered_emg, &filtered_emg, 1); |
lauradeheus | 1:b7a9fcf50776 | 53 | filtered_emg = fabs(filtered_emg); |
lauradeheus | 2:5d64e4c95f5c | 54 | //emg_value_f32 = fabs(emg_value_f32); |
lauradeheus | 3:c82170d8b6c8 | 55 | arm_biquad_cascade_df1_f32(&lowpass_2, &filtered_emg, &filtered_emg, 1 ); |
lauradeheus | 4:7150ed6ce984 | 56 | |
lauradeheus | 4:7150ed6ce984 | 57 | void pieken_tellen(); |
lauradeheus | 4:7150ed6ce984 | 58 | { |
lauradeheus | 4:7150ed6ce984 | 59 | if (filtered_emg>=EMG_treshhold_hoog) |
lauradeheus | 4:7150ed6ce984 | 60 | { |
lauradeheus | 4:7150ed6ce984 | 61 | aanspan=true; //maak een variabele waarin je opslaat dat het signaal hoog is. |
lauradeheus | 4:7150ed6ce984 | 62 | } |
lauradeheus | 4:7150ed6ce984 | 63 | if (aanspan==true && filtered_emg<=EMG_treshhold_laag)//== ipv =, anders wordt aanspan true gemaakt |
lauradeheus | 4:7150ed6ce984 | 64 | { |
lauradeheus | 4:7150ed6ce984 | 65 | aanspan=false; |
lauradeheus | 4:7150ed6ce984 | 66 | aantal_pieken++; |
lauradeheus | 4:7150ed6ce984 | 67 | } |
lauradeheus | 4:7150ed6ce984 | 68 | } |
lauradeheus | 0:b68a6d0451b8 | 69 | |
lauradeheus | 5:f93b7068c202 | 70 | doel = aantal_pieken-((aantal_pieken/3)*3); |
lauradeheus | 0:b68a6d0451b8 | 71 | scope.set(0,emg_value); //uint value |
lauradeheus | 0:b68a6d0451b8 | 72 | scope.set(1,filtered_emg); //processed float |
lauradeheus | 0:b68a6d0451b8 | 73 | scope.send(); |
lauradeheus | 0:b68a6d0451b8 | 74 | } |
lauradeheus | 0:b68a6d0451b8 | 75 | |
lauradeheus | 0:b68a6d0451b8 | 76 | int main() |
lauradeheus | 0:b68a6d0451b8 | 77 | { |
lauradeheus | 0:b68a6d0451b8 | 78 | Ticker log_timer; |
lauradeheus | 0:b68a6d0451b8 | 79 | |
lauradeheus | 1:b7a9fcf50776 | 80 | arm_biquad_cascade_df1_init_f32(&lowpass_1,1 , lowpass_1_const, lowpass_1_states); |
lauradeheus | 0:b68a6d0451b8 | 81 | arm_biquad_cascade_df1_init_f32(&highpass,1 , highpass_const, highpass_states); |
lauradeheus | 2:5d64e4c95f5c | 82 | arm_biquad_cascade_df1_init_f32(¬ch,1 , notch_const, notch_states); |
lauradeheus | 3:c82170d8b6c8 | 83 | arm_biquad_cascade_df1_init_f32(&lowpass_2,1 , lowpass_2_const, lowpass_2_states); |
lauradeheus | 0:b68a6d0451b8 | 84 | |
lauradeheus | 0:b68a6d0451b8 | 85 | log_timer.attach(looper, 0.005); |
lauradeheus | 0:b68a6d0451b8 | 86 | |
lauradeheus | 0:b68a6d0451b8 | 87 | while(1) //Loop |
lauradeheus | 0:b68a6d0451b8 | 88 | { |
lauradeheus | 4:7150ed6ce984 | 89 | lcd.cls(); |
lauradeheus | 5:f93b7068c202 | 90 | lcd.printf("Te raken doel =\n%d", doel); |
lauradeheus | 4:7150ed6ce984 | 91 | wait(0.02); |
lauradeheus | 0:b68a6d0451b8 | 92 | /*Empty!*/ |
lauradeheus | 0:b68a6d0451b8 | 93 | /*Everything is handled by the interrupt routine now!*/ |
lauradeheus | 2:5d64e4c95f5c | 94 | //pc.baud(9600); |
lauradeheus | 0:b68a6d0451b8 | 95 | } |
lauradeheus | 0:b68a6d0451b8 | 96 | } |
lauradeheus | 0:b68a6d0451b8 | 97 |