Permalink
Browse files

only calculate mean if there are more than 1 samples in the buffer + …

…getter for last element
  • Loading branch information...
1 parent 6364e2c commit 83772cabec54a4c99022c0e1c3961cea0e6396e3 Marije Baalman committed Feb 16, 2012
Showing with 22 additions and 24 deletions.
  1. +22 −24 app/src/com/steim/nescivi/android/gvb/CircularFloatArrayBuffer2.java
@@ -82,36 +82,21 @@ public static double sum(double[] a) {
return sum;
}
- float[][] getStats(){
+ public int getLastElement(){
+ return mNewestElement;
+ }
+
+ public float[][] getStats(){
double vart;
double[] stds = {0.0, 0.0, 0,0};
double[] means = {0.0, 0.0, 0,0};
float[][] stats = { {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f} };
- /*
- for ( int axis = 0; axis < 3; axis++ ){
- stats[0][axis] = (float) 0.0;
- }
- */
-
- // mean
- for ( int axis = 0; axis < 3; axis++ ){
- means[axis] = sum( this.mBuffer[axis] ) / this.mSize;
- }
- /*
- for (int i = 0; i < this.mSize; i++){
-
- means[axis] += this.mBuffer[i][axis];
- }
- }
- for ( int axis = 0; axis < 3; axis++ ){
- means[axis] = means[axis] / (float) this.mSize;
- }
- */
-
- // standard deviation
- // std = sqrt(mean( abs(x - x.mean())**2) )
+ // mean
if ( this.mSize > 1 ){
+ for ( int axis = 0; axis < 3; axis++ ){
+ means[axis] = sum( this.mBuffer[axis] ) / this.mSize;
+ }
for ( int axis = 0; axis < 3; axis++ ){
for (int i = 0; i < this.mSize; i++) {
vart = this.mBuffer[axis][i] - means[axis];
@@ -126,6 +111,19 @@ public static double sum(double[] a) {
stats[1][axis] = (float) Math.sqrt( stds[axis] );
}
+ /*
+ for (int i = 0; i < this.mSize; i++){
+
+ means[axis] += this.mBuffer[i][axis];
+ }
+ }
+ for ( int axis = 0; axis < 3; axis++ ){
+ means[axis] = means[axis] / (float) this.mSize;
+ }
+ */
+
+ // standard deviation
+ // std = sqrt(mean( abs(x - x.mean())**2) )
/*
//float delta;
//int n = 0;

0 comments on commit 83772ca

Please sign in to comment.