![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Bandpass, notch, abs en laagdoorlaat 3H
Dependencies: HIDScope MODSERIAL TextLCD mbed-dsp mbed
Fork of EMGmeten by
EMGmeten.cpp@0:b68a6d0451b8, 2014-10-28 (annotated)
- Committer:
- lauradeheus
- Date:
- Tue Oct 28 14:23:05 2014 +0000
- Revision:
- 0:b68a6d0451b8
- Child:
- 1:b7a9fcf50776
Bandpass goedwerkend
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 | 0:b68a6d0451b8 | 3 | |
lauradeheus | 0:b68a6d0451b8 | 4 | #include "arm_math.h" |
lauradeheus | 0:b68a6d0451b8 | 5 | |
lauradeheus | 0:b68a6d0451b8 | 6 | AnalogIn emg(PTB1); //Analog input |
lauradeheus | 0:b68a6d0451b8 | 7 | HIDScope scope(2); |
lauradeheus | 0:b68a6d0451b8 | 8 | |
lauradeheus | 0:b68a6d0451b8 | 9 | arm_biquad_casd_df1_inst_f32 lowpass; |
lauradeheus | 0:b68a6d0451b8 | 10 | arm_biquad_casd_df1_inst_f32 highpass; |
lauradeheus | 0:b68a6d0451b8 | 11 | float lowpass_const[] = {0.978030479206560 , 1.956060958413119 , 0.978030479206560 , -1.955578240315036 , -0.956543676511203}; |
lauradeheus | 0:b68a6d0451b8 | 12 | float lowpass_states[4]; |
lauradeheus | 0:b68a6d0451b8 | 13 | float highpass_const[] = {0.638945525159022, -1.277891050318045, 0.638945525159022 , 1.142980502539901 , -0.412801598096189}; |
lauradeheus | 0:b68a6d0451b8 | 14 | float highpass_states[4]; |
lauradeheus | 0:b68a6d0451b8 | 15 | |
lauradeheus | 0:b68a6d0451b8 | 16 | void looper() |
lauradeheus | 0:b68a6d0451b8 | 17 | { |
lauradeheus | 0:b68a6d0451b8 | 18 | uint16_t emg_value; |
lauradeheus | 0:b68a6d0451b8 | 19 | float filtered_emg; |
lauradeheus | 0:b68a6d0451b8 | 20 | float emg_value_f32; |
lauradeheus | 0:b68a6d0451b8 | 21 | 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 | 22 | emg_value_f32 = emg.read(); |
lauradeheus | 0:b68a6d0451b8 | 23 | |
lauradeheus | 0:b68a6d0451b8 | 24 | arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32, &filtered_emg, 1 ); |
lauradeheus | 0:b68a6d0451b8 | 25 | arm_biquad_cascade_df1_f32(&lowpass, &filtered_emg, &filtered_emg, 1 ); |
lauradeheus | 0:b68a6d0451b8 | 26 | |
lauradeheus | 0:b68a6d0451b8 | 27 | scope.set(0,emg_value); //uint value |
lauradeheus | 0:b68a6d0451b8 | 28 | scope.set(1,filtered_emg); //processed float |
lauradeheus | 0:b68a6d0451b8 | 29 | scope.send(); |
lauradeheus | 0:b68a6d0451b8 | 30 | } |
lauradeheus | 0:b68a6d0451b8 | 31 | |
lauradeheus | 0:b68a6d0451b8 | 32 | int main() |
lauradeheus | 0:b68a6d0451b8 | 33 | { |
lauradeheus | 0:b68a6d0451b8 | 34 | Ticker log_timer; |
lauradeheus | 0:b68a6d0451b8 | 35 | |
lauradeheus | 0:b68a6d0451b8 | 36 | arm_biquad_cascade_df1_init_f32(&lowpass,1 , lowpass_const, lowpass_states); |
lauradeheus | 0:b68a6d0451b8 | 37 | arm_biquad_cascade_df1_init_f32(&highpass,1 , highpass_const, highpass_states); |
lauradeheus | 0:b68a6d0451b8 | 38 | |
lauradeheus | 0:b68a6d0451b8 | 39 | log_timer.attach(looper, 0.005); |
lauradeheus | 0:b68a6d0451b8 | 40 | |
lauradeheus | 0:b68a6d0451b8 | 41 | while(1) //Loop |
lauradeheus | 0:b68a6d0451b8 | 42 | { |
lauradeheus | 0:b68a6d0451b8 | 43 | /*Empty!*/ |
lauradeheus | 0:b68a6d0451b8 | 44 | /*Everything is handled by the interrupt routine now!*/ |
lauradeheus | 0:b68a6d0451b8 | 45 | } |
lauradeheus | 0:b68a6d0451b8 | 46 | } |
lauradeheus | 0:b68a6d0451b8 | 47 |