Poep Hoofd / Mbed 2 deprecated PoolRobot_Code

Dependencies:   HIDScope mbed MODSERIAL QEI

Committer:
Alex_Kyrl
Date:
Mon Oct 30 15:32:27 2017 +0000
Revision:
11:dd1976534a03
Parent:
7:c17f5473f4e1
Child:
15:a24b30061c5f
Testing motor PWM min

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Alex_Kyrl 6:452e301a105a 1 #include "EMG.h"
Alex_Kyrl 11:dd1976534a03 2 // This is a class to set different emg sensors it gets the raw emg as input and returns the filterd envelope of the signal
Alex_Kyrl 6:452e301a105a 3
Alex_Kyrl 11:dd1976534a03 4 EMG::EMG(PinName data) : _data(data) , MainsReject(0.940809296, -1.525271192, 0.940809296, 1.000000000, -1.525271192, 0.881618592) , // set the coeficients of all filters used in the code
Alex_Kyrl 11:dd1976534a03 5 Low_pass( 0.145323884, 0.290647768, 0.145323884, 1.000000000, -0.671029091, 0.252324626) , // all of the filters are objects of the class BiQuad.h
Alex_Kyrl 11:dd1976534a03 6 HiPass(0.914969144, -1.829938288, 0.914969144, 1.000000000, -1.822694925, 0.837181651) ,
john111222333 7:c17f5473f4e1 7 LoPass( 0.003621682, 0.007243363, 0.003621682, 1.000000000, -1.822694925, 0.837181651)
Alex_Kyrl 6:452e301a105a 8 {
Alex_Kyrl 6:452e301a105a 9 cntr = 0;
john111222333 7:c17f5473f4e1 10
Alex_Kyrl 6:452e301a105a 11
Alex_Kyrl 6:452e301a105a 12
john111222333 7:c17f5473f4e1 13 }
Alex_Kyrl 11:dd1976534a03 14 double EMG::get_notch(double data){ // remove 50Hz peak dew to all electrical network apliances
Alex_Kyrl 6:452e301a105a 15
john111222333 7:c17f5473f4e1 16
Alex_Kyrl 6:452e301a105a 17
Alex_Kyrl 6:452e301a105a 18 return MainsReject.step(data);
Alex_Kyrl 6:452e301a105a 19
Alex_Kyrl 6:452e301a105a 20 }
Alex_Kyrl 6:452e301a105a 21
Alex_Kyrl 6:452e301a105a 22
Alex_Kyrl 11:dd1976534a03 23 double EMG::get_noise(){ // remove noise from the system (noise is conciderd 80Hz+)
john111222333 7:c17f5473f4e1 24
Alex_Kyrl 6:452e301a105a 25
Alex_Kyrl 6:452e301a105a 26
john111222333 7:c17f5473f4e1 27 return Low_pass.step(_data);
Alex_Kyrl 6:452e301a105a 28 }
Alex_Kyrl 6:452e301a105a 29
Alex_Kyrl 6:452e301a105a 30
Alex_Kyrl 11:dd1976534a03 31 double EMG::get_DC(double data){ // remove DC offset from the signal (High pass filter above 10Hz)
Alex_Kyrl 6:452e301a105a 32
john111222333 7:c17f5473f4e1 33
Alex_Kyrl 6:452e301a105a 34
Alex_Kyrl 6:452e301a105a 35 return HiPass.step(data);
Alex_Kyrl 6:452e301a105a 36
Alex_Kyrl 6:452e301a105a 37 }
Alex_Kyrl 6:452e301a105a 38
Alex_Kyrl 6:452e301a105a 39
Alex_Kyrl 11:dd1976534a03 40 double EMG::get_absolute(double data){ //get the absolute value of the signal
Alex_Kyrl 6:452e301a105a 41
Alex_Kyrl 6:452e301a105a 42 return abs(data);
Alex_Kyrl 6:452e301a105a 43
Alex_Kyrl 6:452e301a105a 44
Alex_Kyrl 6:452e301a105a 45 }
Alex_Kyrl 6:452e301a105a 46
Alex_Kyrl 6:452e301a105a 47
Alex_Kyrl 11:dd1976534a03 48 double EMG::get_envelope(double data){ // return the envelope of the signal (low pass filter at 5Hz)
Alex_Kyrl 6:452e301a105a 49
john111222333 7:c17f5473f4e1 50
Alex_Kyrl 6:452e301a105a 51
Alex_Kyrl 6:452e301a105a 52 return LoPass.step(data);
Alex_Kyrl 6:452e301a105a 53 }
Alex_Kyrl 6:452e301a105a 54
Alex_Kyrl 11:dd1976534a03 55 double EMG::filter(){ // Aply all filters and absolute in series in order to get envelope of the EMG signal
Alex_Kyrl 6:452e301a105a 56
Alex_Kyrl 6:452e301a105a 57 if(cntr<=500)
Alex_Kyrl 6:452e301a105a 58 {
Alex_Kyrl 6:452e301a105a 59 cntr++;
Alex_Kyrl 6:452e301a105a 60 return 0;
Alex_Kyrl 6:452e301a105a 61 }
Alex_Kyrl 6:452e301a105a 62 else
Alex_Kyrl 6:452e301a105a 63 {
john111222333 7:c17f5473f4e1 64 return get_envelope(get_absolute(get_DC(get_notch(get_noise()))));
Alex_Kyrl 6:452e301a105a 65 }
Alex_Kyrl 6:452e301a105a 66
Alex_Kyrl 6:452e301a105a 67 }