1 //Title: 2-d mixed radix FFT.
3 //Copyright: Copyright (c) 1998
5 //Company: University of Wisconsin-Milwaukee.
7 // . Use FFT1d to perform FFT2d.
12 // Input of FFT, 2-d matrix.
13 double dataRe[][], dataIm[][];
15 // Width and height of 2-d matrix inputRe or inputIm.
18 // Constructor: 2-d FFT of Complex data.
19 public FFT2d(double inputRe[], double inputIm[], int inputWidth) {
20 // First make sure inputRe & inputIm are of the same length.
21 if (inputRe.length != inputIm.length) {
22 System.out.println("Error: the length of real part & imaginary part " +
23 "of the input to 2-d FFT are different");
27 height = inputRe.length / width;
28 dataRe = new double[height][width];
29 dataIm = new double[height][width];
30 //System.out.println("width = "+ width + " height = " + height + "\n");
32 for (int i = 0; i < height; i++)
33 for (int j = 0; j < width; j++) {
34 dataRe[i][j] = inputRe[i * width + j];
35 dataIm[i][j] = inputIm[i * width + j];
38 //System.out.println("Initially dataRe[100][8] = "+ dataRe[100][8] + "\n");
39 //System.out.println("copy to Input[] inputRe[1008] = "+ inputRe[1008] + "\n");
41 // Calculate FFT for each row of the data.
42 FFT1d fft1 = new FFT1d(width);
43 for (int i = 0; i < height; i++)
44 fft1.fft(dataRe[i], dataIm[i]);
46 //System.out.println("After row fft dataRe[100][8] = "+ dataRe[100][8] + "\n");
47 //System.out.println("Element 100 is " + (int)inputRe[100]+ "\n");
48 //System.out.println("Element 405 is " + (int)inputIm[405]+ "\n");
50 // Calculate FFT for each column of the data.
51 double temRe[][] = transpose(dataRe);
52 double temIm[][] = transpose(dataIm);
54 //System.out.println("before column fft dataRe[100][8] = "+ dataRe[100][8] + " temRe[8][100]= " + temRe[8][100] + "\n");
55 FFT1d fft2 = new FFT1d(height);
56 for (int j = 0; j < width; j++)
57 fft2.fft(temRe[j], temIm[j]);
58 //System.out.println("after column fft dataRe[100][8] = "+ dataRe[100][8] + " temRe[8][100]= " + temRe[8][100] + "\n");
60 //System.out.println("Element 100 is " + (int)inputRe[100]+ "\n");
61 //System.out.println("Element 405 is " + (int)inputIm[405]+ "\n");
63 // Copy the result to input[], so the output can be
64 // returned in the input array.
65 for (int i = 0; i < height; i++)
66 for (int j = 0; j < width; j++) {
67 inputRe[i * width + j] = temRe[j][i];
68 inputIm[i * width + j] = temIm[j][i];
70 //System.out.println("copy to Input[] inputRe[1008] = "+ inputRe[1008] + "\n");
74 // Transpose matrix input.
75 private double[][] transpose(double[][] input) {
76 double[][] output = new double[width][height];
78 for (int j = 0; j < width; j++)
79 for (int i = 0; i < height; i++)
80 output[j][i] = input[i][j];
83 } // End of function transpose().
86 public static void main(String[] args) {
91 NUM_THREADS=Integer.parseInt(args[0]);
93 SIZE = Integer.parseInt(args[1]);
96 System.out.println("Num threads = " + NUM_THREADS + " SIZE= " + SIZE + "\n");
99 // Matrix inputRe, inputIm;
103 inputRe = new double[SIZE];
104 inputIm = new double[SIZE];
106 for(int i = 0; i<SIZE; i++){
111 //System.out.println("Element 231567 is " + (int)inputRe[231567]+ "\n");
112 //System.out.println("Element 10 is " + (int)inputIm[10]+ "\n");
113 // Start Barrier Server
115 // Width and height of 2-d matrix inputRe or inputIm.
118 int Relength, Imlength;
119 height = inputRe.length / width;
120 Relength = inputRe.length;
121 Imlength = inputIm.length;
123 // Create threads to do FFT
124 FFT2d myfft2d = new FFT2d(inputRe, inputIm, inputWidth);
126 System.out.println("2DFFT done! \n");
127 //System.out.println("Element 23157 is " + (int)inputRe[23157]+ "\n");
128 //System.out.println("Element 10 is " + (int)inputIm[10]+ "\n");