package transforms.fft;
public class FFT2d {
float dataRe[][], dataIm[][];
int width, height;
public FFT2d(float inputRe[], float inputIm[], int inputWidth) {
if (inputRe.length != inputIm.length) {
System.out.println("Error: the length of real part & imaginary part " +
"of the input to 2-d FFT are different");
return;
} else {
width = inputWidth;
height = inputRe.length / width;
dataRe = new float[height][width];
dataIm = new float[height][width];
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++) {
dataRe[i][j] = inputRe[i * width + j];
dataIm[i][j] = inputIm[i * width + j];
}
FFT1d fft1 = new FFT1d(width);
for (int i = 0; i < height; i++)
fft1.fft(dataRe[i], dataIm[i]);
float temRe[][] = transpose(dataRe);
float temIm[][] = transpose(dataIm);
FFT1d fft2 = new FFT1d(height);
for (int j = 0; j < width; j++)
fft2.fft(temRe[j], temIm[j]);
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++) {
inputRe[i * width + j] = temRe[j][i];
inputIm[i * width + j] = temIm[j][i];
}
}
}
private float[][] transpose(float[][] input) {
float[][] output = new float[width][height];
for (int j = 0; j < width; j++)
for (int i = 0; i < height; i++)
output[j][i] = input[i][j];
return output;
}
}