module Digiproc::FourierTransformable::GenericMethods

Inner module for places where standalone functions are needed, not associated with a class which contains `data`. See Digiproc::Functions for use

Public Instance Methods

fft(data) click to toggle source
fft(data [Array of complex Numerics]) => returns Array of data corresponding to the FFT

Note that for the Radix2Strategy, the only time the return size will equal the input size is if the input size is a power of 2. Otherwise the return will be increased to the closest power of 2.

Digiproc::Functions.fft([1,2,3,4,5,6,7,8]) # => [
# 36,
# (-4.0+9.65685424949238i),
# (-4.000000000000001+4.0i),
# (-4.000000000000002+1.6568542494923797i),
# -4,
# (-3.9999999999999996-1.6568542494923797i),
# (-3.999999999999999-4.0i),
# (-3.999999999999998-9.65685424949238i)]
# File lib/concerns/fourier_transformable.rb, line 38
def fft(data)
    fft_strategy.new(data.dup).calculate
end
fft_strategy() click to toggle source

Return a Fast Fourier Transform (FFT) strategy to be used for GenericMethods. Set to Digiproc::Strategies::Radix2Strategy It is important to note that the Radix2Strategy increases the size of the FFT return to the closest power of 2.

# File lib/concerns/fourier_transformable.rb, line 15
def fft_strategy
    Digiproc::Strategies::Radix2Strategy
end
ifft(data) click to toggle source
ifft(data [Array of complex Numerics])

Due to using the Radix2Strategy, the ifft will return the exact input if the input is a power of 2. Otherwise, there will be trailing 0s. ie:

ft = Digiproc::Functions.fft([1,2,3,4,5,6,7,8])
Digiproc::Functions.ifft(ft) # => [(1.0-0.0i),
 # (2.0000000000000004-2.718345674301793e-16i),
 # (3.0+4.440892098500626e-16i),
 # (4.0+3.8285686989269494e-16i),
 # (5.0-0.0i),
 # (6.0-4.978996250514798e-17i),
 # (7.0-4.440892098500626e-16i),
 # (8.0-6.123233995736767e-17i)]
ft = Digiproc::Functions.fft([1,2,3,4,5])
Digiproc::Functions.ifft(ft) # => [(1.0-0.0i),
 # (2.0+3.0616169978683836e-17i),
 # (3.0-3.3306690738754696e-16i),
 # (4.0+8.040613248383182e-17i),
 # (5.0-0.0i),
 # (0.0-1.9142843494634747e-16i),
 # (0.0+3.3306690738754696e-16i),
 # (0.0+8.040613248383182e-17i)]
# File lib/concerns/fourier_transformable.rb, line 64
def ifft(data)
    ifft_strategy.new(data.dup).calculate
end
ifft_strategy() click to toggle source

Return an Inverse Fast Fourier Transform (IFFT) strategy to be used for GenericMethods. Set to Digiproc::Strategies::IFFTConjugateStrategy

# File lib/concerns/fourier_transformable.rb, line 20
def ifft_strategy
    Digiproc::Strategies::IFFTConjugateStrategy
end