DFT
#Discrete Fourier Transform
from pylab import *
def dft(h):
N=len(h)
w=2*pi/N
H=[]
for n in xrange(N):
s=0
for k in xrange(N):
s+=h[k]*exp(w*k*n*1j)
H.append(s)
return H
hk=[1,2,3,4]
print dft(hk)
Output Screen
[(10+0j), (-2.0000000000000004-1.9999999999999996j), (-2+9.7971743931788257e-16j), (-1.9999999999999982+2.0000000000000009j)]
from pylab import *
def dft(h):
N=len(h)
w=2*pi/N
H=[]
for n in xrange(N):
s=0
for k in xrange(N):
s+=h[k]*exp(w*k*n*1j)
H.append(s)
return H
hk=[1,2,3,4]
print dft(hk)
Output Screen
[(10+0j), (-2.0000000000000004-1.9999999999999996j), (-2+9.7971743931788257e-16j), (-1.9999999999999982+2.0000000000000009j)]
Comments
Post a Comment