filters emg signaal

Dependencies:   HIDScope MODSERIAL biquadFilter mbed

Committer:
Roooos
Date:
Mon Oct 22 08:13:40 2018 +0000
Revision:
0:9fc3cc2f74db
filters emg groep 2;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Roooos 0:9fc3cc2f74db 1 #include "mbed.h"
Roooos 0:9fc3cc2f74db 2 #include "HIDScope.h"
Roooos 0:9fc3cc2f74db 3 //#include "BiQuad.h"
Roooos 0:9fc3cc2f74db 4
Roooos 0:9fc3cc2f74db 5 //Define EMG parameters
Roooos 0:9fc3cc2f74db 6 AnalogIn emg0(A0); //emg signaal 1
Roooos 0:9fc3cc2f74db 7 Ticker sample_timer;
Roooos 0:9fc3cc2f74db 8 HIDScope scope( 2 ); // aantal channels op de HIDscope
Roooos 0:9fc3cc2f74db 9 volatile double emg_1;
Roooos 0:9fc3cc2f74db 10 DigitalOut led(LED_GREEN);
Roooos 0:9fc3cc2f74db 11
Roooos 0:9fc3cc2f74db 12
Roooos 0:9fc3cc2f74db 13
Roooos 0:9fc3cc2f74db 14 //compute biquad function door Biquad(b0, b1, b2, a0, a1) in te vullen
Roooos 0:9fc3cc2f74db 15 //BiQuadChain bqc; //chain voor High Pass en Notch
Roooos 0:9fc3cc2f74db 16 //BiQuad bq1(0.39131200825291007, -0.7826240165058201, 0.39131200825291007, -0.36950493743858204, 0.1957430955730582); //High Pass Filter
Roooos 0:9fc3cc2f74db 17 //BiQuad bq2( 9.91104e-01, -1.60364e+00, 9.91104e-01, -1.60364e+00, 9.82207e-01); //Notch Filter
Roooos 0:9fc3cc2f74db 18 //BiQuad bq3(0.06947941610796837, 0.13895883221593675, 0.06947941610796837, -1.1772781186813919, 0.4551957831132653); //Low Pass Filter
Roooos 0:9fc3cc2f74db 19
Roooos 0:9fc3cc2f74db 20
Roooos 0:9fc3cc2f74db 21 void sample()
Roooos 0:9fc3cc2f74db 22 {
Roooos 0:9fc3cc2f74db 23 emg_1 = emg0.read(); //EMG signal
Roooos 0:9fc3cc2f74db 24 // double FilterStep1 = bqc.step(emg_1); //High Pass + Notch
Roooos 0:9fc3cc2f74db 25 //double RectifyEMG = fabs(FilterStep1); //Rectify Signal
Roooos 0:9fc3cc2f74db 26 // double Filtered_emg_1 = bq3.step(RectifyEMG); //Low Pass
Roooos 0:9fc3cc2f74db 27
Roooos 0:9fc3cc2f74db 28 // scope.set(0,emg_1); //set raw emg signal
Roooos 0:9fc3cc2f74db 29 // scope.set(1,Filtered_emg_1); //set filtered emg signal
Roooos 0:9fc3cc2f74db 30
Roooos 0:9fc3cc2f74db 31 // scope.send(); //send to hidscope
Roooos 0:9fc3cc2f74db 32 }
Roooos 0:9fc3cc2f74db 33
Roooos 0:9fc3cc2f74db 34 int main()
Roooos 0:9fc3cc2f74db 35 {
Roooos 0:9fc3cc2f74db 36 led = 0;
Roooos 0:9fc3cc2f74db 37 // bqc.add( &bq1 ).add( &bq2 ); //make BiQuadChain
Roooos 0:9fc3cc2f74db 38 sample_timer.attach(&sample, 0.002); //500 Hz
Roooos 0:9fc3cc2f74db 39 while (1) {}
Roooos 0:9fc3cc2f74db 40 }