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 09:55:48 2016 +0000
Revision:
13:6c2daab3547b
Parent:
12:a76f9b33fbcb
Child:
14:5b17697cf775
1 scope, coeff floor;

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 4:7d9ca9c1dcce 4 #include "biquadFilter.h"
daniQQue 0:34c739fcc3e0 5
daniQQue 0:34c739fcc3e0 6 //Define objects
daniQQue 0:34c739fcc3e0 7 AnalogIn emg0( A0 ); //analog in to get EMG in to c++
daniQQue 0:34c739fcc3e0 8 Ticker sample_timer; //ticker
daniQQue 13:6c2daab3547b 9 HIDScope scope(1); //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 0:34c739fcc3e0 15 double emg_0_value;
daniQQue 10:7255b59224cc 16 double emg_gefilterd;
daniQQue 7:42d0e38196f1 17 double emg_abs;
daniQQue 7:42d0e38196f1 18 int onoffsignal=0;
daniQQue 13:6c2daab3547b 19 double cut_off_value=0.; //gespecifeerd door floortje
daniQQue 5:688b1b5530d8 20
daniQQue 13:6c2daab3547b 21 biquadFilter filterhigh1(9.5654e-01,-1.9131e+00,9.5654e-01,-1.9112e+00,9.1498e-01);
daniQQue 10:7255b59224cc 22
daniQQue 8:cd0cb71b69f2 23
daniQQue 0:34c739fcc3e0 24 void filter(){
daniQQue 13:6c2daab3547b 25 emg_0_value=emg0.read(); //read the emg value from the elektrodes
daniQQue 10:7255b59224cc 26 emg_gefilterd= filterhigh1.step(emg_0_value);
daniQQue 10:7255b59224cc 27 emg_abs=abs(emg_gefilterd);
daniQQue 0:34c739fcc3e0 28 led=!led;
daniQQue 7:42d0e38196f1 29
daniQQue 13:6c2daab3547b 30 if (emg_abs>cut_off_value)
daniQQue 7:42d0e38196f1 31 {onoffsignal=1;}
daniQQue 7:42d0e38196f1 32
daniQQue 7:42d0e38196f1 33 else
daniQQue 7:42d0e38196f1 34 {onoffsignal=0;}
daniQQue 7:42d0e38196f1 35
daniQQue 0:34c739fcc3e0 36 //send signals to scope
daniQQue 1:30d46f7e5150 37 scope.set(0, emg_0_value ); //set emg signal to scope in channel 1
daniQQue 0:34c739fcc3e0 38 scope.send(); //send all the signals to the scope
daniQQue 0:34c739fcc3e0 39 }
daniQQue 0:34c739fcc3e0 40
daniQQue 0:34c739fcc3e0 41 //program
daniQQue 0:34c739fcc3e0 42
daniQQue 0:34c739fcc3e0 43 int main()
daniQQue 0:34c739fcc3e0 44 {
daniQQue 0:34c739fcc3e0 45 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 46
daniQQue 0:34c739fcc3e0 47 //endless loop
daniQQue 0:34c739fcc3e0 48
daniQQue 0:34c739fcc3e0 49 while(1)
daniQQue 8:cd0cb71b69f2 50 {
daniQQue 8:cd0cb71b69f2 51 if (onoffsignal==1)
daniQQue 8:cd0cb71b69f2 52 {
daniQQue 8:cd0cb71b69f2 53 richting_motor1 = 0; //motordirection (ccw)
daniQQue 10:7255b59224cc 54 pwm_motor1 = 1; //motorspeed 1
daniQQue 8:cd0cb71b69f2 55
daniQQue 8:cd0cb71b69f2 56 }
daniQQue 8:cd0cb71b69f2 57 else if(onoffsignal==0)
daniQQue 8:cd0cb71b69f2 58 {
daniQQue 8:cd0cb71b69f2 59 richting_motor1 = 0; //motordirection (ccw)
daniQQue 8:cd0cb71b69f2 60 pwm_motor1 = 0; //motorspeed 0
daniQQue 8:cd0cb71b69f2 61
daniQQue 8:cd0cb71b69f2 62 }
daniQQue 8:cd0cb71b69f2 63
daniQQue 8:cd0cb71b69f2 64 }
daniQQue 0:34c739fcc3e0 65
daniQQue 0:34c739fcc3e0 66 }