Skip to content

Instantly share code, notes, and snippets.

@mikezink

mikezink/DFT.py Secret

Created November 4, 2019 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikezink/290f7eeceeca3b80699667b24034917f to your computer and use it in GitHub Desktop.
Save mikezink/290f7eeceeca3b80699667b24034917f to your computer and use it in GitHub Desktop.
import numpy as np
from timeit import Timer
pi2 = np.pi * 2
def DFT(x):
N = len(x)
FmList = []
for m in range(N):
Fm = 0.0
for n in range(N):
Fm += x[n] * np.exp(- 1j * pi2 * m * n / N)
FmList.append(Fm / N)
return FmList
N = 1000
x = np.arange(N)
t = Timer(lambda: DFT(x))
print('Elapsed time: {} s'.format(str(t.timeit(number=1))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment