2D FFT in C: confused

2D FFT in C: confused

Hi folks. I'm trying to do a simple 2d real fft with MKL 9.0beta in C, and I'm getting garbage out, not sure why. I think it's something to do with data layout though.

Here's my code; it's pretty simple:

/* Create float array of pixels. The idea is it should be rowsize across, and colsize down. It needs extra elements to hold the FFT data (in CCS format by default). */
int real_rowsize = 2 * (rowsize/2 + 1);
int complex_rowsize = rowsize/2 + 1;
int arraysize = real_colsize * complex_rowsize;
float *f_in = malloc(sizeof(float _Complex) * arraysize);
float *f_out = malloc(sizeof(float _Complex) * arraysize);
/* ... fill in f_in with image data... */

length[0] = colsize;
length[1] = rowsize;
status = DftiCreateDescriptor(&desc_handle, DFTI_SINGLE, DFTI_REAL, 2, length);
status = DftiSetValue(desc_handle, DFTI_BACKWARD_SCALE, 1.0/(colsize * rowsize));
status = DftiCommitDescriptor(desc_handle);
status = DftiComputeForward(desc_handle, f_in);
memcpy(f_out, f_in, sizeof(float _Complex) * arraysize);
status = DftiComputeBackward(desc_handle, f_out);
/* read image data out of f_out. */

Looks trivial, and it should return f_out == f_in. But I get garbage. Actually not quite garbage, I can see a little of my original image, like I'm looking at the LSBs or something. Can anyone see anything wrong with this?

I know I've allocated enough memory, but I'm not sure I've got the length args right. Still, I think a fwd->backward transform pair ought to work even if I got them backwards! What else is there to go wrong? I'm checking all the status return values and they're fine.

This is on Windows ia32, btw, with the Intel 9.0 compiler and 9.0beta MKL. I'm linking with -lmkl_c -lmkl_ia32 -lguide40.

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.