Bandpass, notch, abs en laagdoorlaat 3H

Dependencies:   HIDScope MODSERIAL TextLCD mbed-dsp mbed

Fork of EMGmeten by Laura Heus

Committer:
lauradeheus
Date:
Tue Oct 28 14:37:59 2014 +0000
Revision:
1:b7a9fcf50776
Parent:
0:b68a6d0451b8
Child:
2:5d64e4c95f5c
Bandpass and rectifying correct

Who changed what in which revision?

UserRevisionLine numberNew 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 1:b7a9fcf50776 9 arm_biquad_casd_df1_inst_f32 lowpass_1; //99Hz
lauradeheus 1:b7a9fcf50776 10 arm_biquad_casd_df1_inst_f32 lowpass_2; //3Hz
lauradeheus 1:b7a9fcf50776 11 arm_biquad_casd_df1_inst_f32 highpass; //20Hz
lauradeheus 1:b7a9fcf50776 12 float lowpass_1_const[] = {0.978030479206560 , 1.956060958413119 , 0.978030479206560 , -1.955578240315036 , -0.956543676511203};
lauradeheus 1:b7a9fcf50776 13 float lowpass_1_states[4];
lauradeheus 1:b7a9fcf50776 14 float lowpass_2_const[] = {0.002080567135492 , 0.004161134270985 , 0.002080567135492 , 1.866892279711715 , 0.875214548253684};
lauradeheus 1:b7a9fcf50776 15 float lowpass_2_states[4];
lauradeheus 1:b7a9fcf50776 16 float highpass_const[] = {0.638945525159022 , -1.277891050318045 , 0.638945525159022 , 1.142980502539901 , -0.412801598096189};
lauradeheus 0:b68a6d0451b8 17 float highpass_states[4];
lauradeheus 0:b68a6d0451b8 18
lauradeheus 0:b68a6d0451b8 19 void looper()
lauradeheus 0:b68a6d0451b8 20 {
lauradeheus 0:b68a6d0451b8 21 uint16_t emg_value;
lauradeheus 0:b68a6d0451b8 22 float filtered_emg;
lauradeheus 0:b68a6d0451b8 23 float emg_value_f32;
lauradeheus 0:b68a6d0451b8 24 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 25 emg_value_f32 = emg.read();
lauradeheus 0:b68a6d0451b8 26
lauradeheus 0:b68a6d0451b8 27 arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32, &filtered_emg, 1 );
lauradeheus 1:b7a9fcf50776 28 arm_biquad_cascade_df1_f32(&lowpass_1, &filtered_emg, &filtered_emg, 1 );
lauradeheus 1:b7a9fcf50776 29 filtered_emg = fabs(filtered_emg);
lauradeheus 1:b7a9fcf50776 30 //arm_biquad_cascade_df1_f32(&lowpass_2, &filtered_emg, &filtered_emg, 1 );
lauradeheus 0:b68a6d0451b8 31
lauradeheus 0:b68a6d0451b8 32 scope.set(0,emg_value); //uint value
lauradeheus 0:b68a6d0451b8 33 scope.set(1,filtered_emg); //processed float
lauradeheus 0:b68a6d0451b8 34 scope.send();
lauradeheus 0:b68a6d0451b8 35 }
lauradeheus 0:b68a6d0451b8 36
lauradeheus 0:b68a6d0451b8 37 int main()
lauradeheus 0:b68a6d0451b8 38 {
lauradeheus 0:b68a6d0451b8 39 Ticker log_timer;
lauradeheus 0:b68a6d0451b8 40
lauradeheus 1:b7a9fcf50776 41 arm_biquad_cascade_df1_init_f32(&lowpass_1,1 , lowpass_1_const, lowpass_1_states);
lauradeheus 0:b68a6d0451b8 42 arm_biquad_cascade_df1_init_f32(&highpass,1 , highpass_const, highpass_states);
lauradeheus 1:b7a9fcf50776 43 //arm_biquad_cascade_df1_init_f32(&lowpass_2,1 , lowpass_2_const, lowpass_2_states);
lauradeheus 0:b68a6d0451b8 44
lauradeheus 0:b68a6d0451b8 45 log_timer.attach(looper, 0.005);
lauradeheus 0:b68a6d0451b8 46
lauradeheus 0:b68a6d0451b8 47 while(1) //Loop
lauradeheus 0:b68a6d0451b8 48 {
lauradeheus 0:b68a6d0451b8 49 /*Empty!*/
lauradeheus 0:b68a6d0451b8 50 /*Everything is handled by the interrupt routine now!*/
lauradeheus 0:b68a6d0451b8 51 }
lauradeheus 0:b68a6d0451b8 52 }
lauradeheus 0:b68a6d0451b8 53