EMG filtering; highpass, notch, abs, moving average

Dependencies:   HIDScope MODSERIAL- mbed-dsp mbed

Files at this revision

API Documentation at this revision

Comitter:
Hooglugt
Date:
Fri Oct 03 09:20:24 2014 +0000
Parent:
22:9dce7ec48f5d
Child:
24:c6073b9efd5b
Commit message:
changed method for feedback selection (led display to pc.prinft)

Changed in this revision

MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
Project_main.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show diff for this revision Revisions of this file
--- a/MODSERIAL.lib	Tue Sep 30 15:49:23 2014 +0000
+++ b/MODSERIAL.lib	Fri Oct 03 09:20:24 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Sissors/code/MODSERIAL/#180e968a751e
+http://mbed.org/users/Sissors/code/MODSERIAL/#f6cba765d331
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Project_main.cpp	Fri Oct 03 09:20:24 2014 +0000
@@ -0,0 +1,161 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "HIDScope.h"
+
+//Define objects
+AnalogIn    emg0(PTB1); //Analog input
+PwmOut      emgfloat(PTD4);//Float voor EMG-waarde
+PwmOut      red(LED_RED); //PWM output
+PwmOut      green(LED_GREEN);
+PwmOut      blue(LED_BLUE);
+int         direction = 0;
+int         force = 0;
+
+Ticker log_timer;
+MODSERIAL pc(USBTX,USBRX);
+HIDScope scope(2);
+
+/** Looper function
+* functions used for Ticker and Timeout should be of type void <name>(void)
+* i.e. no input arguments, no output arguments.
+* if you want to change a variable that you use in other places (for example in main)
+* you will have to make that variable global in order to be able to reach it both from
+* the function called at interrupt time, and in the main function.
+* To make a variable global, define it under the includes.
+* variables that are changed in the interrupt routine (written to) should be made
+* 'volatile' to let the compiler know that those values may change outside the current context.
+* i.e.: "volatile uint16_t emg_value;" instead of "uint16_t emg_value"
+* in the example below, the variable is not re-used in the main function, and is thus declared
+* local in the looper function only.
+**/
+void looper()
+{
+    /*variable to store value in*/
+    uint16_t emg_value;
+    /*put raw emg value both in emgfloat and in emg_value*/
+    emgfloat.write(emg0.read());      // read float value (0..1 = 0..3.3V)
+    emg_value = emg0.read_u16(); // read direct ADC result (0..4096 = 0..3.3V)
+    /*send value to PC. Line below is used to prevent buffer overrun */
+    if(pc.rxBufferGetSize(0)-pc.rxBufferGetCount() > 30)
+        pc.printf("%u\n",emg_value);
+    scope.set(0,emg_value);
+    scope.set(1,emgfloat.read());
+    scope.send();
+    /**When not using the LED, the above could also have been done this way:
+    * pc.printf("%u\n", emg0.read_u16());
+    */
+}
+
+
+
+int main()
+{
+    /*setup baudrate. Choose the same in your program on PC side*/
+    pc.baud(115200);
+    /*set the period for the PWM to the emgfloat PTD4*/
+    emgfloat.period_ms(2);
+    /**Here you attach the 'void looper(void)' function to the Ticker object
+    * The looper() function will be called every 0.001 seconds.
+    * Please mind that the parentheses after looper are omitted when using attach.
+    */
+    log_timer.attach(looper, 0.001);
+    goto directionchoice;
+    while(1) { //Loop keuze DIRECTION
+        directionchoice:
+        for(int i=1; i<4; i++) {
+            if(i==1) {           //red
+                red=0;
+                green=1;
+                blue=1;
+                for (int lag=0; lag<50; lag++) {
+                    if(emgfloat.read()>0.8) {                    // 0.8 klopt niet als grenswaarde. #nofilter
+                        direction = 1;
+                        pc.printf("A");
+                        goto forcechoice;
+                    } else {
+                        wait(0.1);
+                    }
+                }
+            }
+            if(i==2) {           //green
+                red =1;
+                green=0;
+                blue=1;
+                for (int lag=0; lag<50; lag++) {
+                    if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
+                        direction = 2;
+                        pc.printf("B");
+                        goto forcechoice;
+                    } else {
+                        wait(0.1);
+                    }
+                }
+            }
+            if(i==3) {           //blue
+                red=1;
+                green=1;
+                blue=0;
+                for (int lag=0; lag<50; lag++) {
+                    if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
+                        direction = 3;
+                        pc.printf("C");
+                        goto forcechoice;
+                    } else {
+                        wait(0.1);
+                    }
+                }
+            }
+        }      
+    }
+    while(1) { //Loop keuze FORCE
+    forcechoice:
+        for(int i=1; i<4; i++) {
+            if(i==1) {           //red
+                red=0;
+                green=1;
+                blue=1;
+                for (int lag=0; lag<50; lag++) {
+                    if(emgfloat.read()>0.8) {                    // 0.8 klopt niet als grenswaarde. #nofilter
+                        force = 1;
+                        pc.printf("A");
+                        goto choicesmade;
+                    } else {
+                        wait(0.1);
+                    }
+                }
+            }
+            if(i==2) {           //green
+                red =1;
+                green=0;
+                blue=1;
+                for (int lag=0; lag<50; lag++) {
+                    if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
+                        force = 2;
+                        pc.printf("B");
+                        goto choicesmade;
+                    } else {
+                        wait(0.1);
+                    }
+                }
+            }
+            if(i==3) {           //blue
+                red=1;
+                green=1;
+                blue=0;
+                for (int lag=0; lag<50; lag++) {
+                    if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
+                        force = 3;
+                        pc.printf("C");
+                        goto choicesmade;
+                    } else {
+                        wait(0.1);
+                    }
+                }
+            }
+        }
+    }
+    choicesmade:
+    red = 0;
+    green = 0;
+    blue = 0;
+    }
\ No newline at end of file
--- a/main.cpp	Tue Sep 30 15:49:23 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,180 +0,0 @@
-#include "mbed.h"
-#include "MODSERIAL.h"
-#include "HIDScope.h"
-
-//Define objects
-AnalogIn    emg0(PTB1); //Analog input
-PwmOut      emgfloat(PTD4);//Float voor EMG-waarde
-emgfloat.write(0);          // float is automatisch 0, dus als geen emg gemeten wordt, dan toch nog een waarde (niet zeker of dit noodzakelijk is)
-PwmOut      red(LED_RED); //PWM output
-PwmOut      green(LED_GREEN);
-PwmOut      blue(LED_BLUE);
-int         direction = 0;
-int         force = 0;
-
-Ticker log_timer;
-MODSERIAL pc(USBTX,USBRX);
-HIDScope scope(2);
-
-/** Looper function
-* functions used for Ticker and Timeout should be of type void <name>(void)
-* i.e. no input arguments, no output arguments.
-* if you want to change a variable that you use in other places (for example in main)
-* you will have to make that variable global in order to be able to reach it both from
-* the function called at interrupt time, and in the main function.
-* To make a variable global, define it under the includes.
-* variables that are changed in the interrupt routine (written to) should be made
-* 'volatile' to let the compiler know that those values may change outside the current context.
-* i.e.: "volatile uint16_t emg_value;" instead of "uint16_t emg_value"
-* in the example below, the variable is not re-used in the main function, and is thus declared
-* local in the looper function only.
-**/
-void looper()
-{
-    /*variable to store value in*/
-    uint16_t emg_value;
-    /*put raw emg value both in emgfloat and in emg_value*/
-    emgfloat.write(emg0.read());      // read float value (0..1 = 0..3.3V)
-    emg_value = emg0.read_u16(); // read direct ADC result (0..4096 = 0..3.3V)
-    /*send value to PC. Line below is used to prevent buffer overrun */
-    if(pc.rxBufferGetSize(0)-pc.rxBufferGetCount() > 30)
-        pc.printf("%u\n",emg_value);
-    scope.set(0,emg_value);
-    scope.set(1,emgfloat.read());
-    scope.send();
-    /**When not using the LED, the above could also have been done this way:
-    * pc.printf("%u\n", emg0.read_u16());
-    */
-}
-
-
-
-int main()
-{
-    /*setup baudrate. Choose the same in your program on PC side*/
-    pc.baud(115200);
-    /*set the period for the PWM to the emgfloat PTD4*/
-    emgfloat.period_ms(2);
-    /**Here you attach the 'void looper(void)' function to the Ticker object
-    * The looper() function will be called every 0.001 seconds.
-    * Please mind that the parentheses after looper are omitted when using attach.
-    */
-    log_timer.attach(looper, 0.001);
-    goto directionchoice;
-    while(1) { //Loop keuze DIRECTION
-        directionchoice:
-        for(int i=1; i<4; i++) {
-            if(i==1) {           //red
-                red=0;
-                green=1;
-                blue=1;
-                for (int lag=0; lag<50; lag++) {
-                    if(emgfloat.read()>0.8) {                    // 0.8 klopt niet als grenswaarde. #nofilter
-                        direction = 1;
-                        blue = 0;
-                        green = 0;
-                        red=1;
-                        wait(2);                            // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie
-                        goto forcechoice;
-                    } else {
-                        wait(0.1);
-                    }
-                }
-            }
-            if(i==2) {           //green
-                red =1;
-                green=0;
-                blue=1;
-                for (int lag=0; lag<50; lag++) {
-                    if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
-                        direction = 2;
-                        blue = 0;
-                        green = 1;
-                        red=0;
-                        wait(2);                            // Tijdelijke wait om paars lampje aan te zetten ter controle selectie
-                        goto forcechoice;
-                    } else {
-                        wait(0.1);
-                    }
-                }
-            }
-            if(i==3) {           //blue
-                red=1;
-                green=1;
-                blue=0;
-                for (int lag=0; lag<50; lag++) {
-                    if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
-                        direction = 3;
-                        blue = 1;
-                        green = 0;
-                        red=0;
-                        wait(2);                            // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie
-                        goto forcechoice;
-                    } else {
-                        wait(0.1);
-                    }
-                }
-            }
-        }      
-    }
-    while(1) { //Loop keuze FORCE
-    forcechoice:
-        for(int i=1; i<4; i++) {
-            if(i==1) {           //red
-                red=0;
-                green=1;
-                blue=1;
-                for (int lag=0; lag<50; lag++) {
-                    if(emgfloat.read()>0.8) {                    // 0.8 klopt niet als grenswaarde. #nofilter
-                        force = 1;
-                        blue = 0;
-                        green = 0;
-                        red=1;
-                        wait(2);                            // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie
-                        goto choicesmade;
-                    } else {
-                        wait(0.1);
-                    }
-                }
-            }
-            if(i==2) {           //green
-                red =1;
-                green=0;
-                blue=1;
-                for (int lag=0; lag<50; lag++) {
-                    if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
-                        force = 2;
-                        blue = 0;
-                        green = 1;
-                        red=0;
-                        wait(2);                            // Tijdelijke wait om paars lampje aan te zetten ter controle selectie
-                        goto choicesmade;
-                    } else {
-                        wait(0.1);
-                    }
-                }
-            }
-            if(i==3) {           //blue
-                red=1;
-                green=1;
-                blue=0;
-                for (int lag=0; lag<50; lag++) {
-                    if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
-                        force = 3;
-                        blue = 1;
-                        green = 0;
-                        red=0;
-                        wait(2);                            // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie
-                        goto choicesmade;
-                    } else {
-                        wait(0.1);
-                    }
-                }
-            }
-        }
-    }
-    choicesmade:
-    red = 0;
-    green = 0;
-    blue = 0;
-    }
\ No newline at end of file