Class: SPCore::FlatTopWindow

Inherits:
Object
  • Object
show all
Defined in:
lib/spcore/windows/flat_top_window.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ FlatTopWindow

Returns a new instance of FlatTopWindow.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/spcore/windows/flat_top_window.rb', line 11

def initialize size
  @data = Array.new(size)
  a0, a1, a2, a3, a4 = 1.0, 1.93, 1.29, 0.388, 0.032
  
  size.times do |n|
    @data[n] = a0 - a1 * Math::cos((TWO_PI * n)/(size - 1)) + a2 * Math::cos((FOUR_PI * n)/(size - 1)) - a3 * Math::cos((SIX_PI * n)/(size - 1)) + a4 * Math::cos((EIGHT_PI * n)/(size - 1))
  end
  
  max = @data.max
  
  # normalize to max of 1.0
  @data.each_index do |i|
    @data[i] /= max
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/spcore/windows/flat_top_window.rb', line 10

def data
  @data
end