DSPRelated.com
Forums

FFTw Forward/Backwards :s

Started by Jorge April 16, 2007
Hello,

I'm having some trouble to use FFTw library...

I'm using two plans like this:

fftw_plan fftw_plan_r2r_1d(SIZE_OF_IN, in, out, R2HC, FFTW_FORWARD);

fftw_plan fftw_plan_r2r_1d(2*SIZE_OF_IN +2, out, originalInput, HC2R,
FFTW_BACKWARD);

If i'm not wrong, i should be getting, after executing those two
plans, the same as 'in' array, in 'originalInput'. But all i get is
noise.

What's wrong ???. I know for sure it's something really easy... but i
can't figure it out.....

Thank you!!!

On Apr 16, 9:26 am, "Jorge" <jleandrope...@gmail.com> wrote:
> fftw_plan fftw_plan_r2r_1d(SIZE_OF_IN, in, out, R2HC, FFTW_FORWARD); > > fftw_plan fftw_plan_r2r_1d(2*SIZE_OF_IN +2, out, originalInput, HC2R, > FFTW_BACKWARD); > > If i'm not wrong, i should be getting, after executing those two > plans, the same as 'in' array, in 'originalInput'. But all i get is > noise.
You should be passing the same size (SIZE_OF_IN) for creating both plans. This is the order of the transform to be computed, regardless of the format of the data. Note also that both in[] and out[] should be arrays of length SIZE_OF_IN. Regards, Steven G. Johnson PS. After you do that, the result should be the original data scaled by SIZE_OF_IN, since FFTW computes an unnormalized DFT.
Jorge wrote:
> I'm having some trouble to use FFTw library... > > fftw_plan fftw_plan_r2r_1d(SIZE_OF_IN, in, out, R2HC, FFTW_FORWARD); > > [...] all i get is noise.
Yous should give the FFTW_ESTIMATE flag, otherwise your array contents may get overwritten by garbage during planning. Hendrik vdH
Thanks you both... but i'm still having trouble. Basically, my code is
like this (simplified,of course)

#define SIZE_OF_IN  32

forward       = fftwf_plan_r2r_1d(SIZE_OF_IN, in, out, FFTW_R2HC,
FFTW_FORWARD | FFTW_ESTIMATE );
backwards  = fftwf_plan_r2r_1d(SIZE_OF_IN, out, out2, FFTW_HC2R,
FFTW_BACKWARD | FFTW_ESTIMATE );

fftwf_execute(forward);
fftwf_execute(backwards);


I get WAY too much noise. *ANY* idea will be very welcome.

Thanks a lot!!
regards


On 16 abr, 15:23, Hendrik van der Heijden <h...@gmx.de> wrote:
> Jorge wrote: > > I'm having some trouble to use FFTw library... > > > fftw_plan fftw_plan_r2r_1d(SIZE_OF_IN, in, out, R2HC, FFTW_FORWARD); > > > [...] all i get is noise. > > Yous should give the FFTW_ESTIMATE flag, otherwise your array > contents may get overwritten by garbage during planning. > > Hendrik vdH
SOLVED !!!!!

"Recall that these transforms are unnormalized, so r2hc followed by
hc2r will result in the original data multiplied by n"....

so... all i had to do is divide every element of 'out2' array (ouput
of forward-backwards) by SIZE_OF_IN.

Thanks!



On 16 abr, 19:01, "Jorge" <jleandrope...@gmail.com> wrote:
> Thanks you both... but i'm still having trouble. Basically, my code is > like this (simplified,of course) > > #define SIZE_OF_IN 32 > > forward = fftwf_plan_r2r_1d(SIZE_OF_IN, in, out, FFTW_R2HC, > FFTW_FORWARD | FFTW_ESTIMATE ); > backwards = fftwf_plan_r2r_1d(SIZE_OF_IN, out, out2, FFTW_HC2R, > FFTW_BACKWARD | FFTW_ESTIMATE ); > > fftwf_execute(forward); > fftwf_execute(backwards); > > I get WAY too much noise. *ANY* idea will be very welcome. > > Thanks a lot!! > regards > > On 16 abr, 15:23, Hendrik van der Heijden <h...@gmx.de> wrote: > > > > > Jorge wrote: > > > I'm having some trouble to use FFTw library... > > > > fftw_plan fftw_plan_r2r_1d(SIZE_OF_IN, in, out, R2HC, FFTW_FORWARD); > > > > [...] all i get is noise. > > > Yous should give the FFTW_ESTIMATE flag, otherwise your array > > contents may get overwritten by garbage during planning. > > > Hendrik vdH- Ocultar texto de la cita - > > - Mostrar texto de la cita -
On Apr 16, 6:01 pm, "Jorge" <jleandrope...@gmail.com> wrote:
> forward = fftwf_plan_r2r_1d(SIZE_OF_IN, in, out, FFTW_R2HC, > FFTW_FORWARD | FFTW_ESTIMATE ); > backwards = fftwf_plan_r2r_1d(SIZE_OF_IN, out, out2, FFTW_HC2R, > FFTW_BACKWARD | FFTW_ESTIMATE );
You shouldn't be passing FFTW_FORWARD or FFTW_BACKWARD, either. These do not belong in the "flags" argument. The sign of the transform is specified by the 4th argument (FFTW_R2HC == forward, FFTW_HC2R == backward). i.e. do: forward = fftwf_plan_r2r_1d(SIZE_OF_IN, in, out, FFTW_R2HC, FFTW_ESTIMATE ); backwards = fftwf_plan_r2r_1d(SIZE_OF_IN, out, out2, FFTW_HC2R, FFTW_ESTIMATE ); Please also note the normalization that I mentioned before. Upon executing the two plans in sequence, out2[i] will be in[i] * SIZE_OF_IN, plus a small relative error on the order of the floating- point precision (1e-7 or so in single precision). Steven
Thank you very much Steven!!!

Regards


On 16 abr, 19:25, "Steven G. Johnson" <stev...@alum.mit.edu> wrote:
> On Apr 16, 6:01 pm, "Jorge" <jleandrope...@gmail.com> wrote: > > > forward = fftwf_plan_r2r_1d(SIZE_OF_IN, in, out, FFTW_R2HC, > > FFTW_FORWARD | FFTW_ESTIMATE ); > > backwards = fftwf_plan_r2r_1d(SIZE_OF_IN, out, out2, FFTW_HC2R, > > FFTW_BACKWARD | FFTW_ESTIMATE ); > > You shouldn't be passing FFTW_FORWARD or FFTW_BACKWARD, either. These > do not belong in the "flags" argument. The sign of the transform is > specified by the 4th argument (FFTW_R2HC == forward, FFTW_HC2R == > backward). i.e. do: > > forward = fftwf_plan_r2r_1d(SIZE_OF_IN, in, out, FFTW_R2HC, > FFTW_ESTIMATE ); > backwards = fftwf_plan_r2r_1d(SIZE_OF_IN, out, out2, FFTW_HC2R, > FFTW_ESTIMATE ); > > Please also note the normalization that I mentioned before. Upon > executing the two plans in sequence, out2[i] will be in[i] * > SIZE_OF_IN, plus a small relative error on the order of the floating- > point precision (1e-7 or so in single precision). > > Steven