![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
things
Revision 0:b1ef0101f09c, committed 2018-10-15
- Comitter:
- WouterJS
- Date:
- Mon Oct 15 12:52:13 2018 +0000
- Commit message:
- Jo;
Changed in this revision
diff -r 000000000000 -r b1ef0101f09c Biquad/Biquad.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Biquad/Biquad.cpp Mon Oct 15 12:52:13 2018 +0000 @@ -0,0 +1,13 @@ +#include "Biquad.h" + +Biquad::Biquad(){}; + +double Biquad::filter( double u, double &v1, double &v2, const double a1, const double a2, + const double b0, const double b1, const double b2 ) +{ + double v = u - a1*v1 - a2*v2; + double y = b0*v + b1*v1 + b2*v2; + v2 = v1; + v1 = v; + return y; +}
diff -r 000000000000 -r b1ef0101f09c Biquad/Biquad.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Biquad/Biquad.h Mon Oct 15 12:52:13 2018 +0000 @@ -0,0 +1,26 @@ +#ifndef _BIQUAD_H_ +#define _BIQUAD_H_ + +#include "mbed.h" + +class Biquad +{ +public: + ///Instantiate the biquad filter + Biquad(void); + + /**Filters the given signal with the filter values. + * @param u : double signal to filter + * @param &v1 : double variable to store previous values + * @param &v2 : double variable to store previous values + * @param a1 : double filter coefficient a1 + * @param a1 : double filter coefficient a2 + * @param a1 : double filter coefficient b0 + * @param a1 : double filter coefficient b1 + * @param a1 : double filter coefficient b2 + * @return v : double filtered signal + */ + double filter( double u, double &v1, double &v2, const double a1, const double a2, + const double b0, const double b1, const double b2 ); +}; +#endif \ No newline at end of file
diff -r 000000000000 -r b1ef0101f09c HIDScope.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HIDScope.lib Mon Oct 15 12:52:13 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/tomlankhorst/code/HIDScope/#eade4ec5282b
diff -r 000000000000 -r b1ef0101f09c filtervalues.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filtervalues.h Mon Oct 15 12:52:13 2018 +0000 @@ -0,0 +1,33 @@ +//////////////////////////////////////////////CONSTANTS +// FS 500 +///////////////////Biquad #1 // Highpass 20 Hz +const double gain_f1 = 1; +const double A_f1[] = { 1 , -1.64742277e+00 , 0.70085836}; +const double B_f1[] = { 0.83707028 , -1.67414057 , 0.83707028}; + +///////////////////Biquad #2 // Lowpass 5 Hz +const double gain_f2 = 1; +const double A_f2[] = { 1 , -1.91118480 , 0.91496354}; +const double B_f2[] = { 0.95653708 ,-1.91307417 , 0.95653708}; + +////////////////////////////////////////////ARRAYS TO VARIABLES +/////////////////Biquad #1 +const double a1_f1 = gain_f1*A_f1[1], + a2_f1 = gain_f1*A_f1[2], + b0_f1 = gain_f1*B_f1[0], + b1_f1 = gain_f1*B_f1[1], + b2_f1 = gain_f1*B_f1[2]; //filter coefficients filter 1 +double v1_f1_emg1=0 , + v2_f1_emg1=0 , + v1_f1_emg2=0 , + v2_f1_emg2=0;//storage variables filter 1 +/////////////////Biquad #2 +const double a1_f2 = gain_f2*A_f2[1], + a2_f2 = gain_f2*A_f2[2], + b0_f2 = gain_f2*B_f2[0], + b1_f2 = gain_f2*B_f2[1], + b2_f2 = gain_f2*B_f2[2]; //filter coefficients filter 2 +double v1_f2_emg1=0 , + v2_f2_emg1=0 , + v1_f2_emg2=0 , + v2_f2_emg2=0;//storage variables filter 2 \ No newline at end of file
diff -r 000000000000 -r b1ef0101f09c main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Oct 15 12:52:13 2018 +0000 @@ -0,0 +1,74 @@ +#include "mbed.h" +#include "Biquad.h" +#include "filtervalues.h" +#include "HIDScope.h" + + +DigitalOut led_red(LED_RED); + +Serial pc(USBTX,USBRX);// serial connection to pc + +Ticker sample_timer; +HIDScope scope( 2 ); + + +Biquad myfilter1;// make filter for signal 1 +Biquad myfilter2;//make filter for signal 2 + +AnalogIn emg1_input(A0);//input for first emg signal 1 +AnalogIn emg2_input(A1);//input for first emg signal 2 + +volatile double filteredsignal1=0;//the first filtered emg signal 1 +volatile double filteredsignal2=0;//the first filtered emg signal 2 + + +void filtereverything(bool makeempty) +{ + //highpass + double pass1_emg1 = myfilter1.filter(emg1_input.read(), v1_f1_emg1 , v2_f1_emg1 , a1_f1 , a2_f1 , b0_f1 , b1_f1 , b2_f1); + double pass1_emg2 = myfilter1.filter(emg2_input.read(), v1_f2_emg2 , v2_f1_emg2 , a1_f1 , a2_f1 , b0_f1 , b1_f1 , b2_f1); + // take aboslute values + double pass2_emg1 = fabs(pass1_emg1); + double pass2_emg2 = fabs(pass1_emg2); + //lowpass + double pass3_emg1 = myfilter1.filter(pass2_emg1, v1_f2_emg1 , v2_f2_emg1 , a1_f2 , a2_f2 , b0_f2 , b1_f2 , b2_f2); + double pass3_emg2 = myfilter1.filter(pass2_emg2, v1_f2_emg2 , v2_f2_emg2 , a1_f2 , a2_f2 , b0_f2 , b1_f2 , b2_f2); + + filteredsignal1 = pass1_emg1; + filteredsignal2 = pass3_emg2; + + if (makeempty==true) {//this is needed so the filtered value is not high after shooting basically it resets the filter + pass1_emg1 = pass2_emg1 = pass3_emg1 = 0; + v1_f1_emg1 = v2_f1_emg1 = v1_f2_emg1 = v2_f2_emg1 = 0; + pass1_emg2 = pass2_emg2 = pass3_emg2 = 0; + v1_f1_emg2 = v2_f1_emg2 = v1_f2_emg2 = v2_f2_emg2 = 0; + } +} + +void scopedata() +{ + scope.set(0,emg1_input.read()); // + scope.set(1,filteredsignal1); // + + scope.send(); // send info to HIDScope server +} + +int main() +{ + sample_timer.attach(&scopedata, 0.002); + pc.baud(115200); + + while (true) { + + filtereverything(false); + + if(filteredsignal1 > 0.8){ + led_red = 0; + } + else{ + led_red = 1; + } + + + } +} \ No newline at end of file
diff -r 000000000000 -r b1ef0101f09c mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Oct 15 12:52:13 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68 \ No newline at end of file