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 QEI TextLCD mbed
Fork of TotalControlEmg2 by
Diff: main.cpp
- Revision:
- 0:557b1ff83a8a
- Child:
- 1:98be4152a539
diff -r 000000000000 -r 557b1ff83a8a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 06 12:02:22 2015 +0000 @@ -0,0 +1,73 @@ +#include "mbed.h" +#include "HIDScope.h" +#include "encoder.h" +#include "Filter.h" + +AnalogIn emg(A0); //Analog input van emg kabels +Ticker EMGticker; +HIDScope scope(2); //2 scopes + +// constante variabelen: + +//Sample frequentie +Fs = 500; //Hz +t = 1/ Fs; // voor EMGticker + +// Filter1a: 50Hz Notch +double v1_50a = 0, v2_50a = 0; +const double a1_50a = -1.61803398875, a2_50a = 1.00000000000; +const double b0_50a = 1.00000000000, b1_50a = -1.61803398875, b2_50a = 1.00000000000; + +// Filter1b: 50Hz Notch +double v1_50b = 0, v2_50b = 0; +const double a1_50b = -1.61803398875, a2_50b = 1.00000000000; +const double b0_50b = 1.00000000000, b1_50b = -1.61803398875, b2_50b = 1.00000000000; + +// Filter1: 20Hz HighPass +double v1_HP = 0, v2_HP = 0; +const double a1_HP = -0.76475499450, a2_HP = 0.27692273367; +const double b0_HP = 1.00000000000, b1_HP = -2.00000000000, b2_HP = 1.00000000000; + +// Filter1: 5Hz LowPass +double v1_LP = 0, v2_LP = 0; +const double a1_LP = -1.16338171052, a2_LP = 0.42191097989; +const double b0_LP = 1.00000000000, b1_LP = 2.00000000000, b2_LP = 1.00000000000; + + +void EMGfilter() +{ + //u = input waarde + //y = output waarde + + double u = emg.read(); // lees waarde van emg signaal uit + + // Op deze manier worden de waardes ingelezen in Filter. Zorg dus voor dezelfde volgorde, zodat de waardes goed uitgelezen worden!: + // Filter(double u, double &v1, double &v2, const double a1, const double a2, const double b0, const double b1, const double b2) + + // 50Hz Notch filter + double y50a = double Filter(u, v1_50a, v2_50a, a1_50a, a2_50a, b0_50a, b1_50a, b2_50a); + double y50b = double Filter(y50a, v1_50b, v2_50b, a1_50b, a2_50b, b0_50b, b1_50b, b2_50b); + + // High Pass filter. Tot 20Hz wordt weggefliterd + double yHP = double Filter(y50b, v1_HP, v2_HP, a1_HP, a2_HP, b0_HP, b1_HP, b2_HP); + + // Absolute waarde wordt genomen. + double y1 = fabs(yHP); + + // Low Pass filter. Alles vanaf 5Hz wordt weggefilterd + double yLP = double Filter(y1, v1_LP, v2_LP, a1_LP, a2_LP, b0_LP, b1_LP, b2_LP); + + double y = yLP; + + // Plotten in HIDscope + scope.set(0,u); //ongefilterde waarde naar scope 1 + scope.set(1,y); //gefilterde waarde naar scope 2 + scope.send(); //stuur de waardes naar HIDscope +} + + +int main(){ + EMGticker.attach(&EMGfilter, t) //500Hz + while(1){} + } + \ No newline at end of file