OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 31 May 2017 09:35:44 -0500dft functionhttp://answers.opencv.org/question/154673/dft-function/ I am using the dft function (tried with both real and complex input.... where imaginary part was set to zero).
The output of the dft is in a compressed format.
1) how do I convert this into the natural format?
2) is there a way to calculate the dft without this intermediate step?
3) If I use a real signal with a pure tone (e.g. sine wave), I get artifacts in the dft (instead of only that specific frequency, I get perturbations other frequencies also). Is this a known issue?
4) when I do the inverse dft (to get the original signal), the results typically have 2 orders of magnitude more noise than LabView (language similar to Matlab, with its own FFT algorithm), does OpenVC take shortcuts that include rounding of values?Wed, 31 May 2017 04:51:35 -0500http://answers.opencv.org/question/154673/dft-function/Answer by LBerger for <p>I am using the dft function (tried with both real and complex input.... where imaginary part was set to zero).
The output of the dft is in a compressed format.</p>
<p>1) how do I convert this into the natural format?</p>
<p>2) is there a way to calculate the dft without this intermediate step?</p>
<p>3) If I use a real signal with a pure tone (e.g. sine wave), I get artifacts in the dft (instead of only that specific frequency, I get perturbations other frequencies also). Is this a known issue?</p>
<p>4) when I do the inverse dft (to get the original signal), the results typically have 2 orders of magnitude more noise than LabView (language similar to Matlab, with its own FFT algorithm), does OpenVC take shortcuts that include rounding of values?</p>
http://answers.opencv.org/question/154673/dft-function/?answer=154884#post-id-154884Question 1 and 2 it is written [in doc](http://docs.opencv.org/master/d2/de8/group__core__array.html#gadd6cf9baf2b8b704a11b5f04aaf4f39d) :
> Re Y_{0,0} & Re Y_{0,1} & Im Y_{0,1} &
> Re Y_{0,2} & Im Y_{0,2} & \cdots & Re
> Y_{0,N/2-1} & Im Y_{0,N/2-1} & Re
> Y_{0,N/2}
If you don't want this flag use [DFT_COMPLEX_OUTPUT](http://docs.opencv.org/master/d2/de8/group__core__array.html#gaf4dde112b483b38175621befedda1f1c)
Mat sigX=(Mat_<double>(1,8)<<1,1,0,0,0,0,0,0),fftsigx;
dft(sigX, fftsigx);
cout << "flag=0 : " << fftsigx << "\n";
dft(sigX, fftsigx, DFT_COMPLEX_OUTPUT);
cout << "flag=DFT_COMPLEX_OUTPUT : " << fftsigx << "\n";
> flag=0 : [2, 1.707106781186547,
> -0.7071067811865475, 1, -1, 0.2928932188134524, -0.7071067811865475, 0]
> flag=DFT_COMPLEX_OUTPUT : [2, 0,
> 1.707106781186547, -0.7071067811865475, 1, -1, 0.2928932188134524, -0.7071067811865475, 0, 0, 0.2928932188134524, 0.7071067811865475, 1, 1, 1.707106781186547, 0.7071067811865475]
Question 3 it is well known issue but not in opencv : window effect.
Question 4 : I want to see your code but with this code no problem
dft(fftsigx, sigX, DFT_COMPLEX_OUTPUT+DFT_INVERSE+DFT_SCALE);
cout << "flag=DFT_COMPLEX_OUTPUT+INVERSE : " << sigX << "\n";
Wed, 31 May 2017 09:35:44 -0500http://answers.opencv.org/question/154673/dft-function/?answer=154884#post-id-154884