C++ 用FFTW连接犰狳
我正在尝试在犰狳包的矩阵中使用FFTW。我需要在2D矩阵上执行N个独立的FFT。根据FFTW手册和其他在线资源,我有以下代码:C++ 用FFTW连接犰狳,c++,fftw,armadillo,C++,Fftw,Armadillo,我正在尝试在犰狳包的矩阵中使用FFTW。我需要在2D矩阵上执行N个独立的FFT。根据FFTW手册和其他在线资源,我有以下代码: #include <armadillo> #include <iostream> #include "fftw3.h" using namespace std; using namespace arma; fftw_plan fplan; int main(int argc, char *argv[]) { cx_mat psi;
#include <armadillo>
#include <iostream>
#include "fftw3.h"
using namespace std;
using namespace arma;
fftw_plan fplan;
int main(int argc, char *argv[])
{
cx_mat psi;
int NCOL=2, NROW=4;
int frank=1;
int howmany=NCOL;
int n[]={NROW};
int idist=NROW, odist=NROW;
int istride=1, ostride=1;
int *inembed=n, *onembed=n;
psi.resize(NROW, NCOL);
psi(0,0)=cx_double(1,1); psi(0,1)=cx_double(1,1);
psi(1,0)=cx_double(2,1); psi(1,1)=cx_double(1,2);
psi(2,0)=cx_double(3,1); psi(2,1)=cx_double(1,3);
psi(3,0)=cx_double(4,1); psi(3,1)=cx_double(1,4);
cout << psi << endl; // the output is correct at here
fftw_complex* in = reinterpret_cast<fftw_complex*>(psi.memptr());
fplan = fftw_plan_many_dft(frank, n, howmany,
in, inembed, istride, idist,
in, onembed, ostride, odist,
FFTW_FORWARD, FFTW_MEASURE);
cout << endl << "after fftw plan: " << endl << psi << endl; // all zeros
// fftw_execute(fplan); // output zeros again if execute
cx_double* A_mem=psi.memptr();
cout << endl << "by reference: " << endl << *A_mem << " " << *(A_mem+1) << endl;
return 0;
}
#包括
#包括
#包括“fftw3.h”
使用名称空间std;
使用arma;
fftw_计划fplan;
int main(int argc,char*argv[])
{
cx_mat psi;
int NCOL=2,NROW=4;
int-frank=1;
int多少=NCOL;
int n[]={NROW};
int idist=NROW,odist=NROW;
int-istride=1,ostride=1;
int*inembed=n,*onembed=n;
psi.调整大小(NROW,NCOL);
psi(0,0)=cx_-double(1,1);psi(0,1)=cx_-double(1,1);
psi(1,0)=cx_-double(2,1);psi(1,1)=cx_-double(1,2);
psi(2,0)=cx_-double(3,1);psi(2,1)=cx_-double(1,3);
psi(3,0)=cx_-double(4,1);psi(3,1)=cx_-double(1,4);
cout使用FFTW\u MEASURE
标志,缓冲区实际上用于调整FFT算法。您应该首先创建计划,然后初始化输入数据
请注意,FFTW\u ESTIMATE
没有显示此行为,因此您也可以在当前代码中更改此标志来解决问题,但这样您的代码可能会运行较慢。使用FFTW\u MEASURE
标志,缓冲区实际上用于调整FFT算法。您应该首先创建计划,然后创建ini调整输入数据
请注意,FFTW\u ESTIMATE
不显示此行为,因此您也可以在当前代码中更改此标志以解决问题,但这样您的代码可能会运行得较慢。使用FFTW\u MEASURE
标志,缓冲区实际上用于调整FFT算法。您应该首先创建计划,然后初始化lise the input data.oh.这就解决了问题。谢谢。没问题-现在将注释转换为答案,以方便将来有类似问题的读者。使用FFTW_MEASURE
标志,缓冲区实际上用于调整FFT算法。您应该先创建计划,然后初始化输入数据。oh.这就解决了问题问题。谢谢。没问题-现在就把评论转换成答案,以方便将来有类似问题的读者。