Dependencies:   mbed HIDScope biquadFilter

Files at this revision

API Documentation at this revision

Comitter:
hidde1104
Date:
Mon Oct 21 09:29:28 2019 +0000
Parent:
28:4eaf5990a7b3
Commit message:
Pre-running calibration

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Oct 21 08:34:37 2019 +0000
+++ b/main.cpp	Mon Oct 21 09:29:28 2019 +0000
@@ -27,6 +27,8 @@
 float filter_value;
 float emg0_value;
 float emg1_value;
+float filter_max;
+float filter_min;
 
 void sample()
 {
@@ -40,17 +42,42 @@
     scope.set(0, emg0.read() );
     scope.set(1, emg1.read() );
     scope.set(2, filter_value);
-    
+
     /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels)
     *  Ensure that enough channels are available (HIDScope scope( 2 ))
     *  Finally, send all channels to the PC at once */
-    
+
     scope.send();
-    
+
     /* To indicate that the function is working, the LED is toggled */
     led = !led;
 }
 
+void sample_2()
+{
+    /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
+    emg0_value = emg0.read();
+    emg1_value = emg1.read();
+
+
+    filter_value = fabs(bq2.step(fabs(bq1.step(emg0_value-emg1_value))));
+    filter_value = (filter_value-filter_min) / (0.5*filter_max-filter_min);
+    
+    scope.set(0, emg0.read() );
+    scope.set(1, emg1.read() );
+    scope.set(2, filter_value);
+
+    /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels)
+    *  Ensure that enough channels are available (HIDScope scope( 2 ))
+    *  Finally, send all channels to the PC at once */
+
+    scope.send();
+
+    /* To indicate that the function is working, the LED is toggled */
+    led = !led;
+}
+
+
 const int length = 1000;
 int i;
 float sample_array[length] = {};
@@ -58,14 +85,28 @@
 void calibration()
 {
     i = 0;
-    while (i < (length-1)) {
+    while (i < (length)) {
         sample();
         pc.printf("I can reach this point\r\n");
         sample_array[i] = filter_value;
-        pc.printf("The filter_value is %f\r\nThe EMG0 input is %f\r\nThe EMG1 input is %f\r\n",filter_value, emg0_value, emg1_value);
+        pc.printf("The filter_value is %f\r\n",filter_value);
         i++;
         wait(0.001);
     }
+
+    filter_max = -100.0;
+    filter_min = 100.0;
+    int m;
+    for (m = 200 ; m < length ; m++) {
+        pc.printf("the value of the m-st instance of sample_array is %f\r\n",sample_array[m]);
+        if (sample_array[m] > filter_max) {
+            filter_max = sample_array[m];
+        }
+        if (sample_array[m] < filter_min) {
+            filter_min = sample_array[m];
+            }
+    }
+    pc.printf("The value of filter_max is %f\r\nThe value of filter_min is %f\r\n",filter_max, filter_min);
 }
 
 int main()
@@ -79,7 +120,7 @@
     wait(2);
     calibration();
 
-    sample_timer.attach(&sample, 0.001);
+    sample_timer.attach(&sample_2, 0.001);
 
     /*empty loop, sample() is executed periodically*/
     while(1) {}