I am trying to re-implement one of the matlab toolboxes. they use fft over there. when i perform same operation on the same data i get different results to those from matlab. Just take a look:
MATLAB:
Msig =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
fft(Msig.')
Columns 1 through 4
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
Columns 5 through 6
1.0000 0
0 - 1.0000i 0
-1.0000 0
0 + 1.0000i 0
PYTHON:
Msig=
array([[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 1., 0., 0.],
[ 0., 0., 0., 0.]])
np.fft.fft(Msig.transpose())
array([[ 0.0 +0.00000000e+00j, 0.0 +0.00000000e+00j,
0.0 +0.00000000e+00j, 0.0 +0.00000000e+00j,
0.0 +0.00000000e+00j, 0.0 +0.00000000e+00j],
[ 1.0 +0.00000000e+00j, -0.5 +8.66025404e-01j,
-0.5 -8.66025404e-01j, 1.0 -3.88578059e-16j,
-0.5 +8.66025404e-01j, -0.5 -8.66025404e-01j],
[ 0.0 +0.00000000e+00j, 0.0 +0.00000000e+00j,
0.0 +0.00000000e+00j, 0.0 +0.00000000e+00j,
0.0 +0.00000000e+00j, 0.0 +0.00000000e+00j],
[ 0.0 +0.00000000e+00j, 0.0 +0.00000000e+00j,
0.0 +0.00000000e+00j, 0.0 +0.00000000e+00j,
0.0 +0.00000000e+00j, 0.0 +0.00000000e+00j]])
The best i can get if i mess with parameters(axis etc.) of np.fft.fft()/np.fft.fft2()/np.fft.fftn() is same values but shifted. unfortunately manual shifting is not an option cause the size and shape of the Msig matrix varies depending on input parameters.
you have any clue how to solve this problem, what can be the cause?
Matlab applies the fft over the columns of the matrix, numpy applies the fft over the last axis (the rows) by default. You want:
>>> np.fft.fft(Msig.T, axis=0)
array([[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.-1.j, 0.+0.j],
[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, -1.+0.j, 0.+0.j],
[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+1.j, 0.+0.j]])
or
>>> np.fft.fft(Msig).T
array([[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.-1.j, 0.+0.j],
[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, -1.+0.j, 0.+0.j],
[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+1.j, 0.+0.j]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With