EMG signalen uitlezen met filters
Dependencies: HIDScope biquadFilter mbed
Diff: main.cpp
- Revision:
- 4:d3c27bbe694f
- Parent:
- 3:dfc08485b1b2
--- a/main.cpp Fri Oct 28 09:56:18 2016 +0000 +++ b/main.cpp Fri Oct 28 11:40:57 2016 +0000 @@ -18,23 +18,31 @@ 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; +BiQuad lowpass1(b0_low, b1_low , b2_low, a1_low, a2_low); +BiQuad lowpass2(b0_low, b1_low , b2_low, a1_low, a2_low); +BiQuad lowpass3(b0_low, b1_low , b2_low, a1_low, a2_low); +BiQuad highpass1(b0_high, b1_high , b2_high, a1_high, a2_high); +BiQuad highpass2(b0_high, b1_high , b2_high, a1_high, a2_high); +BiQuad highpass3(b0_high, b1_high , b2_high, a1_high, a2_high); +BiQuad envelope1(b0_envelope, b1_envelope , b2_envelope, a1_envelope, a2_envelope); +BiQuad envelope2(b0_envelope, b1_envelope , b2_envelope, a1_envelope, a2_envelope); +BiQuad envelope3(b0_envelope, b1_envelope , b2_envelope, a1_envelope, a2_envelope); +BiQuadChain bandpass1; +BiQuadChain bandpass2; +BiQuadChain bandpass3; // 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 = bandpass1.step(emg0); + y2 = bandpass2.step(emg1); + y3 = bandpass3.step(emg2); y1 = fabs(y1); y2 = fabs(y2); y3 = fabs(y3); - y1 = envelope.step(y1); - y2 = envelope.step(y2); - y3 = envelope.step(y3); + y1 = envelope1.step(y1); + y2 = envelope2.step(y2); + y3 = envelope3.step(y3); // Set the sampled and filtered emg values in channel 0/1/2 in the 'HIDScope' instance named 'scope' scope.set(0, y1 ); @@ -46,7 +54,9 @@ int main() { - bandpass.add(&lowpass).add(&highpass); + bandpass1.add(&lowpass1).add(&highpass1); + bandpass2.add(&lowpass2).add(&highpass2); + bandpass3.add(&lowpass3).add(&highpass3); 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