Last active
January 13, 2018 08:33
-
-
Save Sophia-Gold/d66a8e42f34e28e970ebf712c02fa733 to your computer and use it in GitHub Desktop.
Discrete Fourier Transform
This file contains hidden or 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
| (ns dft.core) | |
| (defn fft [x] | |
| (let [length (count x)] | |
| (if (<= length 1) | |
| (->> x | |
| (persistent!) | |
| (vec)) | |
| (let [x (transient x) | |
| even (recur (map #(nth % x) (range length))) | |
| odd (recur (map #(nth % x) (range 1 length))) | |
| aux (map #(* (Math/exp (/ (* (complex 0 -2) Math/pi %) length)) | |
| (nth % odd)) | |
| (range (quot length 2)))] | |
| (recur (concat (map + even aux) | |
| (map - even aux))))))) | |
| (map #(format "~a~&" %) | |
| (fft [1 1 1 1 0 0 0 0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment