Skip to content

tribusonz-2/rb_fft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

rb_fft

Ooura FFT front-end for Ruby

This is a Ruby's front end that allows to use FFT software of Professor Ooura (Kyoto University).

After downloading, unzip it to any directory, go to the lib directory, and type the following in the terminal to import it.

$ ruby extconf.rb
$ make
$ make install
$ make distclean

It is used as follows:

def sinewave(a, f0, n, fs)
  a * Math.sin(2.0 * Math::PI * f0 * n / fs)
end

a = 0.1
f0 = 500.0
fs = 8000

ary = Array.new(8){|n| sinewave(a, f0, n, fs)}
# => 
# [0.0,
#  0.03826834323650898,
#  0.07071067811865475,
#  0.09238795325112868,
#  0.1,
#  0.0923879532511287,
#  0.07071067811865477,
#  0.03826834323650899,
#  1.2246467991473533e-17,
#  -0.03826834323650893,
#  -0.07071067811865471,
#  -0.09238795325112865,
#  -0.1,
#  -0.0923879532511287,
#  -0.07071067811865477,
#  -0.038268343236509045]
fft = FFT.cdft(ary)
# => 
# [(8.163540703054581e-17+0.0i),
#  (-1.960250254624452e-16+0.8i),
#  (-7.379687742073657e-18+1.3976414209117932e-16i),
#  (4.663199920916804e-17+1.3877787807814457e-17i),
#  (-2.938689543196984e-17+8.326672684688674e-17i),
#  (4.663199920916804e-17+1.3877787807814457e-17i),
#  (3.187262372502072e-17+5.649741524429257e-17i),
#  (5.377515507821501e-17+0.0i),
#  (2.6124255799287986e-17+0.0i),
#  (5.377515507821501e-17+0.0i),
#  (3.187262372502072e-17-5.649741524429257e-17i),
#  (4.663199920916804e-17-1.3877787807814457e-17i),
#  (-2.938689543196984e-17-8.326672684688674e-17i),
#  (4.663199920916804e-17-1.3877787807814457e-17i),
#  (-7.379687742073657e-18-1.3976414209117932e-16i),
#  (-1.960250254624452e-16-0.8i)]
FFT.cdft(fft, inversion: true)
# => 
# [(1.232595164407831e-32+0.0i),
#  (0.6122934917841437+0.0i),
#  (1.131370849898476+0.0i),
#  (1.478207252018059+0.0i),
#  (1.6+0.0i),
#  (1.4782072520180591+0.0i),
#  (1.1313708498984765+0.0i),
#  (0.6122934917841438+0.0i),
#  (1.9594348786357647e-16+0.0i),
#  (-0.6122934917841428+0.0i),
#  (-1.1313708498984756+0.0i),
#  (-1.4782072520180585+0.0i),
#  (-1.6+0.0i),
#  (-1.4782072520180591+0.0i),
#  (-1.1313708498984765+0.0i),
#  (-0.6122934917841447+0.0i)]

About

Ooura FFT front-end for Ruby

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published