【发布时间】:2018-05-02 11:10:53
【问题描述】:
我正在尝试对一些真实数据进行二维傅里叶变换。 我正在使用 FFTW 库来执行此操作,因为它比犰狳的库要快得多。
给定一个简单的 (4x4) 起始矩阵: AAA:
0 0 0 0
0 1.0000 2.0000 3.0000
0 2.0000 4.0000 6.0000
0 3.0000 6.0000 9.0000
`
如果我在犰狳中使用内置的 FFT,输出如下所示:
BBB:
(+3.600e+01,+0.000e+00) (-1.200e+01,+1.200e+01) (-1.200e+01,+0.000e+00) (-1.200e+01,-1.200e+01)
(-1.200e+01,+1.200e+01) (+0.000e+00,-8.000e+00) (+4.000e+00,-4.000e+00) (+8.000e+00,+0.000e+00)
(-1.200e+01,+0.000e+00) (+4.000e+00,-4.000e+00) (+4.000e+00,+0.000e+00) (+4.000e+00,+4.000e+00)
(-1.200e+01,-1.200e+01) (+8.000e+00,+0.000e+00) (+4.000e+00,+4.000e+00) (+0.000e+00,+8.000e+00)
但如果我使用 FFTW,我会得到:
CCC:
(+3.600e+01,+0.000e+00) (+0.000e+00,-8.000e+00) (+4.000e+00,+0.000e+00) (0,0)
(-1.200e+01,+1.200e+01) (+4.000e+00,-4.000e+00) (-1.200e+01,-1.200e+01) (0,0)
(-1.200e+01,+0.000e+00) (-1.200e+01,+0.000e+00) (+8.000e+00,+0.000e+00) (0,0)
(-1.200e+01,+1.200e+01) (+4.000e+00,-4.000e+00) (+4.000e+00,+4.000e+00) (0,0
对矩阵 BBB 和 CCC 执行各自的 IFFT 可以准确地得到起始矩阵 AAA。
根据文档:(http://www.fftw.org/fftw3_doc/One_002dDimensional-DFTs-of-Real-Data.html#One_002dDimensional-DFTs-of-Real-Data): “在许多实际应用中,输入数据 in[i] 是纯实数,在这种情况下,DFT 输出满足“厄米”冗余:out[i] 是 out[n-i] 的共轭。可以利用这些情况,在速度和内存使用方面实现大约两倍的改进。”
因此,矩阵 CCC 需要某种操作来检索 Hermetian 冗余,但我在数学上太菜鸟了,无法理解该操作是什么。 谁能帮我解决这个问题?
此外,犰狳以 col 主要格式存储数据,FFTW 以行主要格式存储,根据文档,只要您以相反的顺序将行/列维度传递给计划函数,这并不重要?
感谢收看。
附上我的代码:
#include <iostream>
#include <fftw3.h>
#include "armadillo"
using namespace arma;
using namespace std;
int main(int argc, char** argv)
{
mat AAA=zeros(4,4);
mat IBB=zeros(4,4);
cx_mat BBB(4,4);
for (int xx=0;xx<=3;xx++){
for ( int yy=0;yy<=3;yy++){
AAA(xx,yy)= xx*yy;
}
}
cx_mat CCC (4,4);
cx_mat CCCC(4,4);
mat ICC =zeros(4,4);
fftw_plan plan=fftw_plan_dft_r2c_2d(4, 4,(double(*))&AAA(0,0), (double(*)[2])&CCC(0,0), FFTW_ESTIMATE);
fftw_plan plan2=fftw_plan_dft_c2r_2d(4, 4,(double(*)[2])&CCCC(0,0), (double(*))&ICC(0,0), FFTW_ESTIMATE);
//Perform Armadillo FFT (Correct output)
BBB=fft2(AAA);
//Perform armadillo IFFT
IBB=real(ifft2(BBB));
//Perform FFTW- FFT
fftw_execute(plan);
//Allocate fourier array to another array as imput array is destroyed
CCCC=CCC;
//Perform FFTW- IFFT on newly allocated array
fftw_execute(plan2);
//Must re-normalise the array by the number of elements
ICC=ICC/(4*4);
//myst rescale by the number of elements in the array
BBB.print("BBB:");
CCC.print("CCC:");
IBB.print("IBB:");
ICC.print("ICC:");
return 0;
}
`
【问题讨论】:
-
请看sourceforge.net/projects/sigpack,它已经有你要找的功能了。 FFTW 代码在sourceforge.net/p/sigpack/code/ci/master/tree/fftw/fftw.h 中实现
-
这根本不是他所希望的答案。你真的看过这篇文章吗?
标签: 2d armadillo fftw symmetry