Skip to content

Instantly share code, notes, and snippets.

@mecab
Last active December 14, 2015 07:58
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 mecab/5054317 to your computer and use it in GitHub Desktop.
Save mecab/5054317 to your computer and use it in GitHub Desktop.
DFT
import cmath
I = 1j
data = [ cmath.sin(cmath.pi * 2 * x / 16.0) + 1 for x in xrange(16)]
def dft_gen(data):
return (_sum_xk(data, j) for j in xrange(len(data)))
def _sum_xk(data, j):
return sum(xk * cmath.exp(-2 * cmath.pi * I * j * k / len(data))
for k, xk in enumerate(data))
for x in dft_gen(data):
print abs(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment