开发者

Problem with FFTW2 routine in C

I'm currently working with the FFTW2 (Fastest Fourier Transform in the West) library, and after writing a successful routine in Fortran, I am moving on to C. However, I'm having some trouble with data 开发者_如何学Cassigning when I try to input the data to transform (ie, the values of sin(x)). Currently, my code is:

#include <stdio.h>
#include <fftw.h>
#include <math.h>
#include <complex.h>

void compute_fft(){
  int i;
  const int n[8];
  fftw_complex in[8];
  fftwnd_plan p;

  in[0]->re = 0;
  in[1]->re = (sqrt(2)/2);
  in[2]->re = 1;
  in[3]->re = (sqrt(2)/2);
  in[4]->re = 0;
  in[5]->re = -(sqrt(2)/2);
  in[6]->re = -1;
  in[7]->re = -(sqrt(2)/2);

  for(i = 0; i < 8; i++){
    (in[i])->im = 0;
  }

  p = fftwnd_create_plan(8, n, FFTW_FORWARD, FFTW_ESIMATE | FFTW_IN_PLACE);
  fftwnd_one(p, &in[0], NULL);
  fftwnd_destroy_plan(p);

  printf("Sin\n");
  for(i = 0; i < 8; i++){
    printf("%d\n", n[i]);
  }
}

I've been using this http://fftw.org/fftw2_doc/ link for documentation/tutorial purposes, and currently my error is "invalid type argument of a->a (have afftw_complexa)", and the 'a' characters on either side of the -> and fftw_complex have carats above them. I'm using basically the same pattern that worked when I wrote this in Fortran, and I seem to be following the tutorial, it's really just this assignment here that I am messing up the syntax on. For the record, the compiler I am using is nvcc, if it makes a difference (I previously tried gcc). If anyone here has every used FFTW2 in C before, could you help correct my mistake? Thank you!


It might be because of your array "in" which is a array of fftw_complex so instead of using in[0]->re = 0 you should use it as in[0].re = 0. Unless fftw_complex is again typedefined to some array.

fftw_complex in[8];
in[0].re = 0;
in[1].re = (sqrt(2)/2);
in[2].re = 1;
in[3].re = (sqrt(2)/2);
in[4].re = 0;
in[5].re = -(sqrt(2)/2);
in[6].re = -1;
in[7].re = -(sqrt(2)/2);


Since ffwt_complex is an double[2] being the first dimension([0]) for the real data and the second ([1]) for the imaginary data, a safe solution is:

  in[0][0] = 0;
  in[1][0] = (sqrt(2)/2);
  in[2][0] = 1;
  in[3][0] = (sqrt(2)/2);
  in[4][0] = 0;
  in[5][0] = -(sqrt(2)/2);
  in[6][0] = -1;
  in[7][0] = -(sqrt(2)/2);

 for(i = 0; i < 8; i++){
   in[i][1] = 0;
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜