Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope mbed MODSERIAL QEI
EMG.cpp@21:59431788a42d, 2017-11-06 (annotated)
- Committer:
- john111222333
- Date:
- Mon Nov 06 09:57:21 2017 +0000
- Revision:
- 21:59431788a42d
- Parent:
- 16:a2a73d57d556
final version;
Who changed what in which revision?
| User | Revision | Line number | New 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 | 16:a2a73d57d556 | 10 | |
| john111222333 | 7:c17f5473f4e1 | 11 | } |
| john111222333 | 15:a24b30061c5f | 12 | |
| Alex_Kyrl | 6:452e301a105a | 13 | |
| john111222333 | 15:a24b30061c5f | 14 | double EMG::get_noise(){ // remove noise from the system (noise is conciderd 80Hz+) |
| john111222333 | 15:a24b30061c5f | 15 | |
| john111222333 | 15:a24b30061c5f | 16 | return Low_pass.step(_data); |
| john111222333 | 15:a24b30061c5f | 17 | } |
| john111222333 | 15:a24b30061c5f | 18 | |
| john111222333 | 15:a24b30061c5f | 19 | double EMG::get_notch(double data){ // remove 50Hz peak dew to all electrical network apliances |
| Alex_Kyrl | 6:452e301a105a | 20 | |
| Alex_Kyrl | 6:452e301a105a | 21 | return MainsReject.step(data); |
| Alex_Kyrl | 6:452e301a105a | 22 | |
| Alex_Kyrl | 6:452e301a105a | 23 | } |
| john111222333 | 15:a24b30061c5f | 24 | |
| Alex_Kyrl | 6:452e301a105a | 25 | |
| Alex_Kyrl | 11:dd1976534a03 | 26 | double EMG::get_DC(double data){ // remove DC offset from the signal (High pass filter above 10Hz) |
| Alex_Kyrl | 6:452e301a105a | 27 | |
| Alex_Kyrl | 6:452e301a105a | 28 | return HiPass.step(data); |
| Alex_Kyrl | 6:452e301a105a | 29 | |
| Alex_Kyrl | 6:452e301a105a | 30 | } |
| Alex_Kyrl | 6:452e301a105a | 31 | |
| Alex_Kyrl | 6:452e301a105a | 32 | |
| Alex_Kyrl | 11:dd1976534a03 | 33 | double EMG::get_absolute(double data){ //get the absolute value of the signal |
| Alex_Kyrl | 6:452e301a105a | 34 | |
| john111222333 | 15:a24b30061c5f | 35 | return fabs(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_envelope(double data){ // return the envelope of the signal (low pass filter at 5Hz) |
| Alex_Kyrl | 6:452e301a105a | 41 | |
| Alex_Kyrl | 6:452e301a105a | 42 | return LoPass.step(data); |
| Alex_Kyrl | 6:452e301a105a | 43 | } |
| Alex_Kyrl | 6:452e301a105a | 44 | |
| Alex_Kyrl | 11:dd1976534a03 | 45 | double EMG::filter(){ // Aply all filters and absolute in series in order to get envelope of the EMG signal |
| john111222333 | 16:a2a73d57d556 | 46 | |
| Alex_Kyrl | 6:452e301a105a | 47 | if(cntr<=500) |
| Alex_Kyrl | 6:452e301a105a | 48 | { |
| Alex_Kyrl | 6:452e301a105a | 49 | cntr++; |
| Alex_Kyrl | 6:452e301a105a | 50 | return 0; |
| Alex_Kyrl | 6:452e301a105a | 51 | } |
| john111222333 | 16:a2a73d57d556 | 52 | |
| Alex_Kyrl | 6:452e301a105a | 53 | else |
| Alex_Kyrl | 6:452e301a105a | 54 | { |
| john111222333 | 7:c17f5473f4e1 | 55 | return get_envelope(get_absolute(get_DC(get_notch(get_noise())))); |
| john111222333 | 16:a2a73d57d556 | 56 | |
| Alex_Kyrl | 6:452e301a105a | 57 | } |
| Alex_Kyrl | 6:452e301a105a | 58 | |
| john111222333 | 15:a24b30061c5f | 59 | } |
| john111222333 | 15:a24b30061c5f | 60 | |
| john111222333 | 15:a24b30061c5f | 61 | double EMG::get_data(){ |
| john111222333 | 15:a24b30061c5f | 62 | |
| john111222333 | 15:a24b30061c5f | 63 | return _data; |
| john111222333 | 16:a2a73d57d556 | 64 | } |
| john111222333 | 16:a2a73d57d556 | 65 | |
| john111222333 | 16:a2a73d57d556 | 66 | |
| john111222333 | 16:a2a73d57d556 | 67 |
