Het is kut

Dependencies:   HIDScope biquadFilter mbed

Fork of KUT_HIDSCOPE by Jan Boerman

Revision:
3:d4b8692e6697
Parent:
2:ef6c30f459a5
Child:
4:c8bab10bc897
--- a/main.cpp	Tue Oct 25 15:00:21 2016 +0000
+++ b/main.cpp	Mon Oct 31 15:17:10 2016 +0000
@@ -59,6 +59,13 @@
     return sum(array, size) / size;
 }
 
+float meanSquare(float array[], int size) {
+    for(int i = 0; i < size; i++) {
+        array[i] *= array[i];
+    }
+    return sum(array, size) / size;
+}
+
 float variance(float array[], int size, float avg) {  
     float squaredDifferences[size];
     for (int i = 0; i < size; i++) {
@@ -91,7 +98,18 @@
     float stdDev = standardDeviation(averageCache, numAvgCache, avg);
     scope.set(2, stdDev);
     
-    
+    float blocksize = 1000;
+    if ((sizeof(averageCache)) > blocksize) {
+        float rmsWithoutSquareRoot = meanSquare(averageCache, blocksize);
+        float rms = sqrt(rmsWithoutSquareRoot);
+        scope.set(3, rms);
+    } else {
+        float rmsWithoutSquareRoot = meanSquare(averageCache, ( sizeof(averageCache)));
+        float rms = sqrt(rmsWithoutSquareRoot);
+        scope.set(3, rms);
+
+    }    
+
     //float filtered = bqc.step( emg );
     //scope.set(1, filtered);
     
@@ -107,6 +125,6 @@
 {
    //bqc.add( &bq1 ).add( &bq2 );//.add( &bq3 ).add( &bq4 ).add( &bq5 );
    
-   ticker.attach(&tick, 8.333333333333334e-4);
+   ticker.attach(&tick, 0.005);
    while (true);
 }
\ No newline at end of file