// file: extract_feature/extf_algo_0.cc
//

// isip include files
//
#include "extract_feature.h"
#include <Signal.h>

#include "extract_feature_constants.h"
#include <signal_constants.h>

// method: compute_mean_cc
//
// arguments:
//  float_8* vector: (output) feature
//  float_8* window_buffer_a: (input) window of data
//  int_4 num_samples_a: (input) number of samples to operate upon
//
// This method computes the mean energy of the signal
//
logical_1 compute_mean_cc(float_8* vector_a,
			float_8* window_buffer_a,
			int_4 num_samples_a) {
  
  // compute the mean
  //
  float_8 m = (float_8)0;
  float_8 e = (float_8)0;
  for (int_4 i = 0; i < num_samples_a; i++) {
    e += window_buffer_a[i] * window_buffer_a[i];
    m += window_buffer_a[i];
  }

  m /= (float_8)num_samples_a;
  // e = (e / (float_8)num_samples_a) - m * m;

  if (e > 0.0) {
    vector_a[0] = log(e);
  } else {
    vector_a[0] = 0.0;
  }
  
  // return without error
  //
  return ISIP_TRUE;
}
