Reputation: 9
I have been following an example (https://github.com/ContinuumIO/numbapro-examples/blob/master/convolution/fftconvolve.py) given to do fftconvolve with an image and a kernel, both are 2D arrays. In my use case I would like to do fftconvolve with two 1D arrays to look for possible match and delay between. I have tried to convert the example to 1D but received a few Invalid type combination
errors. Is there possibly a better example to follow for 1-dimentional array fftconvolve using CUDA through numbapro? thanks
Upvotes: 0
Views: 245
Reputation: 2912
Doing convolution in time domain is equivalent of doing fft in the Fourier domain. This is one of the fundamentals in signal processing.
Therefore, to do convolution of vector1 and vector2, you can simply apply fft (1D) to vector1 and vector2, and multiply the two complex transform together (filtering), and then inverse fft the product back into original domain.
In cuda, it should be something like this:
cufftHandle _planKernel // you fft handle
cufftPlan1d(&_planKernel, _fftLen, CUFFT_C2C, 1); // create 1D fft handle
cufftComplex* VECTOR1, *VECTOR2, *PRODUCT;
MakeVector1Complex<<<blockSize, GridSize>>>() // simply set real part of the VECTOR1 = vector1, and set the imaginary part VECTOR to 0
MakeVector2Complex<<<blockSize, GridSize>>>() // simply set real part of the VECTOR2 = vector2, and set the imaginary part VECTOR to 0
cufftExecC2C(planKernel, VECTOR1, VECTOR1, CUFFT_FORWARD); // apply fft to VECTOR1
cufftExecC2C(planKernel, VECTOR2, VECTOR2, CUFFT_FORWARD); // apply fft to VECTOR2
ComplexMutiplication<<<blockSize, GridSize>>>(VECTOR1, VECTOR2) // complex multiplication of VECTOR1 and VECTOR2
cufftExecC2C(planKernel, PRODUCT, PRODUCT, CUFFT_INVERSE); // inverse fft on the product of VECTOR1 AND VECTOR2
MakeProductReal<<<blockSize, GridSize>>>(PRODUCT) // extract the real part of PRODUCT
Now your job is done. There is also an example called "simpleCUFFT" in cuda toolkit, which you can find in C:\ProgramData\NVIDIA Corporation\CUDA Samples
Upvotes: 2