EMG signalen uitlezen met filters
Dependencies: HIDScope biquadFilter mbed
main.cpp
- Committer:
- laurette
- Date:
- 2016-10-27
- Revision:
- 1:0d62559f43af
- Parent:
- 0:5759df060d75
- Child:
- 2:5df98e0832d6
File content as of revision 1:0d62559f43af:
#include "mbed.h" #include "HIDScope.h" #include "BiQuad.h" //Define EMG input AnalogIn emg0( A0 ); AnalogIn emg1( A1 ); AnalogIn emg2( A2 ); Ticker sample_timer; HIDScope scope( 3 ); // 3-channel HIDScope object // Filter coordinates of lowpass/highpass filter before rectifier and lowpassfilter for the envelope const double b0_low = 0.2929, b1_low = 0.5858, b2_low = 0.2929, a1_low = 0, a2_low = 0.1716; const double b0_high = 0.9912, b1_high = -1.9823, b2_high = 0.9912, a1_high = -1.9822, a2_high = 0.9824; const double b0_envelope = 6.1006E-5, b1_envelope = 1.2201E-4, b2_envelope = 6.1006E-5, a1_envelope = -1.9776, a2_envelope = 0.9780; double y1, y2, y3; // Gefilterde output // Biquad filters (lowpass and highpass become a chain in the int main) BiQuad lowpass(b0_low, b1_low , b2_low, a1_low, a2_low); BiQuad highpass(b0_high, b1_high , b2_high, a1_high, a2_high); BiQuad envelope(b0_envelope, b1_envelope , b2_envelope, a1_envelope, a2_envelope); BiQuadChain bandpass; // Sample function, this function samples the emg and sends it to HIDScope void filtering() { y1 = bandpass.step(emg0); y2 = bandpass.step(emg1); y3 = bandpass.step(emg2); y1 = fabs(y1); y2 = fabs(y2); y3 = fabs(y3); y1 = envelope.step(y1); y2 = envelope.step(y2); y3 = envelope.step(y3); // Set the sampled and filtered emg values in channel 0/1/2 in the 'HIDScope' instance named 'scope' scope.set(0, y1 ); scope.set(1, y2 ); scope.set(2, y3 ); scope.send(); // Sends all channels to the PC at once } int main() { bandpass.add(&lowpass).add(&highpass); sample_timer.attach(&filtering, 0.001); // Attach the 'sample' function to the timer 'sample_timer'. This ensures that 'sample' is executed every 0.001 seconds = 1000 Hz while(1) {} // Empty loop, sample() is executed periodically }