hidscope herkent m'n device niet.
Dependencies: HIDScope mbed biquadFilter
Revision 2:ef6c30f459a5, committed 2016-10-25
- Comitter:
- Jankoekenpan
- Date:
- Tue Oct 25 15:00:21 2016 +0000
- Parent:
- 1:d357a1e80389
- Commit message:
- calculate standard deviation from the whole signal
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Oct 25 14:12:40 2016 +0000 +++ b/main.cpp Tue Oct 25 15:00:21 2016 +0000 @@ -18,6 +18,9 @@ //BiQuad bq4( 1.00000e+00, -2.00000e+00, 1.00000e+00, -1.97996e+00, 9.80645e-01 ); //BiQuad bq5( 9.97389e-01, -1.97771e+00, 9.97389e-01, -1.97771e+00, 9.94778e-01 ); +volatile float TOTAL_SAMPLE_SUM = 0; +volatile long NUMBER_SAMPLES = 0; + const int numEmgCache = 50; float emgCache[numEmgCache]; //sorted from new to old; @@ -56,8 +59,7 @@ return sum(array, size) / size; } -float variance(float array[], int size) { - float avg = mean(array, size); +float variance(float array[], int size, float avg) { float squaredDifferences[size]; for (int i = 0; i < size; i++) { float difference = array[i] - avg; @@ -66,12 +68,12 @@ return mean(squaredDifferences, size); } -float standardDeviation(float array[], int size) { - return sqrt(variance(array, size)); +float standardDeviation(float array[], int size, float avg) { + return sqrt(variance(array, size, avg)); } -int decide(float signalvalue, float threshold) { - return signalvalue < threshold ? 0 : 1; +int decide(float value, float threshold) { + return value < threshold ? 0 : 1; } @@ -81,8 +83,12 @@ float filtered = movingAverage( fabs(emg) ); scope.set(1, filtered); + TOTAL_SAMPLE_SUM += emg; + NUMBER_SAMPLES++; + addFirst(filtered, averageCache, numAvgCache); - float stdDev = standardDeviation(averageCache, numAvgCache); + float avg = TOTAL_SAMPLE_SUM / NUMBER_SAMPLES; //TODO calibrate this value. + float stdDev = standardDeviation(averageCache, numAvgCache, avg); scope.set(2, stdDev);