Project

ooura_fft

0.0
The project is in a healthy, maintained state
Front-end of OouraFFT for Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

ooura_fft (Ruby gem)

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

Installation

The software is included in this library. Professor Ooura does not have an installer.

Install the gem and add to the application's Gemfile by executing:

bundle add ooura_fft

If bundler is not being used to manage dependencies, install the gem by executing:

gem install ooura_fft

Usage

Now, there are a total of 6 FFT routines, which are as follows:

    cdft: Complex Discrete Fourier Transform
    rdft: Real Discrete Fourier Transform
    ddct: Discrete Cosine Transform
    ddst: Discrete Sine Transform
    dfct: Cosine Transform of RDFT (Real Symmetric DFT)
    dfst: Sine Transform of RDFT (Real Anti-symmetric DFT)

These routines are owned by the OouraFFT module.

Since the software's using is a discrete type, the ABI makes use of arrays.
In Ruby, it is communicated with the Array class. The Array class is used as an argument, and the FFT computed Array class is the return value.

The design is unified as follows:

    OouraFFT.xxxx(*nusec, inversion: bool)

This *nusec is the Array class. Internally, it is treated as a numeric sequence.
It also supports inverse FFT, and works by applying true to the keyword argument inversion. The default value is false.

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

    OouraFFT.ddct(Array.new(8){|n| sinewave(0.25, 250.0, 8000, n)})
    #=> [0.6284174365157309,
    #=> -0.6284174365157309,
    #=>  0.18707572033318604,
    #=> -0.18707572033318612,
    #=>  0.08352232973991239,
    #=> -0.08352232973991236,
    #=>  0.02486404592245728,
    #=> -0.024864045922457167]

    OouraFFT.ddst(Array.new(8){|n| sinewave(0.25, 250.0, 8000, n)})
    #=> [0.875,
    #=>  0.12500000000000003,
    #=> -0.12499999999999997,
    #=>  0.125,
    #=> -0.125,
    #=>  0.12500000000000006,
    #=> -0.12499999999999994,
    #=>  0.12499999999999994]

For more information on how to the fourier transform, please refer to the technical book.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tribusonz-2/ooura_fft. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the OouraFft project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Provided as a C API

In the future, we plan to provide APIs for gems that are written in C.
In the case of OouraFFT, it is as follows:

RUBY_EXT_EXTERN VALUE rb_mOouraFFT;

VALUE rb_oourafft_cdft(VALUE, int);
VALUE rb_oourafft_rdft(VALUE, int);
VALUE rb_oourafft_ddct(VALUE, int);
VALUE rb_oourafft_ddst(VALUE, int);
VALUE rb_oourafft_dfct(VALUE, int);
VALUE rb_oourafft_dfst(VALUE, int);

When install a gem, a directory is created in the installation location along with the .so file. Here is the header file in C.
In general, there is globals.h which declares the object variables that are entities, and api.h which declares the API functions that can be used in C. There is also a header called ext_extern.h. This is to let the C side know that object variables are treated as global variables at the C level.
To invoke them, include:

#include <ooura_fft/globals.h>
#include <ooura_fft/api.h>