Hi,

I’m trying to use cuFFT API.

So, I made a simple example for fft and ifft using cuFFT and I compared the result with MATLAB.

However, the result was totally different from MATLAB. I think MATLAB result is right.

I attach the source code and results.

If anyone has an idea, please let me know! thank you.

#define SIGNAL_SIZE_TEST 4

int main()

{

int _size = sizeof(cufftComplex) * SIGNAL_SIZE_TEST;

cufftComplex *x_t;

```
//Allocate host memory for the x(t)
x_t = (cufftComplex *)malloc(sizeof(cufftComplex) * SIGNAL_SIZE_TEST);
//Allocate host memory for the result(t)
cufftComplex *result = (cufftComplex *)malloc(_size);
x_t[0].x = 5;
x_t[1].x = 7;
x_t[2].x = 9;
x_t[3].x = 15;
x_t[0].y = 0;
x_t[1].y = 0;
x_t[2].y = 0;
x_t[3].y = 0;
//Allocate device memory for signal
cufftComplex *x_w;
checkCudaErrors(cudaMalloc((void **)&x_w, _size));
//Copy host memory to device
checkCudaErrors(cudaMemcpy(x_w, x_t, _size, cudaMemcpyHostToDevice));
//cufft plan
cufftHandle plan;
checkCudaErrors(cufftPlan1d(&plan, SIGNAL_SIZE_TEST, CUFFT_C2C, 1));
//FFT
printf("Transforming signal cufftexecC2C\n");
checkCudaErrors(cufftExecC2C(plan, x_w, x_w, CUFFT_FORWARD));
//Print-out the result of FFT
checkCudaErrors(cudaMemcpy(result, x_w, _size, cudaMemcpyDeviceToHost));
for(unsigned int i = 0; i<SIGNAL_SIZE_TEST; i++)
{
printf("Real: %f, imagi: %f \n", result[i].x, result[i].y);
}
//IFFT
checkCudaErrors(cufftExecC2C(plan, x_w, x_w, CUFFT_INVERSE));
//Copy device memory to host
printf("Copy device memory to host\n");
checkCudaErrors(cudaMemcpy(result, x_w, _size, cudaMemcpyDeviceToHost));
//Print-out the result of iFFT
for(unsigned int i = 0; i<SIGNAL_SIZE_TEST; i++)
{
printf("Real: %f, imagi: %f \n", result[i].x, result[i].y);
}
```

}

///////////////////////////////

result

- cuda result :

input: [5+0i, 7+0i, 9+0i, 15+0i]

fft result : 36+0i, -4+8i, -8+0i, -4-8i

ifft result: 20+0i, 28+0i, 36+0i, 60+0i

- matlab result:

input: [5+0i, 7+0i, 9+0i, 15+0i]

fft result: 9+0i, -1-2i, -2+0i, -1+2i

ifft result: [5+0i, 7+0i, 9+0i, 15+0i]