FFT scale factor usage is inconsistant

FFT scale factor usage is inconsistant

I downloaded a 30-day trial of MKL to play around with the 2D FFT and test the speed of the routines. The performance has been exceptional and I plan to purchase a license. But I ran into one issue that looks like a software bug. I am coding in C#. If I use a simple real array input, forward transform, and backward transform, the resulting array, x_normal, contains the same as my inputted array. But if I use a real and imaginary array input, forward transform, and backward transform, the resulting aray, x_normal_real, differs from the inputted array by the scale factor. In my case, I send a image of 1024 x 1024, so the scale factor is 1 / 1024 * 1 / 1024 = .0.0000009536743164. Is there a reason why complex 2D input is not scaled like real 2D input? For more information, I include the relevant portions of my two code cases below. Method 1: Real var desc = new IntPtr(); int precision = DFTI.DOUBLE; int forward_domain = DFTI.REAL; // DFTI.COMPLEX; int dimension = 2; int[] len = {rows, columns}; // Create the new DTFI descriptor int ret = DFTI.DftiCreateDescriptor(ref desc, precision, forward_domain, dimension, len); // Setup the scale factor long transform_size = rows * columns; double scale_factor = 1.0 / transform_size; DFTI.DftiSetValue(desc, DFTI.BACKWARD_SCALE, scale_factor); // Setup the transform parameters DFTI.DftiSetValue(desc, DFTI.PLACEMENT, DFTI.NOT_INPLACE); DFTI.DftiSetValue(desc, DFTI.PACKED_FORMAT, DFTI.PACK_FORMAT); // Commit the descriptor DFTI.DftiCommitDescriptor(desc); // The data to be transformed var x_normal = new double[rows * columns]; var x_transformed = new double[rows * columns]; // Initialize the data array for (int y = 0; y < rows; y++) // actually v for (int x = 0; x < columns; x++) // actually u x_normal[y*rows + x] = ((frameImageData[y, x] > 100.0) ? 100.0 : frameImageData[y, x]) + baseline; // Forward transform DFTI.DftiComputeForward(desc, x_normal, x_transformed); // Backward transform DFTI.DftiComputeBackward(desc, x_transformed, x_normal); DFTI.DftiFreeDescriptor(ref desc); Method 2: Complex var desc = new IntPtr(); int precision = DFTI.DOUBLE; int forward_domain = DFTI.COMPLEX; int dimension = 2; int[] len = {rows, columns}; // Create the new DTFI descriptor int ret = DFTI.DftiCreateDescriptor(ref desc, precision, forward_domain, dimension, len); // Setup the scale factor long transform_size = rows * columns; double scale_factor = 1.0 / transform_size; DFTI.DftiSetValue(desc, DFTI.BACKWARD_SCALE, scale_factor); // Try floating-point and GetValue function double backward_scale = 0.0; DFTI.DftiGetValue(desc, DFTI.BACKWARD_SCALE, ref backward_scale); // Setup the transform parameters DFTI.DftiSetValue(desc, DFTI.PLACEMENT, DFTI.NOT_INPLACE); DFTI.DftiSetValue(desc, DFTI.PACKED_FORMAT, DFTI.PACK_FORMAT); DFTI.DftiSetValue(desc, DFTI.COMPLEX_STORAGE, DFTI.REAL_REAL); // Commit the descriptor DFTI.DftiCommitDescriptor(desc); // The data to be transformed var x_normal_real = new double[rows * columns]; var x_normal_imaginary = new double[rows * columns]; var x_transformed_real = new double[rows * columns]; var x_transformed_imaginary = new double[rows * columns]; // Initialize the data array for (int y = 0; y < rows; y++) // actually v for (int x = 0; x < columns; x++) // actually u x_normal_real[y*rows + x] = ((frameImageData[y, x] > 100.0) ? 100.0 : frameImageData[y, x]) + baseline; for (int z = 0; z < rows * columns; z++) x_normal_imaginary[0] = 0.0; // Forward transform DFTI.DftiComputeForward(desc, x_normal_real, x_normal_imaginary, x_transformed_real, x_transformed_imaginary); // Backward transform DFTI.DftiComputeBackward(desc, x_transformed_real, x_transformed_imaginary, x_normal_real, x_normal_imaginary); DFTI.DftiFreeDescriptor(ref desc);

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

Hi thanks for posting your question. Your code snippets have cramped into a big text blob that is very hard to read. Would you please attach a file of your code using the upload button?

Thanks!

Preview showed nice formatting of code. But after commit, all formatting was lost. Here is attachment.

Attachments: 

AttachmentSize
Downloadtext/plain mkl-fft-code-examples.txt4.05 KB

Hi S.,

This is known bug for MKL 11.0.3. It has been fixed in a later release. To workaround this bug, instead of setting BACKWARD_SCALE please scale the image by a separate loop.

Thanks
Dima

Leave a Comment

Please sign in to add a comment. Not a member? Join today