Added variable Test SideToF sensore
Dependencies: QEI2 chair_BNO055 PID Watchdog VL53L1X_Filter ros_lib_kinetic
Statistics/statistics.cpp@27:da718b990837, 2019-06-28 (annotated)
- Committer:
- jvfausto
- Date:
- Fri Jun 28 21:16:26 2019 +0000
- Revision:
- 27:da718b990837
- Child:
- 28:6d6bd8ad04dc
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jvfausto | 27:da718b990837 | 1 | #include "statistics.h" |
jvfausto | 27:da718b990837 | 2 | #include "mbed.h" |
jvfausto | 27:da718b990837 | 3 | |
jvfausto | 27:da718b990837 | 4 | statistics::statistics(int* Input, int dataLengthIn, int firstDataPoint){ |
jvfausto | 27:da718b990837 | 5 | data = Input; |
jvfausto | 27:da718b990837 | 6 | dataLength = dataLengthIn; |
jvfausto | 27:da718b990837 | 7 | } |
jvfausto | 27:da718b990837 | 8 | double statistics::mean(){ |
jvfausto | 27:da718b990837 | 9 | double sum; |
jvfausto | 27:da718b990837 | 10 | for(int i = 0; i < dataLength; ++i) |
jvfausto | 27:da718b990837 | 11 | { |
jvfausto | 27:da718b990837 | 12 | sum += data[i]; |
jvfausto | 27:da718b990837 | 13 | } |
jvfausto | 27:da718b990837 | 14 | |
jvfausto | 27:da718b990837 | 15 | double average = sum/dataLength; |
jvfausto | 27:da718b990837 | 16 | return average; |
jvfausto | 27:da718b990837 | 17 | } |
jvfausto | 27:da718b990837 | 18 | double statistics::stdev(){ |
jvfausto | 27:da718b990837 | 19 | float sum = 0.0, mean, standardDeviation = 0.0; |
jvfausto | 27:da718b990837 | 20 | |
jvfausto | 27:da718b990837 | 21 | int i; |
jvfausto | 27:da718b990837 | 22 | |
jvfausto | 27:da718b990837 | 23 | for(int i = 0; i < dataLength; ++i) |
jvfausto | 27:da718b990837 | 24 | { |
jvfausto | 27:da718b990837 | 25 | sum += data[i]; |
jvfausto | 27:da718b990837 | 26 | } |
jvfausto | 27:da718b990837 | 27 | |
jvfausto | 27:da718b990837 | 28 | mean = sum/dataLength; |
jvfausto | 27:da718b990837 | 29 | |
jvfausto | 27:da718b990837 | 30 | for(int i = 0; i < dataLength; ++i) |
jvfausto | 27:da718b990837 | 31 | standardDeviation += pow(data[i] - mean, 2); |
jvfausto | 27:da718b990837 | 32 | |
jvfausto | 27:da718b990837 | 33 | return sqrt(standardDeviation / dataLength); |
jvfausto | 27:da718b990837 | 34 | } |