Reputation: 161
I'm trying to do DFT for a real 2D matrix using FFTW3. this is my code snippet:
size_t nyh = ny/2 + 1;
out = (fftw_complex*)fftw_malloc ( sizeof ( fftw_complex ) * nx * nyh );
plan_forward = fftw_plan_dft_r2c_2d ( nx, ny, in, out, FFTW_ESTIMATE );
fftw_execute ( plan_forward );
where in
is a double*
each value is at order of e-270.
my problem is that out contains always -nan
values.
Is there any trick to get correct values?
Thank you
Upvotes: 0
Views: 1442
Reputation: 161
Thank everybody.
The problem which i was running in was not due to FFTW3 library and my code was correct despite of it's weakness.
My problem came from the input that i feed to fftw_plan_dft_r2c_2d
function which is issued from a cv::Mat
image. So, I post the error i did to help anyone getting this trouble:)
I convert cv::Mat
to a vector<vector<double> >
using this function:
static MatrixOfDouble _convertMat( cv::Mat& inMat)
{
MatrixOfDouble result;
for (int i = 0; i < inMat.rows; ++i)
{
std::vector<double> row;
for (int j = 0; j < inMat.cols; ++j)
{
row.push_back(inMat.at<double>(i, j));
}
result.push_back(row);
}
return result;
}
And Then i liniarize the returned matrix to feed the dft function.
But some of result matrix elements was NaN.
As a fix, i get cv::Mat element as long instead of double:
row.push_back(inMat.at<long>(i, j));
Good luck for everyone trying to solve this issue.
Upvotes: 1