我正在使用以下代码执行复数数组的COMPLEX IFFT(我必须得到复杂的结果):
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <complex.h>
#include <fftw3.h>
int main(void)
{
fftw_complex *in;
fftw_complex *out;
double re,im;
int size;
int i=0;
FILE *file;
fftw_plan ifft;
printf("Insert size");
if (scanf("%d", &size) != 1 || size < 1)
return 1;
in = fftw_malloc(sizeof(*in)*size);
out = fftw_malloc(sizeof(*out)*size);
file = fopen("numbers.txt", "r");
for (i = 0; i < size && fscanf(file, "%lf+%lf*I\n", &re, &im) == 2; i++)
{
in[i]= re+im*I;
}
fclose(file);
// Error if i != size?
ifft = fftw_plan_dft_1d(size, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
fftw_execute(ifft);
printf("Input: \tOutput:\n");
for(i=0; i<size; i++)
{
printf("%lf+%lf*I\t%lf+%lf*I\n", creal(in[i]), cimag(in[i]), creal(out[i]), cimag(out[i]));
}
fftw_destroy_plan(ifft);
fftw_free(in);
fftw_free(out);
//free(out);
return 0;
}
问题是我总是得到一个实值变换数组(虚部= 0)。 例如:
Input: Output:
0.000000+0.000000*I -3.018122+0.000000*I
0.734204+-1.072180*I -2.106427+0.000000*I
-0.055891+1.938470*I 0.808331+0.000000*I
1.117910+0.471070*I -0.171778+0.000000*I
-1.916920+1.203730*I -0.184422+0.000000*I
-0.114476+0.635334*I 3.623205+0.000000*I
-1.151660+0.278201*I 10.225375+0.000000*I
-0.712223+-0.880753*I 1.746433+0.000000*I
1.179990+0.000000*I -7.119782+0.000000*I
-0.712223+0.880753*I -8.238863+0.000000*I
-1.151660+-0.278201*I 2.578253+0.000000*I
-0.114476+-0.635334*I -6.742277+0.000000*I
-1.916920+-1.203730*I -0.293074+0.000000*I
1.117910+-0.471070*I -7.627715+0.000000*I
-0.055891+-1.938470*I 6.443361+0.000000*I
0.734204+1.072180*I 10.077501+0.000000*I
如何修复它,以获得COMPLEX结果?
答案 0 :(得分:1)