Module: Digiproc::FourierTransformable::GenericMethods

Included in:
Digiproc::Functions
Defined in:
lib/concerns/fourier_transformable.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#fft(data) ⇒ Object

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() # => [ # 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)]



38
39
40
# File 'lib/concerns/fourier_transformable.rb', line 38

def fft(data)
    fft_strategy.new(data.dup).calculate
end

#fft_strategyObject

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.



15
16
17
# File 'lib/concerns/fourier_transformable.rb', line 15

def fft_strategy
    Digiproc::Strategies::Radix2Strategy
end

#ifft(data) ⇒ Object

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() 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() 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)]


64
65
66
# File 'lib/concerns/fourier_transformable.rb', line 64

def ifft(data)
    ifft_strategy.new(data.dup).calculate
end

#ifft_strategyObject

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



20
21
22
# File 'lib/concerns/fourier_transformable.rb', line 20

def ifft_strategy
    Digiproc::Strategies::IFFTConjugateStrategy
end