Showing results for 
Search instead for 
Did you mean: 
Honored Contributor I

FFT / IFFT Example Inconsistency



I was looking at using the 2D FFT / IFFT examples in an application however I was coming across incorrect values for the IFFT result. I'm using MATLAB to compare results and for verification. It appears that the 2D-FFT matches perfectly against matlab's fft2() function, however it differs from the ifft2() function when using the 2D-IFFT example. 


I've made a quick test case using the 2D FFT / IFFT example as a proof of concept of this inconsistency I'm seeing. In the original example, a new set of data is generated for each FFT / IFFT test. I changed this so that it generates one set of data and thus, by performing the FFT followed by an IFFT, I should see the same data out that I originally sent in. From here the only major change should be caused from floating-point error. From just looking at the first 10 values, I'm getting significantly different values than I expected. 


Also in the C host code, "golden truth" values are computed at each FFT / IFFT test which are used to compare for SNR error in dB. The C code matches the results with the OpenCL kernels and so the same inconsistency applies to the "golden truth" values as well, where the FFT is correct and the IFFT appears to be incorrect. All of my tests have been done with the emulator, but I would expect the same thing to show up when doing a full compile. 


Am I missing something here or making a mistake somewhere? I've attached the quick test case described above (I removed all the SVM stuff).  

Also, another thing to note is that I've only made changes to the host file, everything else is the same from the altera examples since ideally the only thing to switch between FFT and IFFT is switching the boolean value.
0 Kudos
2 Replies
Honored Contributor I

You haven't described how you implemented 2D fft/ifft and are you looking at sim results. Is it just a black box 2D fft followed by 2D ifft ip. 

for 2D fft it equals fft on columns followed by fft of rows of resulting output. For ifft you do ifft of resulting rows then ifft of resulting columns. 

Additionally it could be scaling issue.
Honored Contributor I

The 2D FFT / IFFT are taken from the altera opencl examples page and is treated as a black box.  


The link to the example is here: 


I'm not too familiar with the inner workings of the example but it uses 3 kernels fetch, fft2d, and transpose and repeats these operations a total of two times on a 1D FFT, one along the rows and again along the columns. 

I believe it implement the Cooley–Tukey FFT algorithm using butterflys and twiddle factors for the 1D FFT. 


For the IFFT since it is along the rows first and along the columns, I suppose I can try and transpose the data before sending it back into the IFFT and give that a try. 


As for the scale, it is determined by the LOGN define which is defaulted to 10 so it would be performing on a 1024x1024 matrix. 



Transposing before sending it into the IFFT doesn't seem to yield the expected result