Last active
December 14, 2015 07:58
-
-
Save mecab/5054317 to your computer and use it in GitHub Desktop.
DFT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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