<< Chapter < Page | Chapter >> Page > |
The beginning of the class and the beginning of the static method named xform2D is shown in Listing 1 .
This method computes a forward 2D Fourier transform from the space domain into the wavenumber domain. The number of points produced for the wavenumberdomain matches the number of points received for the space domain in both dimensions. Note that the input data must be purely real. In other words, theprogram assumes that there are no imaginary values in the space domain. Therefore, this is not a general purpose 2D complex-to-complex transform.
Listing 1. Beginning of the class named ImgMod30. |
---|
class ImgMod30{
static void xform2D(double[][] inputData,double[][]realOut,
double[][] imagOut,double[][]amplitudeOut){
int height = inputData.length;int width = inputData[0].length;System.out.println("height = " + height);System.out.println("width = " + width); |
The first parameter is a reference to a 2D double array object containing the data to be transformed. The remaining three parameters arereferences to 2D double array objects of the same size that will be populated with the following transform results:
Listing 1 also determines and displays the dimensions of the incoming 2D array of data to be transformed.
I won't bore you with the details as to how and why the 2D Fourier transform does what it does. Neither will I bore you with the details of the code thatimplements the 2D Fourier transform. If you understand the material that I have previously published on Fourier transforms in one dimension, this code and these concepts should be astraightforward extension from one dimension to two dimensions.
The remainder of the xform2D method is shown in Listing 2 . Note that it was necessary to sacrifice indentation in order to force these very long equationsto be compatible with this narrow publication format and still be somewhat readable.
Listing 2. The remainder of the xform2D method. |
---|
//Two outer loops iterate on output data.
for(int yWave = 0;yWave<height;yWave++){
for(int xWave = 0;xWave<width;xWave++){
//Two inner loops iterate on input data.for(int ySpace = 0;ySpace<height;
ySpace++){for(int xSpace = 0;xSpace<width;
xSpace++){//Compute real, imag, and ampltude.
realOut[yWave][xWave] +=(inputData[ySpace][xSpace]*cos(2*PI*((1.0*
xWave*xSpace/width)+(1.0*yWave*ySpace/height))))/sqrt(width*height);imagOut[yWave][xWave ]-=
(inputData[ySpace][xSpace]*sin(2*PI*((1.0*xWave*xSpace/width) + (1.0*yWave*ySpace/height))))
/sqrt(width*height);amplitudeOut[yWave][xWave] =sqrt(
realOut[yWave][xWave] * realOut[yWave][xWave] +imagOut[yWave][xWave]* imagOut[yWave][xWave]);
}//end xSpace loop}//end ySpace loop
}//end xWave loop}//end yWave loop
}//end xform2D method |
The inverseXform2d method is shown in its entirety in Listing 3 . This method computes an inverse 2D Fourier transform from the complex wavenumber domain into thereal space domain. The number of points produced for the space domain matches the number of points received for the wavenumber domain in both dimensions.
Notification Switch
Would you like to follow the 'Digital signal processing - dsp' conversation and receive update notifications?