下面的代码似乎是正确的:
#include <Eigen/Core>
#include <unsupported/Eigen/FFT>
int main ()
{
Eigen::FFT<float> fft;
Eigen::Matrix<float, dim_x, dim_y> in = setMatrix();
Eigen::Matrix<complex<float>, dim_x, dim_y> out;
for (int k = 0; k < in.rows(); k++) {
Eigen::Matrix<complex<float>, dim_x, 1> tmpOut;
fft.fwd(tmpOut, in.row(k));
out.row(k) = tmpOut;
}
for (int k = 0; k < in.cols(); k++) {
Eigen::Matrix<complex<float>, 1, dim_y> tmpOut;
fft.fwd(tmpOut, out.col(k));
out.col(k) = tmpOut;
}
}
但是这必须在编译时指定矩阵的大小,当我把矩阵改成MatrixXd时,这在编译时有错误。我想知道如何在MatrixXd上进行FFT,这样我就可以在它运行时指定矩阵大小。
将所有变量更改为
#include <Eigen/Core>
#include <unsupported/Eigen/FFT>
int main ()
{
size_t dim_x = 28, dim_y = 126;
Eigen::FFT<float> fft;
Eigen::MatrixXf in = Eigen::MatrixXf::Random(dim_x, dim_y);
Eigen::MatrixXcf out;
out.setZero(dim_x, dim_y);
for (int k = 0; k < in.rows(); k++) {
Eigen::VectorXcf tmpOut(dim_x);
fft.fwd(tmpOut, in.row(k));
out.row(k) = tmpOut;
}
for (int k = 0; k < in.cols(); k++) {
Eigen::VectorXcf tmpOut(dim_y);
fft.fwd(tmpOut, out.col(k));
out.col(k) = tmpOut;
}
return 0;
}