:)
Dependencies: HIDScope MODSERIAL mbed-dsp mbed
Fork of emg_filter by
Revision 30:5d8e6f0fabc1, committed 2014-10-17
- Comitter:
- s1340735
- Date:
- Fri Oct 17 10:36:29 2014 +0000
- Parent:
- 29:f54123765a47
- Child:
- 31:b6f7ba4938d4
- Commit message:
- moving average toegevoegd
Changed in this revision
EMGfilter.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/EMGfilter.cpp Fri Oct 17 09:45:41 2014 +0000 +++ b/EMGfilter.cpp Fri Oct 17 10:36:29 2014 +0000 @@ -2,8 +2,9 @@ #include "HIDScope.h" #include "MODSERIAL.h" #include "arm_math.h" +#include "MAF.h" -HIDScope::HIDScope(int channels) : hid(64,64) +HIDScope::HIDScope(int channels) : hid(64,64) { bufferData = new float[channels](); channelCount = channels; @@ -31,10 +32,10 @@ } void HIDScope::send() -{ +{ for(int ch=0; ch<channelCount; ch++) memcpy(&scopeData.data[ch*4], &bufferData[ch], 4); // Copy a 4 byte float to the char array - + // Send non blocking, can be adjusted to blocking (hid.send) hid.sendNB(&scopeData); } @@ -54,7 +55,7 @@ arm_biquad_casd_df1_inst_f32 lowpass; //constants for 50Hz lowpass -float lowpass_const[] = {0.2928920553, 0.5857841107, 0.2928920554, -0, -0.17156822136};//{a0 a1 a2 -b1 -b2} van online calculator +float lowpass_const[] = {0.2928920553, 0.5857841107, 0.2928920554, -0, -0.17156822136};//{a0 a1 a2 -b1 -b2} van online calculator //state values float lowpass_states[4]; @@ -84,7 +85,7 @@ { /*variable to store value in*/ uint16_t emg_valueB; - + float emg_value_f32B; /*put raw emg value both in red and in emg_value*/ emg_valueB = emgB.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V) @@ -100,13 +101,29 @@ scope.set(1,filtered_emgB); //processed float scope.send(); + MAF::MAF() {} + float MAF::update(float filtered_emgB) { + B[0]=filtered_emgB; + MOVAVG_B=B[0]*0.1+B[1]*0.1+B[2]*0.1+B[3]*0.1+B[4]*0.1+B[5]*0.1+B[7]*0.1+B[8]*0.1+B[9]*0.1 + B[9]=B[8]; + B[8]=B[7]; + B[7]=B[6]; + B[6]=B[5]; + B[5]=B[4]; + B[4]=B[3]; + B[3]=B[2]; + B[2]=B[1]; + B[1]=B[0]; + + return MOVAVG_B; + } } void looperT() { /*variable to store value in*/ uint16_t emg_valueT; - + float emg_value_f32T; /*put raw emg value both in red and in emg_value*/ emg_valueT = emgT.read_u16(); // read direct ADC result, converted to 16 bit integer (0..2^16 = 0..65536 = 0..3.3V) @@ -150,9 +167,8 @@ { float drempelwaarde=4.99; int y; - - if (filtered_emgB > drempelwaarde) - { + + if (filtered_emgB > drempelwaarde) { y=1; } else { y=0;