I'm trying to implement FFT and iFFT using Intel MKL. The FFT on the real input works fine and the output array I get back is correct. On using the same output array for an iFFT the values that are returned are all multiplied by the size of the array and this holds true for all sizes. I'm unable to understand why this is happening. The code is as follows:
size_t size;
std::cout << "enter the size of input and output array: ";
std::cin >> size;
float *inp = NULL;
MKL_Complex8 *op = NULL;
MKL_LONG status;
// Allocate memory for the arrays.
inp = (float*) mkl_malloc(size*sizeof(float), 64);
op = (MKL_Complex8*) mkl_malloc((size/2+1)*sizeof(MKL_Complex8), 64);
//Initialize values of input
for (size_t i = 0; i < size; i++){
if(i < 8)
inp[i] = -std::rand()%10;
else if(i ==8)
inp[i] = 0;
else
inp[i] = std::rand()%10;
}
std::cout << "The input array is: " << std::endl;
for (size_t i = 0; i < size; i++){
std::cout << inp[i] << ", ";
}
std::cout << std::endl;
//Specify descriptor values.
DFTI_DESCRIPTOR_HANDLE hand = NULL;
status = DftiCreateDescriptor(&hand, DFTI_SINGLE, DFTI_REAL, 1, (MKL_LONG) size);
status = DftiSetValue(hand, DFTI_PLACEMENT, DFTI_NOT_INPLACE);
status = DftiSetValue(hand, DFTI_CONJUGATE_EVEN_STORAGE, DFTI_COMPLEX_COMPLEX);
status = DftiSetValue(hand, DFTI_PACKED_FORMAT, DFTI_CCE_FORMAT);
status = DftiCommitDescriptor(hand);
status = DftiComputeForward(hand, inp, op);
status = DftiComputeBackward(hand, op, inp);
std::cout << "\nThe output of iFFT is: " << std::endl;
for (size_t i = 0; i < size; i++){
std::cout << inp[i] << ", ";
}
std::cout << std::endl;
DftiFreeDescriptor(&hand);
free(inp);
free(op);
return 0;
}
A crude workaround would be to divide individual array elements by the size after iFFT, but that fails to explain why this is happening in the first place. It would be much better to understand the actual cause and rectify that. This is a trial to implement these transforms before the actual code and I would really like to understand why this is happening. Thanks.