emg with text

Dependencies:   HIDScope MODSERIAL biquadFilter mbed

Fork of emg_import by Daniqe Kottelenberg

Committer:
daniQQue
Date:
Mon Oct 31 15:11:42 2016 +0000
Revision:
39:c933a6c2b730
Parent:
38:23601b26bb84
Child:
40:187ef29de53d
1 EMG signal biceps, new notch filter with new coefficients from matlab, works perfectly!!

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 38:23601b26bb84 20 double cut_off_value=0.04; //gespecifeerd door floortje
daniQQue 5:688b1b5530d8 21
daniQQue 37:60dd2e42bf8f 22 BiQuad filterhigh(9.1497e-01, -1.8299e+00, 9.1497e-01, -1.8227e+00, 8.3718e-01); //
daniQQue 37:60dd2e42bf8f 23 BiQuad filterlow ( 3.9130e-05 , 7.8260e-05 , 3.9130e-05, -1.9822e+00 , 9.8239e-01); //
daniQQue 39:c933a6c2b730 24 BiQuad notch( 9.9376e-01 , -1.8902e-00, 9.9376e-01 , -1.8902e-00 , 9.875e-01);
daniQQue 10:7255b59224cc 25
daniQQue 15:bb4a6c7836d8 26 //functions which are called in ticker
daniQQue 0:34c739fcc3e0 27 void filter(){
daniQQue 15:bb4a6c7836d8 28 emg_biceps_right=emg_biceps_right_in.read(); //read the emg value from the elektrodes
daniQQue 15:bb4a6c7836d8 29 emg_filtered_high_biceps_right= filterhigh.step(emg_biceps_right);
daniQQue 38:23601b26bb84 30 double emg_filtered_notch=notch.step(emg_filtered_high_biceps_right);
daniQQue 38:23601b26bb84 31 emg_abs_biceps_right=fabs(emg_filtered_notch); //fabs because float
daniQQue 15:bb4a6c7836d8 32 emg_filtered_biceps_right=filterlow.step(emg_abs_biceps_right);
daniQQue 0:34c739fcc3e0 33 led=!led;
daniQQue 7:42d0e38196f1 34
daniQQue 15:bb4a6c7836d8 35 if (emg_filtered_biceps_right>cut_off_value)
daniQQue 7:42d0e38196f1 36 {onoffsignal=1;}
daniQQue 7:42d0e38196f1 37
daniQQue 7:42d0e38196f1 38 else
daniQQue 37:60dd2e42bf8f 39 {onoffsignal=0;}
daniQQue 7:42d0e38196f1 40
daniQQue 0:34c739fcc3e0 41 //send signals to scope
daniQQue 39:c933a6c2b730 42 scope.set(0, emg_biceps_right ); //set emg signal to scope in channel 1
daniQQue 37:60dd2e42bf8f 43 scope.set(1, emg_abs_biceps_right);
daniQQue 37:60dd2e42bf8f 44 scope.set(2, emg_filtered_biceps_right);
daniQQue 37:60dd2e42bf8f 45 scope.send(); //send all the signals to the scope
daniQQue 0:34c739fcc3e0 46 }
daniQQue 0:34c739fcc3e0 47
daniQQue 0:34c739fcc3e0 48 //program
daniQQue 0:34c739fcc3e0 49
daniQQue 0:34c739fcc3e0 50 int main()
daniQQue 0:34c739fcc3e0 51 {
daniQQue 0:34c739fcc3e0 52 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 53
daniQQue 0:34c739fcc3e0 54 //endless loop
daniQQue 0:34c739fcc3e0 55
daniQQue 0:34c739fcc3e0 56 while(1)
daniQQue 8:cd0cb71b69f2 57 {
daniQQue 8:cd0cb71b69f2 58 if (onoffsignal==1)
daniQQue 8:cd0cb71b69f2 59 {
daniQQue 8:cd0cb71b69f2 60 richting_motor1 = 0; //motordirection (ccw)
daniQQue 10:7255b59224cc 61 pwm_motor1 = 1; //motorspeed 1
daniQQue 8:cd0cb71b69f2 62
daniQQue 8:cd0cb71b69f2 63 }
daniQQue 8:cd0cb71b69f2 64 else if(onoffsignal==0)
daniQQue 8:cd0cb71b69f2 65 {
daniQQue 8:cd0cb71b69f2 66 richting_motor1 = 0; //motordirection (ccw)
daniQQue 8:cd0cb71b69f2 67 pwm_motor1 = 0; //motorspeed 0
daniQQue 8:cd0cb71b69f2 68
daniQQue 8:cd0cb71b69f2 69 }
daniQQue 8:cd0cb71b69f2 70
daniQQue 8:cd0cb71b69f2 71 }
daniQQue 0:34c739fcc3e0 72
daniQQue 0:34c739fcc3e0 73 }