EMG+filter

Dependencies:   mbed HIDScope biquadFilter biquad

Committer:
Rosalie
Date:
Tue Oct 15 12:55:03 2019 +0000
Revision:
22:782e4eac9796
Parent:
21:7932900d6e3b
Child:
23:71103eda6fa2
EMG+biquad maar zonder goede coefficienten

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"
Rosalie 22:782e4eac9796 3 #include "BiQuad.h"
vsluiter 0:32bb76391d89 4
vsluiter 4:8b298dfada81 5 //Define objects
tomlankhorst 19:2bf824669684 6 AnalogIn emg0( A0 );
tomlankhorst 19:2bf824669684 7 AnalogIn emg1( A1 );
tomlankhorst 19:2bf824669684 8
tomlankhorst 14:f83354387756 9 Ticker sample_timer;
tomlankhorst 19:2bf824669684 10 HIDScope scope( 2 );
tomlankhorst 18:21d8e7a81cf5 11 DigitalOut led(LED1);
vsluiter 2:e314bb3b2d99 12
Rosalie 22:782e4eac9796 13 BiQuadChain bqc;
Rosalie 22:782e4eac9796 14 BiQuad bq1(b0, b1, b2, a1, a2); //bijvoorbeeld van rechterbiceps
Rosalie 22:782e4eac9796 15 BiQuad bq2(b00, b11, b22, a11, a22); //bijvoorbeeld van linkerbiceps
Rosalie 22:782e4eac9796 16
Rosalie 22:782e4eac9796 17 Ticker emgSampleTicker;
Rosalie 22:782e4eac9796 18 AnalogIn emg(A0); //kloptA0 wel??
Rosalie 22:782e4eac9796 19
tomlankhorst 14:f83354387756 20 /** Sample function
tomlankhorst 14:f83354387756 21 * this function samples the emg and sends it to HIDScope
tomlankhorst 14:f83354387756 22 **/
tomlankhorst 14:f83354387756 23 void sample()
vsluiter 2:e314bb3b2d99 24 {
tomlankhorst 19:2bf824669684 25 /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
tomlankhorst 19:2bf824669684 26 scope.set(0, emg0.read() );
tomlankhorst 19:2bf824669684 27 scope.set(1, emg1.read() );
tomlankhorst 19:2bf824669684 28 /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels)
tomlankhorst 19:2bf824669684 29 * Ensure that enough channels are available (HIDScope scope( 2 ))
tomlankhorst 20:97059009a491 30 * Finally, send all channels to the PC at once */
vsluiter 11:ce72ec658a95 31 scope.send();
tomlankhorst 18:21d8e7a81cf5 32 /* To indicate that the function is working, the LED is toggled */
tomlankhorst 18:21d8e7a81cf5 33 led = !led;
vsluiter 2:e314bb3b2d99 34 }
vsluiter 0:32bb76391d89 35
Rosalie 22:782e4eac9796 36
Rosalie 22:782e4eac9796 37
Rosalie 22:782e4eac9796 38
Rosalie 22:782e4eac9796 39
Rosalie 22:782e4eac9796 40 void emgSample()
Rosalie 22:782e4eac9796 41 {
Rosalie 22:782e4eac9796 42 double emgFiltered=bqc.step(emg.read());
Rosalie 22:782e4eac9796 43 }
Rosalie 22:782e4eac9796 44
Rosalie 22:782e4eac9796 45
Rosalie 22:782e4eac9796 46
Rosalie 22:782e4eac9796 47
vsluiter 0:32bb76391d89 48 int main()
tomlankhorst 19:2bf824669684 49 {
tomlankhorst 14:f83354387756 50 /**Attach the 'sample' function to the timer 'sample_timer'.
tomlankhorst 19:2bf824669684 51 * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
vsluiter 4:8b298dfada81 52 */
WiesjeRoskamp 21:7932900d6e3b 53 sample_timer.attach(&sample, 0.002f);
Rosalie 22:782e4eac9796 54 bqc.add(&bq1).add(&bq2);
Rosalie 22:782e4eac9796 55 emgSampleTicker.attach(&emgSample,0.01);
tomlankhorst 15:0da764eea774 56
tomlankhorst 14:f83354387756 57 /*empty loop, sample() is executed periodically*/
WiesjeRoskamp 21:7932900d6e3b 58 while(1) {
WiesjeRoskamp 21:7932900d6e3b 59 wait(0.1f);
WiesjeRoskamp 21:7932900d6e3b 60 }
vsluiter 0:32bb76391d89 61 }