Sha256: 83e5681eeb05a053b8ebf12e058f522b2e9e07e1bd94417629d27d003beab580

Contents?: true

Size: 915 Bytes

Versions: 7

Compression:

Stored size: 915 Bytes

Contents

##
# A brute force Discrete Fourier Transform strategy
# O(n^2) algorith, no reason to sue it over FFT unless you 
# don't want to work within the parameters of a Radix2 strategy 
# (ie data points of DFT size will be a power of 2). This strategy does
# not have those parameters
class Digiproc::BFDFTStrategy

    attr_accessor :data

    # initialize with an array of numerics
    def initialize(data)
        @data = data.dup
    end

    # Calculate the DFT with an O(n^2) algorithm
    # Can accept an array of numerics, with a default value of 
    # @data
    def calculate(data = @data)
        ft = []
        for k in 0...data.length do
            tot = 0
            data.each_with_index do |x_n, n|
                tot += x_n * Math::E ** (Complex(0,-1) * 2.0 * Math::PI * k * n / data.length.to_f)
            end
            ft << tot
        end
        ft
    end

end

Version data entries

7 entries across 7 versions & 1 rubygems

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