code: protected double downsample(double[] data, int start, int end, int size) {
      double sum = 0;
      for (int i = start; i < end; i++) {
        sum += data[i];
      }
      return sum;
    }
docs: Perform downsampling on a number of bins.
  
  @param data Data array (needs cast!)
  @param start Interval start
  @param end Interval end (exclusive)
  @param size Intended size - extra bins are assumed to be empty, should be a
  power of two
  @return New bin value