import java.text.*;

public class FFTTest {
    
    public static void main(String[] args) {
	int N = 8;
	double[] data = new double[N];
	
	data[0] = 1;
	
	for(int i=0; i<N; i++) {
	    //data[i] = Math.exp(-(i*i)/8.0);
	    //data[i] += 1.0;
	    //data[i] += Math.cos(0.25 * i * Math.PI);
	    //data[i] += i%2 == 0 ? 1 : -1;
	}
	
	//ArrayUtil.realft(data, data.length, true);
	//for(int i=0; i<N; i++) System.out.println(new DecimalFormat("0.000").format(data[i]));
	
	//Complex[] spectrum = new Complex[N/2 + 1];
	//for(int f=0; f<spectrum.length; f++) spectrum[f] = new Complex();
	// ArrayUtil.unsecureFFT(data, spectrum);
	//for(int f=0; f<spectrum.length; f++) System.out.println(spectrum[f].toString());
		
	Complex[] spectrum = ArrayUtil.FFT(data);
	for(int f=0; f<spectrum.length; f++) spectrum[f].math('*', spectrum[f]);

	//Complex[] spectrum = ArrayUtil.hanningWindowedFFT(data, 16);
	double[] A = ArrayUtil.amplitude(spectrum);       
	ArrayUtil.print(A, new DecimalFormat("0.000"));

	//double[] P = ArrayUtil.averagePower(data, 8);       
	//ArrayUtil.print(P, new DecimalFormat("0.000"));

	//double[] P = ArrayUtil.averagePower(data, 16);
	//ArrayUtil.print(P, new DecimalFormat("0.000"));

	System.out.println();

	double[] back = ArrayUtil.backFFT(spectrum);
	ArrayUtil.print(back, new DecimalFormat("0.000"));
    }
}
