a
Dependencies: QEI2 chair_BNO055 PID Watchdog VL53L1X_Filter ros_lib_kinetic
Dependents: wheelchairControlSumer19 Version1-0
Diff: Statistics/statistics.cpp
- Revision:
- 28:6d6bd8ad04dc
- Parent:
- 27:da718b990837
- Child:
- 30:c25b2556e84d
--- a/Statistics/statistics.cpp Fri Jun 28 21:16:26 2019 +0000 +++ b/Statistics/statistics.cpp Mon Jul 01 06:03:43 2019 +0000 @@ -1,13 +1,22 @@ + #include "statistics.h" #include "mbed.h" - statistics::statistics(int* Input, int dataLengthIn, int firstDataPoint){ + /************************************************************************** + * This function initializes the private members of the class Statistics * + **************************************************************************/ + statistics::statistics(int* Input, int dataLengthIn, int firstDataPointIn){ data = Input; dataLength = dataLengthIn; + firstDataPoint = firstDataPointIn; } + + /************************************************************************** + * This function returns the mean(average) of an array. * + **************************************************************************/ double statistics::mean(){ double sum; - for(int i = 0; i < dataLength; ++i) + for(int i = firstDataPoint; i < (firstDataPoint + dataLength); ++i) { sum += data[i]; } @@ -15,20 +24,30 @@ double average = sum/dataLength; return average; } + + /************************************************************************** + * This function returns the standard deviation of an array. This is * + * used to determine whether the data is valid or not. * + **************************************************************************/ double statistics::stdev(){ - float sum = 0.0, mean, standardDeviation = 0.0; + double sum = 0.0, mean, standardDeviation = 0.0; + printf("The length of the array is %d\n", dataLength); + //double num = (pow(2.0,2.0)); + //printf("2^2 is %f\n", num); + //int i; - int i; - - for(int i = 0; i < dataLength; ++i) + for(int i = firstDataPoint; i < (firstDataPoint + dataLength); ++i) { sum += data[i]; + printf("%d\n", data[i]); } mean = sum/dataLength; - for(int i = 0; i < dataLength; ++i) - standardDeviation += pow(data[i] - mean, 2); + for(int i = firstDataPoint; i < (firstDataPoint + dataLength); ++i) { + //standardDeviation += pow(data[i] - mean, 2); + standardDeviation += (data[i] - mean)*(data[i] - mean); + } return sqrt(standardDeviation / dataLength); - } + } \ No newline at end of file