From 9000c4b21d9af6c5116881e69612ff43846f1372 Mon Sep 17 00:00:00 2001 From: Gathros <6323830+Gathros@users.noreply.github.com> Date: Sat, 15 Sep 2018 18:39:15 +0100 Subject: [PATCH 1/3] Adding dft to python --- contents/cooley_tukey/code/python/fft.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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))) From 8a4eed07aee9d9924f44327026296a00019819e5 Mon Sep 17 00:00:00 2001 From: Gathros <6323830+Gathros@users.noreply.github.com> Date: Sat, 15 Sep 2018 18:42:15 +0100 Subject: [PATCH 2/3] updating cooley_tukey.md --- contents/cooley_tukey/cooley_tukey.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contents/cooley_tukey/cooley_tukey.md b/contents/cooley_tukey/cooley_tukey.md index e414e8c16..945c52423 100644 --- a/contents/cooley_tukey/cooley_tukey.md +++ b/contents/cooley_tukey/cooley_tukey.md @@ -78,7 +78,7 @@ For some reason, though, putting code to this transformation really helped me fi {% 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 %} @@ -123,7 +123,7 @@ In the end, the code looks like: {% 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 %} From b860b780c695bdc5c8706342a76fbd287ef62b8b Mon Sep 17 00:00:00 2001 From: Gathros <6323830+Gathros@users.noreply.github.com> Date: Sat, 15 Sep 2018 18:46:09 +0100 Subject: [PATCH 3/3] adding code examples for cooley tukey --- contents/cooley_tukey/cooley_tukey.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contents/cooley_tukey/cooley_tukey.md b/contents/cooley_tukey/cooley_tukey.md index 945c52423..1bacbf5d9 100644 --- a/contents/cooley_tukey/cooley_tukey.md +++ b/contents/cooley_tukey/cooley_tukey.md @@ -74,7 +74,7 @@ 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" %} @@ -119,7 +119,7 @@ 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" %}