Added variable Test SideToF sensore
Dependencies: QEI2 chair_BNO055 PID Watchdog VL53L1X_Filter ros_lib_kinetic
Statistics/statistics.cpp@28:6d6bd8ad04dc, 2019-07-01 (annotated)
- Committer:
- jvfausto
- Date:
- Mon Jul 01 06:03:43 2019 +0000
- Revision:
- 28:6d6bd8ad04dc
- Parent:
- 27:da718b990837
- Child:
- 30:c25b2556e84d
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jvfausto | 28:6d6bd8ad04dc | 1 | |
jvfausto | 27:da718b990837 | 2 | #include "statistics.h" |
jvfausto | 27:da718b990837 | 3 | #include "mbed.h" |
jvfausto | 27:da718b990837 | 4 | |
jvfausto | 28:6d6bd8ad04dc | 5 | /************************************************************************** |
jvfausto | 28:6d6bd8ad04dc | 6 | * This function initializes the private members of the class Statistics * |
jvfausto | 28:6d6bd8ad04dc | 7 | **************************************************************************/ |
jvfausto | 28:6d6bd8ad04dc | 8 | statistics::statistics(int* Input, int dataLengthIn, int firstDataPointIn){ |
jvfausto | 27:da718b990837 | 9 | data = Input; |
jvfausto | 27:da718b990837 | 10 | dataLength = dataLengthIn; |
jvfausto | 28:6d6bd8ad04dc | 11 | firstDataPoint = firstDataPointIn; |
jvfausto | 27:da718b990837 | 12 | } |
jvfausto | 28:6d6bd8ad04dc | 13 | |
jvfausto | 28:6d6bd8ad04dc | 14 | /************************************************************************** |
jvfausto | 28:6d6bd8ad04dc | 15 | * This function returns the mean(average) of an array. * |
jvfausto | 28:6d6bd8ad04dc | 16 | **************************************************************************/ |
jvfausto | 27:da718b990837 | 17 | double statistics::mean(){ |
jvfausto | 27:da718b990837 | 18 | double sum; |
jvfausto | 28:6d6bd8ad04dc | 19 | for(int i = firstDataPoint; i < (firstDataPoint + dataLength); ++i) |
jvfausto | 27:da718b990837 | 20 | { |
jvfausto | 27:da718b990837 | 21 | sum += data[i]; |
jvfausto | 27:da718b990837 | 22 | } |
jvfausto | 27:da718b990837 | 23 | |
jvfausto | 27:da718b990837 | 24 | double average = sum/dataLength; |
jvfausto | 27:da718b990837 | 25 | return average; |
jvfausto | 27:da718b990837 | 26 | } |
jvfausto | 28:6d6bd8ad04dc | 27 | |
jvfausto | 28:6d6bd8ad04dc | 28 | /************************************************************************** |
jvfausto | 28:6d6bd8ad04dc | 29 | * This function returns the standard deviation of an array. This is * |
jvfausto | 28:6d6bd8ad04dc | 30 | * used to determine whether the data is valid or not. * |
jvfausto | 28:6d6bd8ad04dc | 31 | **************************************************************************/ |
jvfausto | 27:da718b990837 | 32 | double statistics::stdev(){ |
jvfausto | 28:6d6bd8ad04dc | 33 | double sum = 0.0, mean, standardDeviation = 0.0; |
jvfausto | 28:6d6bd8ad04dc | 34 | printf("The length of the array is %d\n", dataLength); |
jvfausto | 28:6d6bd8ad04dc | 35 | //double num = (pow(2.0,2.0)); |
jvfausto | 28:6d6bd8ad04dc | 36 | //printf("2^2 is %f\n", num); |
jvfausto | 28:6d6bd8ad04dc | 37 | //int i; |
jvfausto | 27:da718b990837 | 38 | |
jvfausto | 28:6d6bd8ad04dc | 39 | for(int i = firstDataPoint; i < (firstDataPoint + dataLength); ++i) |
jvfausto | 27:da718b990837 | 40 | { |
jvfausto | 27:da718b990837 | 41 | sum += data[i]; |
jvfausto | 28:6d6bd8ad04dc | 42 | printf("%d\n", data[i]); |
jvfausto | 27:da718b990837 | 43 | } |
jvfausto | 27:da718b990837 | 44 | |
jvfausto | 27:da718b990837 | 45 | mean = sum/dataLength; |
jvfausto | 27:da718b990837 | 46 | |
jvfausto | 28:6d6bd8ad04dc | 47 | for(int i = firstDataPoint; i < (firstDataPoint + dataLength); ++i) { |
jvfausto | 28:6d6bd8ad04dc | 48 | //standardDeviation += pow(data[i] - mean, 2); |
jvfausto | 28:6d6bd8ad04dc | 49 | standardDeviation += (data[i] - mean)*(data[i] - mean); |
jvfausto | 28:6d6bd8ad04dc | 50 | } |
jvfausto | 27:da718b990837 | 51 | |
jvfausto | 27:da718b990837 | 52 | return sqrt(standardDeviation / dataLength); |
jvfausto | 28:6d6bd8ad04dc | 53 | } |