C 中的 FFTW2 例程问题
我目前正在使用 FFTW2(西方最快的傅里叶变换)库,在用 Fortran 编写成功的例程后,我将转向 C。但是,当我尝试输入时,我在数据分配方面遇到了一些麻烦要转换的数据(即 sin(x) 的值)。目前,我的代码是:
#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]);
}
}
我一直在使用此 http://fftw.org/fftw2_doc/ 链接文档/教程目的,目前我的错误是“a->a 的类型参数无效(具有 afftw_complexa)”,并且 -> 两侧的“a”字符和 fftw_complex 上面有克拉。我使用的模式与我在 Fortran 中编写此代码时的模式基本相同,而且我似乎正在遵循教程,实际上只是这里的这个作业,我搞乱了语法。根据记录,我使用的编译器是 nvcc,如果它有区别的话(我之前尝试过 gcc)。如果这里有人以前用过 C 中的 FFTW2,你能帮助纠正我的错误吗?谢谢你!
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 assigning 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是因为你的数组“in”是 fftw_complex 的数组,所以不要使用 in[0]->re = 0 你应该使用它作为 in[0].re = 0 。除非 fftw_complex 再次被类型定义为一些数组。
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.
由于 ffwt_complex 是 double[2],第一维 ([0]) 代表真实数据,第二维 ([1]) 代表虚数数据,因此安全的解决方案是:
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: