import java.io.*;
import java.text.*;

public class Samples {
    double dx;
    double[] data;
    
    public Samples() {}
    
    public Samples(double[] d) { data = d; }
    
    public Samples(float[] f) {
	data = new double[f.length];
	for(int i=0; i<f.length; i++) data[i] = f[i];
    }
    
    public void write(PrintStream out, DecimalFormat df) {
	for(int i=0; i<data.length; i++) {
	    out.println(df.format(i*dx) + "\t" + df.format(data[i]));
	}
	out.flush();
    }
    
    public void write(PrintStream out) { write(out, new DecimalFormat("0.000E0")); }
    
    public Samples averagePower(int windowSize) {
	Samples power = new Samples();
	windowSize = ArrayUtil.getTruncatedFFTSize(windowSize);
	power.dx = 1.0 / (windowSize * dx);
	power.data = ArrayUtil.averagePower(data, windowSize);
	return power;
    }
}
