Skip to content
/ ft Public
forked from slowjud/FFT

A Frequency Domain Transforms for Ruby written in C. Discreete and Fast Fourier Transform (DFT and FFT).

Notifications You must be signed in to change notification settings

placek/ft

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FT for Ruby

This gem contains a library written in C to perform:

  • Discrete Hartley Transform (DHT),

  • Fast Hartley Transform (FHT),

  • Discrete Fourier Transform (DFT),

  • Fast Fourier Transform (FFT).

The extension allows to do the transform in both directions. Moreover all the transforms are avaliable in one and two dimensions to process.

Instalation

To install the extension clone the repository on your machine:

git clone git://github.com/placek/ft.git

build a gem:

gem build ft.gemspec

and install it:

gem install ft-*.gem

Requirements

Data for Fourier transforms is a set of complex numbers. It need to be storaged in two seperate arrays of the same dimensions. First one will contain real parts of numbers, second one - imaginary parts. The length of data should be a power of 2 (otherwise FT methods will return nil).

Data for Hartley transforms is a set of real numbers. Here the only restriction is a length of array - it should be a multiplication of 2

Usage

Import the FT gem:

require 'ft'

Prepare some data to process:

data =   [[2.0, 1.0, 1.0, 2.0],   # real parts of data
          [0.0, 0.0, 0.0, 0.0]]   # imaginary parts of data

data2d = [[[1.0, 1.0, 1.0, 1.0],  # real parts
           [1.0, 2.0, 2.0, 1.0],  #
           [1.0, 2.0, 2.0, 1.0],  #
           [1.0, 1.0, 1.0, 1.0]], #
          [[0.0, 0.0, 0.0, 0.0],  # imaginary parts
           [0.0, 0.0, 0.0, 0.0],  #
           [0.0, 0.0, 0.0, 0.0],  #
           [0.0, 0.0, 0.0, 0.0]]] #

hdata =   [2.0, 1.0, 1.0, 2.0]    # data for DHT or FHT
hdata2d = [[1.0, 1.0, 1.0, 1.0],  # 2D data for DHT or FHT
           [1.0, 2.0, 2.0, 1.0],  #
           [1.0, 2.0, 2.0, 1.0],  #
           [1.0, 1.0, 1.0, 1.0]]  #

Make some data processing with FFT:

result = data.fft             # will return FFT
result.rfft                   # will return reverse FFT
result2d = data.fft2d         # will return FFT for 2D data
result2d.rfft2d               # will return reverse FFT for 2D data

And some data processing with DFT:

result = data.dft             # will return DFT
result.rdft                   # will return reverse DFT
result2d = data.dft2d         # will return DFT for 2D data
result2d.rdft2d               # will return reverse DFT for 2D data

Data processing with DHT or FHT:

result = hdata.dht
result = hdata.fht
result = hdata2d.dht2d
result = hdata2d.fht2d

Credits

  • Paweł Placzyński

  • Jude Sutton

About

A Frequency Domain Transforms for Ruby written in C. Discreete and Fast Fourier Transform (DFT and FFT).

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 50.1%
  • Ruby 49.9%