From: tcharles on
Hello,
can anyone explain me how to perform the convolution of two dimentional
array with fftw?
Thanks

From: cincydsp on

tcharles wrote:
> Hello,
> can anyone explain me how to perform the convolution of two dimentional
> array with fftw?
> Thanks

This method of performing convolution is a relatively straightforward
application of the FFT; see these links:

http://www.dspguide.com/ch18/2.htm
http://cnx.org/content/m10963/latest/

This would be no different with FFTW than any other environment; just
the mechanics of the source code used to perform the FFT would be
different.

Jason

From: stevenj on
tcharles wrote:
> double * fft::backward(fftw_complex * in) {
> out = new double[nx*(ny/2+1)];
> /* Backward transformation */
> plan_backward = fftw_plan_dft_c2r_2d(nx, ny, in, out, FFTW_ESTIMATE);
> fftw_execute ( plan_backward );
> return(out);
> }

> and I have a segmentation fault in the backward function, the debugger

The real output array of an out-of-place c2r transform should be of
size nx*ny, not nx*(ny/2+1). You are confusing the size of the complex
array with the size of the real array. See the FFTW manual.

You also have a memory leak because you don't call fftw_destroy_plan.

Note also that using "new" instead of "fftw_malloc" may prevent FFTW
from exploiting SIMD instructions (e.g. SSE/SSE2), since "new" is
probably not 16-byte aligned.

Steven G. Johnson

From: tcharles on
>tcharles wrote:
>> double * fft::backward(fftw_complex * in) {
>> out = new double[nx*(ny/2+1)];
>> /* Backward transformation */
>> plan_backward = fftw_plan_dft_c2r_2d(nx, ny, in, out,
FFTW_ESTIMATE);
>> fftw_execute ( plan_backward );
>> return(out);
>> }
>
>> and I have a segmentation fault in the backward function, the debugger
>
>The real output array of an out-of-place c2r transform should be of
>size nx*ny, not nx*(ny/2+1). You are confusing the size of the complex
>array with the size of the real array. See the FFTW manual.
>
>You also have a memory leak because you don't call fftw_destroy_plan.
>
>Note also that using "new" instead of "fftw_malloc" may prevent FFTW
>from exploiting SIMD instructions (e.g. SSE/SSE2), since "new" is
>probably not 16-byte aligned.
>
>Steven G. Johnson

Thanks for your answer, I wrote a destructor to call fftw_destroy_plan und
fftw_free, und made the following changes:

fft::~fft() {
fftw_destroy_plan (plan_backward );
fftw_destroy_plan (plan_forward );
fftw_free ( out );
fftw_free ( R );
}

double * fft::backward(fftw_complex * in) {
out = (double *)fftw_malloc ( sizeof ( double ) *nx*ny );
/* Backward transformation */
plan_backward = fftw_plan_dft_c2r_2d(nx, ny, in, out, FFTW_ESTIMATE);
fftw_execute ( plan_backward );
return(out);
}

but I still have size fault. The debugger output is:
Address 0x464C028 is 0 bytes inside a block of size 20,808 alloc'd
==2095== at 0x401A4CE: malloc (vg_replace_malloc.c:149)
==2095== by 0x8096AF4: fft::backward(double (*) [2]) (fft_l.C:68)
the line 68 is out = (double *)fftw_malloc ( sizeof ( double ) *nx*ny );
Thanks for your help.
Charles Tchoutat


 | 
Pages: 1
Prev: memory f2812
Next: ADC's noise on DSP 2812