diff --git a/contents/cooley_tukey/code/python/fft.py b/contents/cooley_tukey/code/python/fft.py index 2f3646639..e7206e35f 100644 --- a/contents/cooley_tukey/code/python/fft.py +++ b/contents/cooley_tukey/code/python/fft.py @@ -2,6 +2,14 @@ from cmath import exp, pi from math import log2 +def dft(X): + N = len(X) + temp = [0]*N + for i in range(N): + for k in range(N): + temp[i] += X[k] * exp(-2.0j*pi*i*k/N) + return temp + def cooley_tukey(X): N = len(X) if N <= 1: @@ -47,5 +55,7 @@ def iterative_cooley_tukey(X): Y = cooley_tukey(X) Z = iterative_cooley_tukey(X) +T = dft(X) print(all(abs([Y[i] - Z[i] for i in range(64)][j]) < 1 for j in range(64))) +print(all(abs([Y[i] - T[i] for i in range(64)][j]) < 1 for j in range(64))) diff --git a/contents/cooley_tukey/cooley_tukey.md b/contents/cooley_tukey/cooley_tukey.md index e414e8c16..1bacbf5d9 100644 --- a/contents/cooley_tukey/cooley_tukey.md +++ b/contents/cooley_tukey/cooley_tukey.md @@ -74,11 +74,11 @@ For some reason, though, putting code to this transformation really helped me fi {% sample lang="c" %} [import:8-19, lang:"c_cpp"](code/c/fft.c) {% sample lang="cpp" %} -[import:2-11, lang:"julia"](code/julia/fft.jl) +[import:23-33, lang:"c_cpp"](code/c++/fft.cpp) {% sample lang="hs" %} [import:2-11, lang:"julia"](code/julia/fft.jl) {% sample lang="py" %} -[import:2-11, lang:"julia"](code/julia/fft.jl) +[import:5-11, lang:"python"](code/python/fft.py) {% sample lang="scratch" %} [import:2-11, lang:"julia"](code/julia/fft.jl) {% endmethod %} @@ -119,11 +119,11 @@ In the end, the code looks like: {% sample lang="c" %} [import:20-39, lang:"c_cpp"](code/c/fft.c) {% sample lang="cpp" %} -[import:35-66, lang:"c_cpp"](code/c++/fft.cpp) +[import:36-66, lang:"c_cpp"](code/c++/fft.cpp) {% sample lang="hs" %} [import:6-19, lang:"haskell"](code/haskell/fft.hs) {% sample lang="py" %} -[import:5-16, lang:"python"](code/python/fft.py) +[import:13-24, lang:"python"](code/python/fft.py) {% sample lang="scratch" %} [import:14-31, lang:"julia"](code/julia/fft.jl) {% endmethod %}