Fast Fourier Transform CUFFT

Hello, i am working in a project in a code with CUFFT but i don’t really know what it does. I have tried to transform a dirac delta function but i don´t get a constant as an output. Is this correct? or am i using it wrongly? What should I expect to be the output of this function???

In case you need it, this is part of my code in CUDA C:

int main()
{
cufftComplex *y,*h;
cufftComplex *h_d;

int size = NX* BATCH * sizeof(cufftComplex);

h = (cufftComplex*) malloc (size);
y = (cufftComplex*) malloc (size);

for (int m = 0; m < NX*BATCH; m++)
{	
	h [m].x = (float) 0;
	h [m].y = (float) 0;
}

h[20].x=(float)1;

cufftHandle plan;

cudaMalloc((void**)&h_d, size);
	
cudaMemcpy (h_d, h, size, cudaMemcpyHostToDevice);

//Create a 1D FFT plan.
cufftPlan1d(&plan, NX, CUFFT_C2C, BATCH);

//Use the CUFFT plan to transform the signal in place.
cufftExecC2C(plan, h_d, h_d, CUFFT_FORWARD);

cudaMemcpy (y, h_d, size, cudaMemcpyDeviceToHost);

// Destroy the CUFFT plan.
cufftDestroy(plan);

cudaFree(h_d);

for (int n = 0; n <NX*BATCH; n++)
{
	printf("h_d[%i] = %f\n",n, y[n].y);
}
free (y);
free (h);
	
return(0);

}

Thanks for your help!!! :wave:

Hello, i am working in a project in a code with CUFFT but i don’t really know what it does. I have tried to transform a dirac delta function but i don´t get a constant as an output. Is this correct? or am i using it wrongly? What should I expect to be the output of this function???

In case you need it, this is part of my code in CUDA C:

int main()
{
cufftComplex *y,*h;
cufftComplex *h_d;

int size = NX* BATCH * sizeof(cufftComplex);

h = (cufftComplex*) malloc (size);
y = (cufftComplex*) malloc (size);

for (int m = 0; m < NX*BATCH; m++)
{	
	h [m].x = (float) 0;
	h [m].y = (float) 0;
}

h[20].x=(float)1;

cufftHandle plan;

cudaMalloc((void**)&h_d, size);
	
cudaMemcpy (h_d, h, size, cudaMemcpyHostToDevice);

//Create a 1D FFT plan.
cufftPlan1d(&plan, NX, CUFFT_C2C, BATCH);

//Use the CUFFT plan to transform the signal in place.
cufftExecC2C(plan, h_d, h_d, CUFFT_FORWARD);

cudaMemcpy (y, h_d, size, cudaMemcpyDeviceToHost);

// Destroy the CUFFT plan.
cufftDestroy(plan);

cudaFree(h_d);

for (int n = 0; n <NX*BATCH; n++)
{
	printf("h_d[%i] = %f\n",n, y[n].y);
}
free (y);
free (h);
	
return(0);

}

Thanks for your help!!! :wave:

your code is correct.
you should compare your result to MATLAB.

According to Riesz-representation, there exists a vector y corresponding to delta function under finite dimensional, satisfying

\delta[\phi] = <y, \phi> for all \phi

and
(1) <y, \phi> is forward FFT of y
(2) \delta[\phi] = \phi(x) if x is a grid of dicrete FFT

so result of forward FFT is not a constant vector except x = 0.

your code is correct.
you should compare your result to MATLAB.

According to Riesz-representation, there exists a vector y corresponding to delta function under finite dimensional, satisfying

\delta[\phi] = <y, \phi> for all \phi

and
(1) <y, \phi> is forward FFT of y
(2) \delta[\phi] = \phi(x) if x is a grid of dicrete FFT

so result of forward FFT is not a constant vector except x = 0.