In [1]:
import numpy as np
def dftmatrix(N):
x = np.arange(N).reshape(N,1)
u = x
Wn = np.exp(-1j*2*np.pi/N)
A = (1./np.sqrt(N)) * (Wn ** u.dot(x.T))
return A
In [1]:
testing = (__name__ == "__main__")
if testing:
! jupyter nbconvert --to python dftmatrix.ipynb
import numpy as np
import sys,os
import matplotlib.image as mpimg
ia898path = os.path.abspath('../../')
if ia898path not in sys.path:
sys.path.append(ia898path)
import ia898.src as ia
In [2]:
if testing:
A = ia.dftmatrix(128)
ia.adshow(ia.normalize(A.real),'A.real')
ia.adshow(ia.normalize(A.imag),'A.imag')
In [3]:
if testing:
A = ia.dftmatrix(4)
print('A=\n', A.round(1))
print('A-A.T=\n', A - A.T)
print((np.abs(np.linalg.inv(A)-np.conjugate(A))).max() < 10E-15)
In [4]:
if testing:
u = x = np.arange(10).reshape(10,1)
print('u xT=\n', u.dot(x.T))
In [6]:
if testing:
print('testing dftmatrix')
print(repr(np.floor(0.5 + 10E4*ia.dftmatrix(4).real) / 10E4) == repr(np.array(
[[ 0.5, 0.5, 0.5, 0.5],
[ 0.5, 0. , -0.5, 0. ],
[ 0.5, -0.5, 0.5, -0.5],
[ 0.5, 0. , -0.5, 0. ]])))
print(repr(np.floor(0.5 + 10E4*ia.dftmatrix(4).imag) / 10E4) == repr(np.array(
[[ 0. , 0. , 0. , 0. ],
[ 0. , -0.5, 0. , 0.5],
[ 0. , 0. , 0. , 0. ],
[ 0. , 0.5, 0. , -0.5]])))
In [ ]: