class Digiproc::Strategies::IFFTConjugateStrategy

Strategy for calculating the Inverse Fast Fourier Transform (IFFT) O(nlgn) runtime, depends on the FFT strategy to calculate thie IFFT Uses “conjugate strategy”

Attributes

data[RW]
strategy[RW]

Public Class Methods

new(data, fft_strategy = Digiproc::Strategies::Radix2Strategy) click to toggle source

Input args:

data

Array (DFT values)

fft_strategy(Optional)

See Digiproc::Strategies::Radix2Strategy for required protocol (This is the default value)

# File lib/strategies/fft/inverse_fft_conjugate_strategy.rb, line 13
def initialize(data, fft_strategy = Digiproc::Strategies::Radix2Strategy)
    @data = data
    @strategy = fft_strategy.new
end

Public Instance Methods

calculate() click to toggle source

No input args Calculate the IFFT given Discrete Fourier Transform (DFT) values

# File lib/strategies/fft/inverse_fft_conjugate_strategy.rb, line 21
def calculate
    strategy.data = conjugate(data)
    fft_out = strategy.calculate
    n = fft_out.length.to_f
    conjugate(fft_out){ |real, imag| OpenStruct.new(real: (real / n), imaginary: (imag / n) ) }
end

Private Instance Methods

conjugate(data) { |real, imaginary| ... } click to toggle source
# File lib/strategies/fft/inverse_fft_conjugate_strategy.rb, line 31
def conjugate(data)
    data.map do |value|
        if value.is_a? Complex
            complex_num = block_given? ? yield(value.real, value.imaginary) : OpenStruct.new(real: value.real, imaginary: value.imaginary)
            Complex(complex_num.real, -1 * complex_num.imaginary)
        else
            real_num = block_given? ? yield(value, 0) : OpenStruct.new(real: value, imaginary: 0)
            real_num.real
        end
    end
end