Created
June 14, 2014 13:02
-
-
Save Mon-Ouie/6af0ec554da0e9a84def to your computer and use it in GitHub Desktop.
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
def unnormalized_fft(x, start_i = 0, n = x.size, step = 1) | |
if n == 1 | |
Vector[x[start_i]] | |
else | |
even = unnormalized_fft(x, start_i, n/2, step * 2) | |
odd = unnormalized_fft(x, start_i + step, n/2, step * 2) | |
out = Array.new(n) | |
(n/2).times do |k| | |
out[k] = even[k] + Complex.polar(1, -2*Math::PI*k/n)*odd[k] | |
out[k + n/2] = even[k] - Complex.polar(1, -2*Math::PI*k/n)*odd[k] | |
end | |
Vector.elements out | |
end | |
end | |
def fft(x) | |
unnormalized_fft(x)/x.size | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment