59 lines · 1.2 KB · C++
RawDownload
////  StdDev.cpp//  hifi////  Created by Philip Rosedale on 3/12/13.//  Copyright (c) 2013 HighFidelity, Inc. All rights reserved.// #include <limits>   #include <cmath>#include "StdDev.h" const int MAX_STDEV_SAMPLES = 1000; StDev::StDev() {    data = new float[MAX_STDEV_SAMPLES];    sampleCount = 0;} void StDev::reset() {    sampleCount = 0;} void StDev::addValue(float v) {    data[sampleCount++] = v;    if (sampleCount == MAX_STDEV_SAMPLES) sampleCount = 0;} float StDev::getAverage() {    float average = 0;    for (int i = 0; i < sampleCount; i++) {        average += data[i];    }    if (sampleCount > 0)        return average/(float)sampleCount;    else return 0;}/*float StDev::getMax() {     float average = -FLT_MAX;    for (int i = 0; i < sampleCount; i++) {        average += data[i];    }    if (sampleCount > 0)        return average/(float)sampleCount;    else return 0;}*/ float StDev::getStDev() {    float average = getAverage();    float stdev = 0;    for (int i = 0; i < sampleCount; i++) {        stdev += powf(data[i] - average, 2);    }    if (sampleCount > 1)        return sqrt(stdev/(float)(sampleCount - 1.0));    else        return 0;}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t