Sha256: 171f363868b9b9382843d2480200472f119c5dcbb86e1d476f7e6cf25af19c4d

Contents?: true

Size: 1.44 KB

Versions: 7

Compression:

Stored size: 1.44 KB

Contents

##
# Strategy for calculating the Inverse Fast Fourier Transform (IFFT)
# O(nlgn) runtime, depends on the FFT strategy to calculate thie IFFT
# Uses "conjugate strategy"
class Digiproc::Strategies::IFFTConjugateStrategy

    attr_accessor :data, :strategy

    ##
    # == Input args:
    # data:: Array[Numeric] (DFT values)
    # fft_strategy(Optional):: See Digiproc::Strategies::Radix2Strategy for required protocol (This is the default value)
    def initialize(data, fft_strategy = Digiproc::Strategies::Radix2Strategy)
        @data = data
        @strategy = fft_strategy.new
    end

    ##
    # No input args
    # Calculate the IFFT given Discrete Fourier Transform (DFT) values
    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

    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


end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
digiproc-0.2.5 lib/strategies/fft/inverse_fft_conjugate_strategy.rb
digiproc-0.2.4 lib/strategies/fft/inverse_fft_conjugate_strategy.rb
digiproc-0.2.3 lib/strategies/fft/inverse_fft_conjugate_strategy.rb
digiproc-0.2.2 lib/strategies/fft/inverse_fft_conjugate_strategy.rb
digiproc-0.2.1 lib/strategies/fft/inverse_fft_conjugate_strategy.rb
digiproc-0.2.0 lib/strategies/fft/inverse_fft_conjugate_strategy.rb
digiproc-0.1.0 lib/strategies/fft/inverse_fft_conjugate_strategy.rb