Skip to content

Instantly share code, notes, and snippets.

@Sophia-Gold
Last active January 13, 2018 08:33
Show Gist options
  • Select an option

  • Save Sophia-Gold/d66a8e42f34e28e970ebf712c02fa733 to your computer and use it in GitHub Desktop.

Select an option

Save Sophia-Gold/d66a8e42f34e28e970ebf712c02fa733 to your computer and use it in GitHub Desktop.
Discrete Fourier Transform
(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