EMG filteren
Dependencies: HIDScope biquadFilter mbed
main.cpp
- Committer:
- Hubertus
- Date:
- 2018-10-11
- Revision:
- 1:082004527d2e
- Parent:
- 0:55a2b57fd35d
- Child:
- 2:5a5a54374f80
File content as of revision 1:082004527d2e:
#include "mbed.h" #include "HIDScope.h" #include "BiQuad.h" //Define objects AnalogIn emg0( A0 ); AnalogIn emg1( A1 ); Ticker sample_timer; HIDScope scope( 4 ); DigitalOut ledred(LED1); DigitalOut ledgreen(LED_GREEN); //------------Filter parameters---------------------- //Lowpassfilter const double b0LP = 0.0014831498359569692; const double b1LP = 0.0029662996719139385; const double b2LP = 0.0014831498359569692; const double a1LP = -1.918570032544273; const double a2LP = 0.9245026318881009; //Highpassfilter const double b0HP = 0.9921463375688531; const double b1HP = -1.9842926751377061; const double b2HP = 0.9921463375688531; const double a1HP = -1.9841702689557372; const double a2HP = 0.9844150813196749; //Notchfilter //const double b0NO = 1; //const double b1NO = 1; //const double b2NO = 1; //const double a1NO = 1; //const double a2NO = 1; //--------------Filter------------ BiQuad LP1( b0LP, b1LP, b2LP, a1LP, a2LP ); //Lowpass filter Biquad BiQuad HP2( b0HP, b1HP, b2HP, a1HP, a2HP ); //Highpass filter Biquad //BiQuad NO3( b0NO, b1NO, b2NO, a1NO, a2NO ); //Notch filter Biquad BiQuadChain BiQuad_filter; float Signal; float Signal_filtered; float Signal_filtered_HP; float Signal_filtered_fabs; /** Sample function * this function samples the emg and sends it to HIDScope **/ void sample_filter() { Signal = emg0; Signal_filtered_HP = HP2.step(Signal); Signal_filtered_fabs = fabs(Signal_filtered_HP); Signal_filtered = LP1.step(Signal_filtered_fabs); //Poging tot goed filter //Signal = emg0-emg1; // BiQuad_filter.add(&LP); // Signal_filtered = BiQuad_filter.step(Signal); // Signal_filtered = fabs(Signal_filtered); // BiQuad_filter.add(&HP); // Signal_filtered = BiQuad_filter.step(Signal_filtered); //Signal_filtered = fabs(Signal_filtered); // je wil alleen de absolute waardes /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */ scope.set(0, emg0.read() ); scope.set(1, emg1.read() ); scope.set(2, Signal ); scope.set(3, Signal_filtered); /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) * Ensure that enough channels are available (HIDScope scope( 2 )) * Finally, send all channels to the PC at once */ scope.send(); /* To indicate that the function is working, the LED is toggled */ ledred = !ledred; } //----------Parameters voor filter---------- //const float Fs = 200.0; //const float Fnyq = Fs / 2; //const int Nthorder = 4; // ////---------Functie voor filter----------- //void filter() //{ // //} int main() { /**Attach the 'sample' function to the timer 'sample_timer'. * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz */ sample_timer.attach(&sample_filter, 0.002); /*empty loop, sample() is executed periodically*/ while(1) { if (Signal_filtered > 0.1) { ledgreen = 0; } else { ledgreen = 1; } } }