Bandpass, notch, abs en laagdoorlaat 3H

Dependencies:   HIDScope MODSERIAL TextLCD mbed-dsp mbed

Fork of EMGmeten by Laura Heus

Committer:
lauradeheus
Date:
Wed Oct 29 08:57:43 2014 +0000
Revision:
3:c82170d8b6c8
Parent:
2:5d64e4c95f5c
Child:
4:7150ed6ce984
Bandpass, notch, abs en laag 3Hz werkt :D

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 2:5d64e4c95f5c 3 #include "arm_math.h"
lauradeheus 2:5d64e4c95f5c 4 #include "MODSERIAL.h"
lauradeheus 0:b68a6d0451b8 5
lauradeheus 2:5d64e4c95f5c 6 //MODSERIAL pc(USBTX,USBRX);
lauradeheus 0:b68a6d0451b8 7 AnalogIn emg(PTB1); //Analog input
lauradeheus 0:b68a6d0451b8 8 HIDScope scope(2);
lauradeheus 0:b68a6d0451b8 9
lauradeheus 1:b7a9fcf50776 10 arm_biquad_casd_df1_inst_f32 lowpass_1; //99Hz
lauradeheus 1:b7a9fcf50776 11 arm_biquad_casd_df1_inst_f32 lowpass_2; //3Hz
lauradeheus 1:b7a9fcf50776 12 arm_biquad_casd_df1_inst_f32 highpass; //20Hz
lauradeheus 2:5d64e4c95f5c 13 arm_biquad_casd_df1_inst_f32 notch; //50Hz
lauradeheus 1:b7a9fcf50776 14 float lowpass_1_const[] = {0.978030479206560 , 1.956060958413119 , 0.978030479206560 , -1.955578240315036 , -0.956543676511203};
lauradeheus 1:b7a9fcf50776 15 float lowpass_1_states[4];
lauradeheus 3:c82170d8b6c8 16 float lowpass_2_const[] = {0.002080567135492 , 0.004161134270985 , 0.002080567135492 , 1.866892279711715 , -0.875214548253684};
lauradeheus 1:b7a9fcf50776 17 float lowpass_2_states[4];
lauradeheus 1:b7a9fcf50776 18 float highpass_const[] = {0.638945525159022 , -1.277891050318045 , 0.638945525159022 , 1.142980502539901 , -0.412801598096189};
lauradeheus 0:b68a6d0451b8 19 float highpass_states[4];
lauradeheus 2:5d64e4c95f5c 20 float notch_const[] = {0.978048948305681 , 0.000000000000000 , 0.978048948305681 , 0.000000000000000 , -0.956097896611362};
lauradeheus 2:5d64e4c95f5c 21 float notch_states[4];
lauradeheus 0:b68a6d0451b8 22
lauradeheus 0:b68a6d0451b8 23 void looper()
lauradeheus 0:b68a6d0451b8 24 {
lauradeheus 0:b68a6d0451b8 25 uint16_t emg_value;
lauradeheus 0:b68a6d0451b8 26 float filtered_emg;
lauradeheus 0:b68a6d0451b8 27 float emg_value_f32;
lauradeheus 0:b68a6d0451b8 28 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 29 emg_value_f32 = emg.read();
lauradeheus 0:b68a6d0451b8 30
lauradeheus 0:b68a6d0451b8 31 arm_biquad_cascade_df1_f32(&highpass, &emg_value_f32, &filtered_emg, 1 );
lauradeheus 1:b7a9fcf50776 32 arm_biquad_cascade_df1_f32(&lowpass_1, &filtered_emg, &filtered_emg, 1 );
lauradeheus 2:5d64e4c95f5c 33 arm_biquad_cascade_df1_f32(&notch, &filtered_emg, &filtered_emg, 1);
lauradeheus 1:b7a9fcf50776 34 filtered_emg = fabs(filtered_emg);
lauradeheus 2:5d64e4c95f5c 35 //emg_value_f32 = fabs(emg_value_f32);
lauradeheus 3:c82170d8b6c8 36 arm_biquad_cascade_df1_f32(&lowpass_2, &filtered_emg, &filtered_emg, 1 );
lauradeheus 0:b68a6d0451b8 37
lauradeheus 0:b68a6d0451b8 38 scope.set(0,emg_value); //uint value
lauradeheus 0:b68a6d0451b8 39 scope.set(1,filtered_emg); //processed float
lauradeheus 0:b68a6d0451b8 40 scope.send();
lauradeheus 0:b68a6d0451b8 41 }
lauradeheus 0:b68a6d0451b8 42
lauradeheus 0:b68a6d0451b8 43 int main()
lauradeheus 0:b68a6d0451b8 44 {
lauradeheus 0:b68a6d0451b8 45 Ticker log_timer;
lauradeheus 0:b68a6d0451b8 46
lauradeheus 1:b7a9fcf50776 47 arm_biquad_cascade_df1_init_f32(&lowpass_1,1 , lowpass_1_const, lowpass_1_states);
lauradeheus 0:b68a6d0451b8 48 arm_biquad_cascade_df1_init_f32(&highpass,1 , highpass_const, highpass_states);
lauradeheus 2:5d64e4c95f5c 49 arm_biquad_cascade_df1_init_f32(&notch,1 , notch_const, notch_states);
lauradeheus 3:c82170d8b6c8 50 arm_biquad_cascade_df1_init_f32(&lowpass_2,1 , lowpass_2_const, lowpass_2_states);
lauradeheus 0:b68a6d0451b8 51
lauradeheus 0:b68a6d0451b8 52 log_timer.attach(looper, 0.005);
lauradeheus 0:b68a6d0451b8 53
lauradeheus 0:b68a6d0451b8 54 while(1) //Loop
lauradeheus 0:b68a6d0451b8 55 {
lauradeheus 0:b68a6d0451b8 56 /*Empty!*/
lauradeheus 0:b68a6d0451b8 57 /*Everything is handled by the interrupt routine now!*/
lauradeheus 2:5d64e4c95f5c 58 //pc.baud(9600);
lauradeheus 2:5d64e4c95f5c 59 //pc.printf("filtered_emg=%f\n\r",filtered_emg);
lauradeheus 0:b68a6d0451b8 60 }
lauradeheus 0:b68a6d0451b8 61 }
lauradeheus 0:b68a6d0451b8 62