emg2
Dependencies: HIDScope biquadFilter mbed QEI
Fork of EMG by
main.cpp
- Committer:
- s1574396
- Date:
- 2018-10-29
- Revision:
- 24:6bdc50e21805
- Parent:
- 23:dec549767006
- Child:
- 25:02f183b944ed
File content as of revision 24:6bdc50e21805:
#include "mbed.h" #include "HIDScope.h" #include "BiQuad.h" HIDScope scope( 2 ); Ticker sample_timer; // Inputs EMG AnalogIn emg0_in( A0 ); AnalogIn emg1_in( A1 ); AnalogIn emg2_in( A2 ); // Constants EMG const double m1 = 0.5000; const double m2 = -0.8090; const double n0 = 0.5000; const double n1 = -0.8090; const double n2 = 0; const double a1 = 0.9565; const double a2 = -1.9131; const double b0 = 0.9565; const double b1 = -1.9112; const double b2 = 0.9150; const double c1 = 0.0675; const double c2 = 0.1349; const double d0 = 0.0675; const double d1 = -1.1430; const double d2 = 0.4128; // Variables EMG double emg0; double emg1; double emg2; double notch0; double notch1; double notch2; double high0; double high1; double high2; double absolute0; double absolute1; double absolute2; double low0; double low1; double low2; // BiQuad values BiQuadChain notch; BiQuad N1( m1, m2, n0, n1, n2); BiQuad N2( m1, m2, n0, n1, n2); BiQuad N3( m1, m2, n0, n1, n2); BiQuadChain highpass; BiQuad H1( a1, a2, b0, b1, b2); BiQuad H2( a1, a2, b0, b1, b2); BiQuad H3( a1, a2, b0, b1, b2); BiQuadChain lowpass; BiQuad L1( c1, c2, d0, d1, d2); BiQuad L2( c1, c2, d0, d1, d2); BiQuad L3( c1, c2, d0, d1, d2); // Filter of the first EMG signal void filtering() { emg0 = emg0_in.read(); // Reading the EMG signal emg1 = emg1_in.read(); emg2 = emg2_in.read(); notch0 = N1.step(emg0); // Applying a notch filter over the EMG data notch1 = N2.step(emg1); notch2 = N3.step(emg2); high0 = H1.step(notch0); // Applying a high pass filter high1 = H2.step(notch1); high2 = H3.step(notch2); absolute0 = fabs(high0); // Rectifying the signal absolute1 = fabs(high1); absolute2 = fabs(high2); low0 = L1.step(absolute0); // Applying low pass filter low1 = L2.step(absolute1); low2 = L3.step(absolute2); scope.set(0,emg0); // Sending the signal to the HIDScope scope.set(1,low0); scope.send(); } int main() { sample_timer.attach(&filtering, 0.002); while(1) {} }