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
main.cpp
- Committer:
- Peasofcake
- Date:
- 2015-09-21
- Revision:
- 5:ba1679ff9951
- Parent:
- 4:d6a3b318c744
- Child:
- 6:c20a8c0f90ed
File content as of revision 5:ba1679ff9951:
#include "mbed.h" #include "MODSERIAL.h" #include "math.h" #include "HIDScope.h" AnalogIn EMG(A0); MODSERIAL pc(USBTX, USBRX); //const int baudrate = 115200; //const int ms_wait = 100; // Define the HIDScope and Ticker objects HIDScope scope(1); Ticker scopeTimer; // Define the storage variables and filter coeicients for two filters // 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 = 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; double biquad( 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; } // 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 ; //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 ); scope.set(0,y2); scope.send(); } int main() { scopeTimer.attach_us(&scopeSend,1e4); while(1){} }