Question

I cannot get what size parameters are for fftwf_plan_dft_r2c_2d

  • Input: a N rows by M cols matrix
  • Output: a N rows by floor(M/2) + 1 cols matrix ?

Are parameters input or output size?

Tried to give input size. This is what GDB sais

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1676.0x768]
0x637eed72 in n1fv_8 () from C:\devfiles\bin\libfftw3f-3.dll
(gdb) backtrace
#0  0x637eed72 in n1fv_8 () from C:\devfiles\bin\libfftw3f-3.dll
#1  0x7c91a000 in ntdll!RtlpUnWaitCriticalSection ()
   from C:\WINDOWS\system32\ntdll.dll

No other thread uses fftw at the time.

The context:

Herbs::MatrixStorage<float> spectrum_in(frame_a.nRowsGet(),frame_a.nColsGet());
Herbs::MatrixStorage<std::complex<float>> 
    spectrum_out(frame_a.nRowsGet(),frame_a.nColsGet()/2+1);

Check for heap corruption issued by possible alllocation mistakes in MatrixStorage class . The rows in the matrix is one large block. rowGet returns the pointer to the given row.

memset(spectrum_in.rowGet(0),0
    ,sizeof(float)*spectrum_in.nRowsGet()*spectrum_in.nColsGet());
memset(spectrum_out.rowGet(0),0
    ,sizeof(float)*spectrum_out.nRowsGet()*spectrum_out.nColsGet());
heapdump(); //Heap seams to be fine after these

Causes sigsevg

FFT::PlanFloat_2dR2C plan(spectrum_in,spectrum_out);

The plan constructor does the following

plan=FFT::PlanFloat_2dR2C::PlanFloat_2dR2C(Herbs::MatrixStorage<InputType>& buffer_in
,Herbs::MatrixStorage<OutputType>& buffer_out)
{
plan=fftwf_plan_dft_r2c_2d
    (
     buffer_in.nRowsGet()
    ,buffer_in.nColsGet()
    ,buffer_in.rowGet(0)
    ,(fftwf_complex*)buffer_out.rowGet(0)
    ,FFTW_MEASURE
    );
}

EDIT:

I used a precompiled DLL instead. GCC may produce bad code on 32-bit Windows (From release notes):

Removed an archaic stack-alignment hack that was failing with gcc-4.7/i386. Added stack-alignment hack necessary for gcc on Windows/i386. We will regret this in ten years (see previous change).

EDIT 2:

The dll became bad due to wrong options given to the configure script. The documentation is now updated.

Was it helpful?

Solution

You are correct. For an NxM float or double input you should allocate Nx(M/2+1) fftwf_complex or fftw_complex output.

The parameters are the input size. For example,

#include "fftw3.h"

#define Width 1024
#define Height 768

int main(){
        float input[Width*Height];
        fftwf_complex *fft = new fftwf_complex[((Width/2)+1)*Height];
        fftwf_plan fplan = fftwf_plan_dft_r2c_2d(Height, Width,
                                 (float*)input, fft, FFTW_ESTIMATE);
        fftwf_execute(fplan);
        fftwf_destroy_plan(fplan);
}

See Chapter 4.3 Basic Interface of the FFTW User Manual

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top