FFTW Segfault(可能很简单的答案)
我正在尝试编写一个简单的 FFTW 例程(版本 2),我想我已经基本了解了,但是当我调用 fftwnd_one 函数时,我遇到了持久的段错误(我正在做一个维变换,但为了模块化,我使用 n 维代码)。然而,我认为我的问题在于计划的制定;谁能提供一些关于这段代码有什么问题的见解?如果可以的话,我将不胜感激 - 谢谢!
作为参考,我在这里使用的函数是 sin(x)。我意识到并不是所有的数学运算都已实现,我只是想让 FFTW2 库首先工作,然后我可以使数据变得有用。
#include <stdio.h>
#include <fftw.h>
#include <math.h>
#include <complex.h>
int main(){
int i;
fftw_complex in[8];
fftwnd_plan p;
const int *n;
int temp = (int)pow(2, 2)*pow(3,2)*pow(5,1)*pow(7,1)*pow(11,1)*pow(13,0);
n = &temp;
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]);
}
return 0;
}
I'm trying to write a simple FFTW routine (version 2), and I think I've just about got the bones down, but I'm running into a persistent segfault when I call the fftwnd_one function (I'm doing a one dimensional transform, but I'm using the n-dimensional code for modularity's sake). However, I believe my problem to be in the plan creation; could anyone offer some insight as to what's wrong with this code? I'd greatly appreciate it if so - thank you!
For reference, the function that I'm working with here is sin(x). I realize that not all of the mathematical operations have been implemented, I'm just trying to get the FFTW2 library working first, then I can make the data useful.
#include <stdio.h>
#include <fftw.h>
#include <math.h>
#include <complex.h>
int main(){
int i;
fftw_complex in[8];
fftwnd_plan p;
const int *n;
int temp = (int)pow(2, 2)*pow(3,2)*pow(5,1)*pow(7,1)*pow(11,1)*pow(13,0);
n = &temp;
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]);
}
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
fftwnd_create_plan
的前两个参数看起来完全错误。看来您只想创建一个大小为 8 的 1D FFT 计划(这提出了一个问题:如果您只需要 1D FFT ,为什么要使用 fftwnd_create_plan ?)。调用应该类似于:The first two parameters to
fftwnd_create_plan
look completely wrong. It seems you just want to create a plan for 1D FFT with size 8 (which raises the question as to why you're using fftwnd_create_plan if you only need a 1D FFT ?). The call should be something like:当 n 只指向一个整数时,您似乎将 n 视为一个数组。例如,不应该是
:
You seem to be treating n as an array, when it only points to a single integer. For example, should not this:
be: