2D复数FFT实现

时间:2015-04-24 19:06:45

标签: c multidimensional-array fft fftw

我使用Dev-C ++在C中工作

我已经创建了一个复数的二维数组:

#include<complex.h>

double complex **x;

x = malloc(Nx * sizeof *X);

if (x)
{
for (i = 0; i < Nx; i++) 
{
x[i] = malloc(Nx * sizeof *x[i]);

}   

并用数据填充,我已经用真实和虚构的部分绘制了经验证和正确的部分。

我只是想对这些数据执行FFT(希望只有一个函数只接受数组,它的尺寸和fft方向),它将转换数组并且还能够执行反转。

我看过像FFTW这样的图书馆,但尽管我努力理解,但实施仍然让我难以理解。

有人可以解释一下我这样做的最佳方式吗?感谢

2 个答案:

答案 0 :(得分:2)

Starting from the beginning, you need to get the FFTW library for your system. Depending on what you are running the code on you may have to make it from the source code as shown here:

http://www.fftw.org/fftw3_doc/Installation-and-Customization.html

The configure, make, make install process could take quite a while.

Once this is complete you will need to include the library in your code using

rails console

This may change depending on which version you are using. To compile the code, you will need to link the library using -lfftw3.

Now to actually include the FFT code . This can be broken down into about three steps: Plan, fill the input array, and execute.

The planning stage for a 2d complex FFT can be shown here: http://www.fftw.org/fftw3_doc/Complex-Multi_002dDimensional-DFTs.html#Complex-Multi_002dDimensional-DFTs You only need to plan once, unless the dimensions of the FFT change.

The second stage requires that you use the provided FFTW arrays. A helpful link for formatting the arrays is shown in the previous link.

And the third stage is as simple as calling the "fftw_execute" routine. Once this is called the output array will be filled with the output of the FFT.

答案 1 :(得分:0)

我最终通过制作单独的实数和虚数2D数组来解决这个问题。然后编写函数以接收数组,创建双倍长度1D数组,其中交替的实数和虚数值表示行和列。这使我能够使用简单的代码内FFT four1函数(在C中的数字配方中给出),通过对每一行和每列连续执行变换。

这可以完成没有图书馆的工作!

请记住在每次转换后都要包括标准化。