The STL complex template is not used for Recursive Implementation of FFT in image compilation. The real and virtual parts are operated directly, and the results of the spectrum image are different from those of the opencv library, the FFT of the Lena image is like a rough cloth. The left side of the image is generated by opencv and the right side is generated by yourself.
The upper left corner shows that the upper left corner has a frequency band in the lower right corner. However, the lower right corner cannot be seen and an error occurs. It is normal to use the complex template for calculation. It should be because of an error in the complex number operation written by myself. I did not see it carefully. I wrote a few program tests and finally found the problem.
ProgramThere is a self-Multiplication operation w = W * wn. If the complex template is used, it is very simple, but it is ignored when I write the multiplication of the plural.
What?
Incorrect program:
W_r = w_r * wn_r-w_ I * wn_ I; w_ I = w_r * wn_ I + w_ I * wn_r;
The correct program:
T t_r = w_r; w_r = t_r * wn_r-w_ I * wn_ I; w_ I = t_r * wn_ I + w_ I * wn_r;
Now we can see at a glance that the original real part is used in the calculation of the virtual part during the self-Multiplication operation, and the wrong program uses the calculated real part...The original value should be saved for temporary storage, and the original value should be used for calculation. The following program calculates the real part first, so you only need to save the real part, if you calculate the virtual part first, it is obvious that it should be saved to the virtual part.
There is no need to worry about the addition and subtraction of the plural because the real imaginary part is not mixed. The division of the plural part also involves the coefficient Hybrid Operation of the real imaginary part. Therefore, you should also pay attention to the temporary storage of the original data during self-division.