Class: Digiproc::BFDFTStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/strategies/fft/brute_force_dft_strategy.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ BFDFTStrategy

initialize with an array of numerics



12
13
14
# File 'lib/strategies/fft/brute_force_dft_strategy.rb', line 12

def initialize(data)
    @data = data.dup
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/strategies/fft/brute_force_dft_strategy.rb', line 9

def data
  @data
end

Instance Method Details

#calculate(data = @data) ⇒ Object

Calculate the DFT with an O(n^2) algorithm Can accept an array of numerics, with a default value of



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/strategies/fft/brute_force_dft_strategy.rb', line 19

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