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;
}
The first two parameters to
fftwnd_create_planlook 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: