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
Diff: EMG.cpp
- Revision:
- 6:452e301a105a
- Child:
- 7:c17f5473f4e1
diff -r 4c27dea81e4c -r 452e301a105a EMG.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/EMG.cpp Mon Oct 16 13:07:53 2017 +0000
@@ -0,0 +1,75 @@
+#include "EMG.h"
+#include"BiQuad.h"
+
+EMG::EMG(PinName data) : _data(data)
+{
+ cntr = 0;
+}
+
+
+double EMG::get_notch(double data){
+
+ double a0=1, a1=-1.525271192436899, a2=0.881618592363190,
+ b0=0.940809296181595, b1=-1.525271192436899, b2=0.940809296181595;
+
+ BiQuad MainsReject(b0, b1, b2, a0, a1, a2);
+
+ return MainsReject.step(data);
+
+}
+
+
+double EMG::get_noise(double data){
+
+ double a0=1, a1=-0.671029090774096, a2=0.252324626282266,
+ b0=0.145323883877042, b1= 0.290647767754085, b2= 0.145323883877042;
+
+ BiQuad Low_pass(b0, b1, b2, a0, a1, a2);
+
+ return Low_pass.step(data);
+}
+
+
+double EMG::get_DC(double data){
+
+ double a_0_0=1, a_0_1=-1.475480443592646, a_0_2=0.586919508061190,
+ b_0_0=0.765599987913459, b_0_1=-1.531199975826918, b_0_2=0.765599987913459;
+
+ BiQuad HiPass(b_0_0, b_0_1, b_0_2, a_0_0, a_0_1, a_0_2);
+
+ return HiPass.step(data);
+
+}
+
+
+double EMG::get_absolute(double data){
+
+ return abs(data);
+
+
+}
+
+
+double EMG::get_envelope(double data){
+
+ double a_1_0=1, a_1_1=-1.982228929792529, a_1_2=0.982385450614126,
+ b_1_0=0.00003913020539916823, b_1_1=0.00007826041079833645, b_1_2=0.00003913020539916823;
+
+ BiQuad LoPass(b_1_0, b_1_1, b_1_2, a_1_0, a_1_1, a_1_2);
+
+ return LoPass.step(data);
+}
+
+double EMG::filter(){
+
+ if(cntr<=500)
+ {
+ cntr++;
+ return 0;
+ }
+ else
+ {
+ return get_envelope(get_absolute(get_DC(get_notch(get_noise(_data)))));
+ }
+
+}
\ No newline at end of file
