FFTW生产的实际,而不是复杂的输出 [英] FFTW producing real instead of complex output

查看:100
本文介绍了FFTW生产的实际,而不是复杂的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code来执行复杂的数字数组(我必须变得复杂结果)复杂IFFT:

I'm using the following code to perform the COMPLEX IFFT of an array of complex numbers (I must get complex results):

#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)。
例如:

The problem is that I always get a real-valued transformed array (imaginary part = 0). For example:

    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

如何解决,因此要获得复数结果?

How can I fix it, so to get COMPLEX results?

推荐答案

碰巧你的输入信号有以下的属性

It happens that your input signal has the following property :

对应的频率的输入是彼此缀合物。
因此,它是一个真正的信号的FFT:无需担心你的输出是空的虚部。这是完全正常的。

Inputs of corresponding frequencies are conjugates from one another. Hence, it is the FFT of a real signal : no need to worry about the imaginary part of your output being null. It is perfectly normal.

更改一个输入文件和东西线应该改变。

Change one line of your input file and things should change.

这篇关于FFTW生产的实际,而不是复杂的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆