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 12:40:15 2014 +0000
Parent:
25:ec41b972b250
Child:
27:54167d54b0c5
Child:
29:7523e4a8e000
Commit message:
script iets netter

Changed in this revision

Project_main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Project_main.cpp	Fri Oct 03 12:27:01 2014 +0000
+++ b/Project_main.cpp	Fri Oct 03 12:40:15 2014 +0000
@@ -2,6 +2,7 @@
 #include "MODSERIAL.h"
 #include "HIDScope.h"
 #define TIMEB4NEXTCHOICE 2
+#define TIMEBETWEENBLINK 20
 
 //Define objects
 AnalogIn    emg0(PTB1); //Analog input
@@ -54,9 +55,9 @@
     pc.baud(115200); //baudrate instellen
     emgfloat.period_ms(2); //sets period for the PWM to the emgfloat PTD4
     log_timer.attach(looper, 0.001); // The looper() function will be called every 0.001 seconds (with the ticker object)
-    
+
     goto directionchoice; // goes to first while(1) for the deciding the direction
-    
+
     while(1) { //Loop keuze DIRECTION
 directionchoice:
         for(int i=1; i<4; i++) {
@@ -64,13 +65,13 @@
                 red=0;
                 green=1;
                 blue=1;
-                for (int lag=0; lag<20; lag++) {
+                for (int lag=0; lag<TIMEBETWEENBLINK; lag++) {
                     if(emgfloat.read()>0.8) {                   // 0.8 klopt niet als grenswaarde. #nofilter
                         direction = 1;
                         blue = 0;
                         green = 0;
                         red=1;
-                        pc.printf("A");
+                        pc.printf("links ");
                         wait(TIMEB4NEXTCHOICE);                 // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie
                         goto forcechoice;                       // goes to second while(1) for the deciding the force
                     } else {
@@ -82,13 +83,13 @@
                 red =1;
                 green=0;
                 blue=1;
-                for (int lag=0; lag<20; lag++) {
+                for (int lag=0; lag<TIMEBETWEENBLINK; lag++) {
                     if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
                         direction = 2;
                         blue = 0;
                         green = 1;
                         red=0;
-                        pc.printf("B");
+                        pc.printf("mid ");
                         wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om paars lampje aan te zetten ter controle selectie
                         goto forcechoice;
                     } else {
@@ -100,13 +101,13 @@
                 red=1;
                 green=1;
                 blue=0;
-                for (int lag=0; lag<20; lag++) {
+                for (int lag=0; lag<TIMEBETWEENBLINK; lag++) {
                     if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
                         direction = 3;
                         blue = 1;
                         green = 0;
                         red=0;
-                        pc.printf("C");
+                        pc.printf("rechts ");
                         wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie
                         goto forcechoice;
                     } else {
@@ -123,13 +124,13 @@
                 red=0;
                 green=1;
                 blue=1;
-                for (int lag=0; lag<20; lag++) {
+                for (int lag=0; lag<TIMEBETWEENBLINK; lag++) {
                     if(emgfloat.read()>0.8) {                    // 0.8 klopt niet als grenswaarde. #nofilter
                         force = 1;
                         blue = 0;
                         green = 0;
                         red=1;
-                        pc.printf("D");
+                        pc.printf("zwak ");
                         wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om cyaan lampje aan te zetten ter controle selectie
                         goto choicesmade;
                     } else {
@@ -141,13 +142,13 @@
                 red =1;
                 green=0;
                 blue=1;
-                for (int lag=0; lag<20; lag++) {
+                for (int lag=0; lag<TIMEBETWEENBLINK; lag++) {
                     if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
                         force = 2;
                         blue = 0;
                         green = 1;
                         red=0;
-                        pc.printf("E");
+                        pc.printf("normaal ");
                         wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om paars lampje aan te zetten ter controle selectie
                         goto choicesmade;
                     } else {
@@ -159,13 +160,13 @@
                 red=1;
                 green=1;
                 blue=0;
-                for (int lag=0; lag<20; lag++) {
+                for (int lag=0; lag<TIMEBETWEENBLINK; lag++) {
                     if(emgfloat.read()>0.8) {                    //0.8 klopt niet als grenswaarde. #nofilter
                         force = 3;
                         blue = 1;
                         green = 0;
                         red=0;
-                        pc.printf("F");
+                        pc.printf("sterk ");
                         wait(TIMEB4NEXTCHOICE);                            // Tijdelijke wait om oranje lampje aan te zetten ter controle selectie
                         goto choicesmade;
                     } else {
@@ -177,6 +178,10 @@
     }
 choicesmade:
 
+    red = 0;
+    green = 0;
+    blue = 0;           // wit lampje
+
     if(direction == 0 || force == 0) {
         pc.printf("error");
     }
@@ -207,9 +212,4 @@
     if(direction == 3 && force == 3) {            // rechts sterk
         pc.printf("rechts sterk");
     }
-
-    red = 0;
-    green = 0;
-    blue = 0;
-
 }
\ No newline at end of file