Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV Fourier Transform complex output issue

I try to do some Fourier analysis, but in the OpenCV cv::dft function the cv::DFT_COMPLEX_OUTPUT seems not working. I do the following:

// Calculate Fourier transform for each time signal
cv::Mat hf, hf_raw, h, h_raw;
cv::Mat Fp(Pt.size[0], Pt.size[1], CV_64FC2);
cv::Mat Fz(Pt.size[0], Pt.size[1], CV_64FC2);

cv::dft(Pt.t(), Fp, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT);
cv::dft(Zt.t(), Fz, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT);



// [DEBUG]
// Fp and Fz has to be (K*4 x WINDOW_LENGTH) size in the current case (24 x 256)
std::cout << "Fp.size: " << Fp.size << std::endl;
// -> OK
// Fp elements should be complx
std::cout << "Fp.type(): " << Fp.type() << std::endl;
// -> Lots of zero at the end!!! -> With cv::DFT_REAL_OUTPUT there are no zeros



cv::Mat nom, denom, W;
cv::mulSpectrums(Fp, Fp, nom, cv::DFT_ROWS, true);
cv::mulSpectrums(Fz, Fz, denom, cv::DFT_ROWS, true);

I declare Fp and Fz to be two channeled in order to hold the real and complex values (on which the cv::mulSpectrums function can operate). But Fp.type() results in 6 which means the type of the output matrix is CV_64FC1.