the emg filtering part of the program

Dependencies:   HIDScope biquadFilter mbed MODSERIAL

Fork of EMG by Tom Tom

Committer:
RiP
Date:
Tue Oct 18 15:29:45 2016 +0000
Revision:
21:3aecd735319d
Parent:
20:97059009a491
Child:
22:f38a15e851d2
3 emg signals+ filtering;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsluiter 0:32bb76391d89 1 #include "mbed.h"
vsluiter 11:ce72ec658a95 2 #include "HIDScope.h"
RiP 21:3aecd735319d 3 #include "BiQuad.h"
vsluiter 0:32bb76391d89 4
vsluiter 4:8b298dfada81 5 //Define objects
RiP 21:3aecd735319d 6 AnalogIn emg1( A0 );
RiP 21:3aecd735319d 7 AnalogIn emg2( A1 );
RiP 21:3aecd735319d 8 AnalogIn emg3( A2 );
tomlankhorst 19:2bf824669684 9
tomlankhorst 14:f83354387756 10 Ticker sample_timer;
RiP 21:3aecd735319d 11 HIDScope scope( 6 );
tomlankhorst 18:21d8e7a81cf5 12 DigitalOut led(LED1);
vsluiter 2:e314bb3b2d99 13
RiP 21:3aecd735319d 14 BiQuadChain bqc11;
RiP 21:3aecd735319d 15 BiQuadChain bqc13;
RiP 21:3aecd735319d 16 BiQuadChain bqc21;
RiP 21:3aecd735319d 17 BiQuadChain bqc23;
RiP 21:3aecd735319d 18 BiQuadChain bqc31;
RiP 21:3aecd735319d 19 BiQuadChain bqc33;
RiP 21:3aecd735319d 20 //BiQuad bq11( 9.87589e-01, -1.59795e+00, 9.87589e-01, -1.59795e+00, 9.75178e-01 ); //oude BiQuad waardes
RiP 21:3aecd735319d 21 /* BiQuads for filter emg1
RiP 21:3aecd735319d 22 notch filter*/
RiP 21:3aecd735319d 23 BiQuad bq111(0.9795, -1.5849, 0.9795, 1.0000, -1.5849, 0.9589);
RiP 21:3aecd735319d 24 BiQuad bq112(0.9833, -1.5912, 0.9833, 1.0000, -1.5793, 0.9787);
RiP 21:3aecd735319d 25 BiQuad bq113(0.9957, -1.6111, 0.9957, 1.0000, -1.6224, 0.9798);
RiP 21:3aecd735319d 26 /* High pass filter*/
RiP 21:3aecd735319d 27 BiQuad bq121( 9.56543e-01, -1.91309e+00, 9.56543e-01, -1.91120e+00, 9.14976e-01 );
RiP 21:3aecd735319d 28 /* low pass filter*/
RiP 21:3aecd735319d 29 BiQuad bq131( 3.91302e-05, 7.82604e-05, 3.91302e-05, -1.98223e+00, 9.82385e-01 );
RiP 21:3aecd735319d 30
RiP 21:3aecd735319d 31
RiP 21:3aecd735319d 32 /* BiQuads for filter emg2
RiP 21:3aecd735319d 33 notch filter*/
RiP 21:3aecd735319d 34 BiQuad bq211(0.9795, -1.5849, 0.9795, 1.0000, -1.5849, 0.9589);
RiP 21:3aecd735319d 35 BiQuad bq212(0.9833, -1.5912, 0.9833, 1.0000, -1.5793, 0.9787);
RiP 21:3aecd735319d 36 BiQuad bq213(0.9957, -1.6111, 0.9957, 1.0000, -1.6224, 0.9798);
RiP 21:3aecd735319d 37 /* High pass filter*/
RiP 21:3aecd735319d 38 BiQuad bq221( 9.56543e-01, -1.91309e+00, 9.56543e-01, -1.91120e+00, 9.14976e-01 );
RiP 21:3aecd735319d 39 /* low pass filter*/
RiP 21:3aecd735319d 40 BiQuad bq231( 3.91302e-05, 7.82604e-05, 3.91302e-05, -1.98223e+00, 9.82385e-01 );
RiP 21:3aecd735319d 41
RiP 21:3aecd735319d 42 /* BiQuads for filter emg3
RiP 21:3aecd735319d 43 notch filter*/
RiP 21:3aecd735319d 44 BiQuad bq311(0.9795, -1.5849, 0.9795, 1.0000, -1.5849, 0.9589);
RiP 21:3aecd735319d 45 BiQuad bq312(0.9833, -1.5912, 0.9833, 1.0000, -1.5793, 0.9787);
RiP 21:3aecd735319d 46 BiQuad bq313(0.9957, -1.6111, 0.9957, 1.0000, -1.6224, 0.9798);
RiP 21:3aecd735319d 47 /* High pass filter*/
RiP 21:3aecd735319d 48 BiQuad bq321( 9.56543e-01, -1.91309e+00, 9.56543e-01, -1.91120e+00, 9.14976e-01 );
RiP 21:3aecd735319d 49 /* low pass filter*/
RiP 21:3aecd735319d 50 BiQuad bq331( 3.91302e-05, 7.82604e-05, 3.91302e-05, -1.98223e+00, 9.82385e-01 );
RiP 21:3aecd735319d 51
tomlankhorst 14:f83354387756 52 void sample()
vsluiter 2:e314bb3b2d99 53 {
RiP 21:3aecd735319d 54 /* Read the emg signals and filter it*/
RiP 21:3aecd735319d 55
RiP 21:3aecd735319d 56 scope.set(0, emg1.read()); //original signal
RiP 21:3aecd735319d 57 double emg02=bqc13.step(fabs(bqc11.step(emg1.read())));
RiP 21:3aecd735319d 58 scope.set(1, emg02);
RiP 21:3aecd735319d 59 /* Read the second emg signal and filter it*/
RiP 21:3aecd735319d 60 scope.set(2, emg2.read()); //original signal
RiP 21:3aecd735319d 61 double emg12=bqc23.step(fabs(bqc21.step(emg2.read())));
RiP 21:3aecd735319d 62 scope.set(3, emg12);
RiP 21:3aecd735319d 63 /* Read the third emg signal and filter it*/
RiP 21:3aecd735319d 64 scope.set(4, emg3.read()); //original signal
RiP 21:3aecd735319d 65 double emg22=bqc33.step(fabs(bqc31.step(emg3.read())));
RiP 21:3aecd735319d 66 scope.set(5, emg22);
RiP 21:3aecd735319d 67
RiP 21:3aecd735319d 68 /* Ensure that enough channels are available (HIDScope scope( 2 ))
RiP 21:3aecd735319d 69 * Finally, send all channels to the PC at once */
vsluiter 11:ce72ec658a95 70 scope.send();
RiP 21:3aecd735319d 71 /* To indicate that the function is working, the LED is toggled */
tomlankhorst 18:21d8e7a81cf5 72 led = !led;
vsluiter 2:e314bb3b2d99 73 }
vsluiter 0:32bb76391d89 74
vsluiter 0:32bb76391d89 75 int main()
RiP 21:3aecd735319d 76 {
RiP 21:3aecd735319d 77 //de biquad chains instellen
RiP 21:3aecd735319d 78 bqc11.add( &bq111 ).add( &bq112 ).add( &bq113 ).add( &bq121 );
RiP 21:3aecd735319d 79 bqc13.add( &bq131);
RiP 21:3aecd735319d 80 bqc21.add( &bq211 ).add( &bq212 ).add( &bq213 ).add( &bq221 );
RiP 21:3aecd735319d 81 bqc23.add( &bq231);
RiP 21:3aecd735319d 82 bqc31.add( &bq311 ).add( &bq312 ).add( &bq313 ).add( &bq321 );
RiP 21:3aecd735319d 83 bqc33.add( &bq331);
RiP 21:3aecd735319d 84 /*Attach the 'sample' function to the timer 'sample_timer'.
RiP 21:3aecd735319d 85 this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
vsluiter 4:8b298dfada81 86 */
tomlankhorst 19:2bf824669684 87 sample_timer.attach(&sample, 0.002);
tomlankhorst 15:0da764eea774 88
RiP 21:3aecd735319d 89 /* empty loop, sample() is executed periodically*/
tomlankhorst 15:0da764eea774 90 while(1) {}
vsluiter 0:32bb76391d89 91 }