0

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.

1 Answer 1

1

For the flags the 'or' operator should be used, otherwise the second will be put in a wrong slot!

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

In this case the output will be complex!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.