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

public final class FTSignal {

    public static void getSpectra(ReductionTool cleaner) {
	int windowSize = 256;
	double[] spectrum = new double[129];
	for(int scan=0; scan<cleaner.scans; scan++) {
	    double[] correlated = new double[cleaner.correlated[scan].length];
	    for(int t=0; t<correlated.length; t++) correlated[t] = cleaner.correlated[scan][t];
	    double[] scanSpectrum = ArrayUtil.averagePower(correlated, windowSize);
	    for(int k=0; k < spectrum.length; k++) spectrum[k] += scanSpectrum[k];	    
	}
	for(int k=0; k < spectrum.length; k++) {
	    spectrum[k] /= cleaner.scans;
	    spectrum[k] *= 1e18;
	}
	
	try {
	    File file = new File("spectrum.dat");
	    if(file.exists()) file.delete();
	    
	    RandomAccessFile out = new RandomAccessFile(file, "rw");
	    DecimalFormat df = new DecimalFormat("0.00E0");
	    
	    for(int k=0; k < spectrum.length; k++) out.writeBytes(k + "\t" + df.format(spectrum[k]) + "\n");
	    
	    out.close();
	} 
	catch(IOException e) {}
    }
}


