EMG signals all around zero, not showing differences anymore in hidscope

Dependencies:   HIDScope MODSERIAL biquadFilter mbed

Fork of a_check_emg_filtered_without_cal by Daniqe Kottelenberg

Committer:
daniQQue
Date:
Mon Oct 24 11:24:50 2016 +0000
Revision:
15:bb4a6c7836d8
Parent:
14:5b17697cf775
Child:
16:fd4521a4f0b3
werkend, met filters van flooortje;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daniQQue 0:34c739fcc3e0 1 //libraries
daniQQue 0:34c739fcc3e0 2 #include "mbed.h"
daniQQue 0:34c739fcc3e0 3 #include "HIDScope.h"
daniQQue 14:5b17697cf775 4 #include "BiQuad.h"
daniQQue 0:34c739fcc3e0 5
daniQQue 0:34c739fcc3e0 6 //Define objects
daniQQue 15:bb4a6c7836d8 7 AnalogIn emg_biceps_right_in( A0 ); //analog in to get EMG in to c++
daniQQue 0:34c739fcc3e0 8 Ticker sample_timer; //ticker
daniQQue 14:5b17697cf775 9 HIDScope scope( 3); //open 3 channels in hidscope
daniQQue 8:cd0cb71b69f2 10 DigitalOut richting_motor1(D4); //motor1 direction output
daniQQue 8:cd0cb71b69f2 11 PwmOut pwm_motor1(D5); //motor1 velocity output
daniQQue 0:34c739fcc3e0 12 DigitalOut led(LED_GREEN);
daniQQue 0:34c739fcc3e0 13
daniQQue 0:34c739fcc3e0 14 //define variables
daniQQue 15:bb4a6c7836d8 15 double emg_biceps_right;
daniQQue 15:bb4a6c7836d8 16 double emg_filtered_high_biceps_right;
daniQQue 15:bb4a6c7836d8 17 double emg_abs_biceps_right;
daniQQue 15:bb4a6c7836d8 18 double emg_filtered_biceps_right;
daniQQue 7:42d0e38196f1 19 int onoffsignal=0;
daniQQue 15:bb4a6c7836d8 20 double cut_off_value=0.08; //gespecifeerd door floortje
daniQQue 5:688b1b5530d8 21
daniQQue 15:bb4a6c7836d8 22 BiQuad filterhigh(9.5654e-01,-1.9131e+00,9.5654e-01,-1.9112e+00,9.1498e-01);
daniQQue 15:bb4a6c7836d8 23 BiQuad filterlow (6.2942e-06, 1.2588e-05,6.2942e-06,-1.9929e+00,9.9292e-01);
daniQQue 10:7255b59224cc 24
daniQQue 15:bb4a6c7836d8 25 //functions which are called in ticker
daniQQue 0:34c739fcc3e0 26 void filter(){
daniQQue 15:bb4a6c7836d8 27 emg_biceps_right=emg_biceps_right_in.read(); //read the emg value from the elektrodes
daniQQue 15:bb4a6c7836d8 28 emg_filtered_high_biceps_right= filterhigh.step(emg_biceps_right);
daniQQue 15:bb4a6c7836d8 29 emg_abs_biceps_right=fabs(emg_filtered_high_biceps_right); //fabs because float
daniQQue 15:bb4a6c7836d8 30 emg_filtered_biceps_right=filterlow.step(emg_abs_biceps_right);
daniQQue 0:34c739fcc3e0 31 led=!led;
daniQQue 7:42d0e38196f1 32
daniQQue 15:bb4a6c7836d8 33 if (emg_filtered_biceps_right>cut_off_value)
daniQQue 7:42d0e38196f1 34 {onoffsignal=1;}
daniQQue 7:42d0e38196f1 35
daniQQue 7:42d0e38196f1 36 else
daniQQue 7:42d0e38196f1 37 {onoffsignal=0;}
daniQQue 7:42d0e38196f1 38
daniQQue 0:34c739fcc3e0 39 //send signals to scope
daniQQue 15:bb4a6c7836d8 40 scope.set(0, emg_biceps_right ); //set emg signal to scope in channel 1
daniQQue 15:bb4a6c7836d8 41 scope.set(1, emg_filtered_biceps_right);
daniQQue 14:5b17697cf775 42 scope.set(2, onoffsignal);
daniQQue 0:34c739fcc3e0 43 scope.send(); //send all the signals to the scope
daniQQue 0:34c739fcc3e0 44 }
daniQQue 0:34c739fcc3e0 45
daniQQue 0:34c739fcc3e0 46 //program
daniQQue 0:34c739fcc3e0 47
daniQQue 0:34c739fcc3e0 48 int main()
daniQQue 0:34c739fcc3e0 49 {
daniQQue 0:34c739fcc3e0 50 sample_timer.attach(&filter, 0.001); //continously execute the EMG reader and filter, it ensures that filter and sampling is executed every 1/frequency seconds
daniQQue 4:7d9ca9c1dcce 51
daniQQue 0:34c739fcc3e0 52 //endless loop
daniQQue 0:34c739fcc3e0 53
daniQQue 0:34c739fcc3e0 54 while(1)
daniQQue 8:cd0cb71b69f2 55 {
daniQQue 8:cd0cb71b69f2 56 if (onoffsignal==1)
daniQQue 8:cd0cb71b69f2 57 {
daniQQue 8:cd0cb71b69f2 58 richting_motor1 = 0; //motordirection (ccw)
daniQQue 10:7255b59224cc 59 pwm_motor1 = 1; //motorspeed 1
daniQQue 8:cd0cb71b69f2 60
daniQQue 8:cd0cb71b69f2 61 }
daniQQue 8:cd0cb71b69f2 62 else if(onoffsignal==0)
daniQQue 8:cd0cb71b69f2 63 {
daniQQue 8:cd0cb71b69f2 64 richting_motor1 = 0; //motordirection (ccw)
daniQQue 8:cd0cb71b69f2 65 pwm_motor1 = 0; //motorspeed 0
daniQQue 8:cd0cb71b69f2 66
daniQQue 8:cd0cb71b69f2 67 }
daniQQue 8:cd0cb71b69f2 68
daniQQue 8:cd0cb71b69f2 69 }
daniQQue 0:34c739fcc3e0 70
daniQQue 0:34c739fcc3e0 71 }