Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope MODSERIAL mbed
Fork of Signal Filter by
Diff: main.cpp
- Revision:
- 8:a1ea1bf49944
- Parent:
- 7:7493a0c5c6aa
diff -r 7493a0c5c6aa -r a1ea1bf49944 main.cpp --- a/main.cpp Mon Sep 28 08:41:32 2015 +0000 +++ b/main.cpp Mon Oct 19 08:36:31 2015 +0000 @@ -4,7 +4,7 @@ #include "HIDScope.h" -AnalogIn EMG(A0); +AnalogIn EMG(A1); MODSERIAL pc(USBTX, USBRX); //const int baudrate = 115200; @@ -15,14 +15,13 @@ Ticker scopeTimer; // Define moving average variables -const int N = 150; +const int N = 125; double a; // Define the storage variables and filter coeicients for two filters double f1_v1 = 0, f1_v2 = 0, f2_v1 = 0, f2_v2 = 0; -const double f1_a1 = -1.998222847291842, f1_a2 = 0.998224425026401, f1_b0 = 0.999111818079561, f1_b1 = -1.998223636159122, f1_b2 = 0.999111818079561; -// const double f1_a1 = 0.25071442433, f1_a2 = 0.21711875780, f1_b0 = 1.0, f1_b1 = -1.62432585007, f1_b2 = 1.0; -// const double f2_a1 = -1.77682226139, f2_a2 = 0.80213897411, f2_b0 = 1.0, f2_b1 = -1.62432585007, f2_b2 = 1.0; +const double f1_a1 = -1.822694925196308, f1_a2 = 0.837181651256022, f1_b0 = 0.914969144113083, f1_b1 = -1.829938288226165, f1_b2 = 0.914969144113083; +const double f2_a1 = -1.964460580205232, f2_a2 = 0.965081173899135, f2_b0 = 0.000155148423475721, f2_b1 = 0.000310296846951441, f2_b2 = 0.000155148423475721; double biquad( double u, double &v1, double &v2, const double a1, const double a2, const double b0, const double b1, const double b2 ) { @@ -36,7 +35,7 @@ { double f_x[f_N]; double f_sum=0; - f_x[1]=fabs(u); + f_x[1]=abs(u); for (int i=f_N; i>=1; i--){ f_x[i]=f_x[i-1]; } @@ -50,32 +49,15 @@ return a; } - - - - - - - - // This is your controller, call it using a Ticker -// void myController() { - //double u1 = EMG, u2 = y1 ; - //double y1 = biquad( u1, f1_v1, f1_v2, f1_a1, f1_a2, f1_b0, f1_b1, f1_b2 ); - //double y2 = biquad( u2, f2_v1, f2_v2, f2_a1, f2_a2, f2_b0, f2_b1, f2_b2 ); - //} - void scopeSend(){ double u1 = EMG.read() ; //filter 1 input - double y1 = biquad( u1, f1_v1, f1_v2, f1_a1, f1_a2, f1_b0, f1_b1, f1_b2 ); - //double u2 = y1; //filter 2 input - //double y2 = biquad( u2, f2_v1, f2_v2, f2_a1, f2_a2, f2_b0, f2_b1, f2_b2 ); - double z1 = sliding_average(y1, N); - scope.set(0,z1); - //scope.set(1,u1); + double y2 = biquad( fabs(y1), f2_v1, f2_v2, f2_a1, f2_a2, f2_b0, f2_b1, f2_b2 ); + //double z1 = 3*sliding_average(y2, N); + scope.set(0,y2); scope.send(); }