项目需要fft2,在此记录比较的过程
值的比较
C++
arma::mat ar_mat = {
{
1, 2, 3 },{
5, 6, 7 } };
cout << ar_mat << "\n" << endl;
arma::cx_mat fft2_mat = fft2(ar_mat);
cout << fft2_mat << "\n" << endl;
a=[1,2,3;5,6,7]
fft2(a)
ans =
24.0000 + 0.0000i -3.0000 + 1.7321i -3.0000 - 1.7321i
-12.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
结果看是一致的,后面需要比较一下复数的fft2的结果
C++
arma::mat ar_mat = {
{
1, 2, 3 },{
5, 6, 7 } };
arma::mat ar_matk = {
{
11, 22, 33 },{
55, 65, 77 } };
arma::cx_mat hhhh = cx_mat(ar_mat, ar_matk);
arma::cx_mat fft2_mat = fft2(hhhh);
cout << fft2_mat << "\n" << endl;
Matlab++
a=[1,2,3;5,6,7]
b=[11, 22, 33;55, 65, 77 ]
c=complex(a,b)
fft2(c)
a =
1 2 3
5 6 7
b =
11 22 33
55 65 77
c =
1.0000 +11.0000i 2.0000 +22.0000i 3.0000 +33.0000i
5.0000 +55.0000i 6.0000 +65.0000i 7.0000 +77.0000i
ans =
1.0e+02 *
0.2400 + 2.6300i -0.2292 - 0.3077i 0.1692 - 0.3423i
-0.1200 - 1.3100i 0.0087 - 0.0050i -0.0087 - 0.0050i
结果一致,证明Armadilo的fft2和matlab的fft2可以等价转换
那么,ifft2可以等价吗?
arma::mat ar_mat = {
{
1, 2, 3 },{
5, 6, 7 } };
arma::mat ar_matk = {
{
11, 22, 33 },{
55, 65, 77 } };
arma::cx_mat hhhh = cx_mat(ar_mat, ar_matk);
cout << hhhh << "\n" << endl;
arma::cx_mat fft2_mat = ifft2(hhhh);
cout << fft2_mat << "\n" << endl;
matlab
a=[1,2,3;5,6,7]
b=[11, 22, 33;55, 65, 77 ]
c=complex(a,b)
ifft2(c)
a =
1 2 3
5 6 7
b =
11 22 33
55 65 77
c =
1.0000 +11.0000i 2.0000 +22.0000i 3.0000 +33.0000i
5.0000 +55.0000i 6.0000 +65.0000i 7.0000 +77.0000i
ans =
4.0000 +43.8333i 2.8198 - 5.7053i -3.8198 - 5.1280i
-2.0000 -21.8333i -0.1443 - 0.0833i 0.1443 - 0.0833i