Created
November 16, 2009 20:55
-
-
Save corbanbrook/236306 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
# is a discrete fourier transform in ruby by corban http://en.wikipedia.org/wiki/Discrete_Fourier_transform | |
require 'complex' | |
TWO_PI = 2 * Math::PI | |
N = ARGV.first.to_i || 256 | |
x = Array.new(N, rand) | |
X = Array.new(N, 0) | |
X.each_index do |k| | |
x.each_index do |n| | |
X[k] += x[n] * Math::E ** -((Complex(0, TWO_PI) / N) * k * n) | |
end | |
end | |
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
zetagun:~ corban$ time ruby DFT.rb 1024 | |
real 1m4.676s | |
user 1m3.956s | |
sys 0m0.195s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment