Poep Hoofd / Mbed 2 deprecated PoolRobot_Code

Dependencies:   HIDScope mbed MODSERIAL QEI

Committer:
john111222333
Date:
Wed Nov 01 13:32:43 2017 +0000
Revision:
15:a24b30061c5f
Parent:
11:dd1976534a03
Child:
16:a2a73d57d556
changed EMG class;

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 }
john111222333 15:a24b30061c5f 11
Alex_Kyrl 6:452e301a105a 12
john111222333 15:a24b30061c5f 13 double EMG::get_noise(){ // remove noise from the system (noise is conciderd 80Hz+)
john111222333 15:a24b30061c5f 14
john111222333 15:a24b30061c5f 15 return Low_pass.step(_data);
john111222333 15:a24b30061c5f 16 }
john111222333 15:a24b30061c5f 17
john111222333 15:a24b30061c5f 18 double EMG::get_notch(double data){ // remove 50Hz peak dew to all electrical network apliances
Alex_Kyrl 6:452e301a105a 19
Alex_Kyrl 6:452e301a105a 20 return MainsReject.step(data);
Alex_Kyrl 6:452e301a105a 21
Alex_Kyrl 6:452e301a105a 22 }
john111222333 15:a24b30061c5f 23
Alex_Kyrl 6:452e301a105a 24
Alex_Kyrl 11:dd1976534a03 25 double EMG::get_DC(double data){ // remove DC offset from the signal (High pass filter above 10Hz)
Alex_Kyrl 6:452e301a105a 26
Alex_Kyrl 6:452e301a105a 27 return HiPass.step(data);
Alex_Kyrl 6:452e301a105a 28
Alex_Kyrl 6:452e301a105a 29 }
Alex_Kyrl 6:452e301a105a 30
Alex_Kyrl 6:452e301a105a 31
Alex_Kyrl 11:dd1976534a03 32 double EMG::get_absolute(double data){ //get the absolute value of the signal
Alex_Kyrl 6:452e301a105a 33
john111222333 15:a24b30061c5f 34 return fabs(data);
Alex_Kyrl 6:452e301a105a 35
Alex_Kyrl 6:452e301a105a 36 }
Alex_Kyrl 6:452e301a105a 37
Alex_Kyrl 6:452e301a105a 38
Alex_Kyrl 11:dd1976534a03 39 double EMG::get_envelope(double data){ // return the envelope of the signal (low pass filter at 5Hz)
Alex_Kyrl 6:452e301a105a 40
Alex_Kyrl 6:452e301a105a 41 return LoPass.step(data);
Alex_Kyrl 6:452e301a105a 42 }
Alex_Kyrl 6:452e301a105a 43
Alex_Kyrl 11:dd1976534a03 44 double EMG::filter(){ // Aply all filters and absolute in series in order to get envelope of the EMG signal
Alex_Kyrl 6:452e301a105a 45
Alex_Kyrl 6:452e301a105a 46 if(cntr<=500)
Alex_Kyrl 6:452e301a105a 47 {
Alex_Kyrl 6:452e301a105a 48 cntr++;
Alex_Kyrl 6:452e301a105a 49 return 0;
Alex_Kyrl 6:452e301a105a 50 }
Alex_Kyrl 6:452e301a105a 51 else
Alex_Kyrl 6:452e301a105a 52 {
john111222333 7:c17f5473f4e1 53 return get_envelope(get_absolute(get_DC(get_notch(get_noise()))));
Alex_Kyrl 6:452e301a105a 54 }
Alex_Kyrl 6:452e301a105a 55
john111222333 15:a24b30061c5f 56 }
john111222333 15:a24b30061c5f 57
john111222333 15:a24b30061c5f 58 double EMG::get_data(){
john111222333 15:a24b30061c5f 59
john111222333 15:a24b30061c5f 60 return _data;
Alex_Kyrl 6:452e301a105a 61 }