I use FFTW to perform DFT and I have problem execute the pointwise multiplication, here is my code fftw_complex * fft::multiply(fftw_complex * A, fftw_complex * B) { fftw_complex * R; double scale = 1.0 / (nx * ny); R = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) *nx * ny); for(int i= 0; i < nx; i++) for(int j= 0; j < ny/2+1; j++){ int ij = i*(ny/2+1) + j; R[i][j].re = (A[ij].re * B[ij].re - A[ij].im * B[ij].im) * scale; R[i][j].im = (A[ij].re * B[ij].im + A[ij].im * B[ij].re) * scale; } return(R); } I receive such fault: fft_l.C:118: request for member `re' in `*((((i * 2) + j) * 8) + R)', which is of non-aggregate type `double' fft_l.C:118: request for member `re' in `*(A + (+(ij * 16)))', which is of non-aggregate type `double[2]' fft_l.C:119: request for member `re' in `*(B + (+(ij * 16)))', which is of non-aggregate type `double[2]' fft_l.C:119: request for member `im' in `*(A + (+(ij * 16)))', which is of non-aggregate type `double[2]' pleased can you tell me what wrong with my code Thanks
FFTW pointwise multiplication
Started by ●December 14, 2006
Reply by ●December 14, 20062006-12-14
tcharles wrote:> I use FFTW to perform DFT and I have problem execute the pointwise > multiplication, here is my code > > fftw_complex * fft::multiply(fftw_complex * A, fftw_complex * B) { > fftw_complex * R; > double scale = 1.0 / (nx * ny); > > R = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) *nx * ny); > for(int i= 0; i < nx; i++) > for(int j= 0; j < ny/2+1; j++){ > int ij = i*(ny/2+1) + j; > R[i][j].re = (A[ij].re * B[ij].re > - A[ij].im * B[ij].im) * scale; > R[i][j].im = (A[ij].re * B[ij].im > + A[ij].im * B[ij].re) * scale; > } > return(R); > } > > I receive such fault: > fft_l.C:118: request for member `re' in `*((((i * 2) + j) * 8) + R)', > which is > of non-aggregate type `double' > fft_l.C:118: request for member `re' in `*(A + (+(ij * 16)))', which is > of > non-aggregate type `double[2]' > fft_l.C:119: request for member `re' in `*(B + (+(ij * 16)))', which is > of > non-aggregate type `double[2]' > fft_l.C:119: request for member `im' in `*(A + (+(ij * 16)))', which is > of > non-aggregate type `double[2]' > pleased can you tell me what wrong with my code > ThanksThe problem is that the default FFTW interface has the following definition for the fftw_complex type: typedef double fftw_complex[2]; So, a fftw_complex is really just an array of two doubles, not a structure, so you can't treat it as if it has real and imaginary part members .re and .im. Use indices [0] and [1] instead. http://www.fftw.org/fftw3_doc/Complex-numbers.html Jason