Gerlinde van de Haar / Mbed 2 deprecated EMG_converter_code

Dependencies:   HIDScope MODSERIAL QEI biquadFilter mbed

Fork of EMG_converter_code by K K

Files at this revision

API Documentation at this revision

Comitter:
Technical_Muffin
Date:
Wed Oct 21 15:23:36 2015 +0000
Child:
1:9913e3886643
Commit message:
Code for converting emg signal to usable code.

Changed in this revision

HIDScope.lib Show annotated file Show diff for this revision Revisions of this file
biquadFilter.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HIDScope.lib	Wed Oct 21 15:23:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/tomlankhorst/code/HIDScope/#5020a2c0934b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/biquadFilter.lib	Wed Oct 21 15:23:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/tomlankhorst/code/biquadFilter/#e3bf917ae0a3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 21 15:23:36 2015 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+#include "HIDScope.h"
+#include "biquadFilter.h"        // Require the HIDScope library
+
+//Define objects
+AnalogIn    emg(A0); //Analog of EMG input
+Ticker      sample_timer;
+HIDScope    scope(2);        // Instantize a 2-channel HIDScope object
+/*The biquad filters required to transform the EMG signal into an usable signal*/
+biquadFilter filterhigh1(-1.1430, 0.4128, 0.6389, -1.2779, 0.6389);
+biquadFilter filterlow1(1.9556, 0.9565, 0.9780, 1.9561, 0.9780);
+biquadFilter notch(-1.1978e-16, 0.9561, 0.9780, -1.1978e-16, 0.9780);
+biquadFilter filterlow2(-1.9645, 0.9651, 1.5515e-4, 3.1030e-4, 1.5515e-4);
+
+/* 
+ */
+void filter()
+{
+    /* Sample the EMG using the 'read' method of the 'AnalogIn' variable named 'emg' */
+    double emg_value = emg.read();
+        double signalpart1 = filterhigh1.step(emg_value);//Highpass filter for removing offset and artifacts
+        double signalpart2 = abs(signalpart1);//rectify the filtered signal
+        double signalpart3 = filterlow1.step(signalpart2);//low pass filter to envelope the emg
+        double signalpart4 = notch.step(signalpart3);//notch filter to remove 50Hz signal
+        double signalfinal = filterlow2.step(signalpart4);//2nd low pass filter to envelope the emg
+        scope.set(0,emg_value);//emg_value
+        scope.set(1,signalfinal);
+        /* Second, set the sampled emg value in channel zero (the first channel) in the 'HIDScope' variable named 'scope' */
+    /* Repeat the step above if required for more channels (channel 0 up to 5 = 6 channels) */
+    /* Finally, send all channels to the PC at once */
+    scope.send();
+}
+
+int main()
+{
+    /**Attach the 'sample' function to the timer 'sample_timer'.
+    * this ensures that 'sample' is executed every... 0.002 seconds
+    */
+    sample_timer.attach(&filter, 0.002);
+
+    /*empty loop, sample() is executed periodically*/
+    while(1) {}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 21 15:23:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file