Class: Digiproc::WindowStrategy

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

Overview

Parent class to all types of windows

Constant Summary collapse

PI =
Math::PI

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size:) ⇒ WindowStrategy

Initialize with size: Numeric (numnber of datapoints in window)



13
14
15
16
# File 'lib/strategies/window/window.rb', line 13

def initialize(size: )
    @size = size
    @equation = lambda { |n| 1 }
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/strategies/window/window.rb', line 10

def data
  @data
end

#equationObject (readonly)

Returns the value of attribute equation.



10
11
12
# File 'lib/strategies/window/window.rb', line 10

def equation
  @equation
end

#sizeObject

Returns the value of attribute size.



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

def size
  @size
end

#valuesObject (readonly)

Returns the value of attribute values.



10
11
12
# File 'lib/strategies/window/window.rb', line 10

def values
  @values
end

Instance Method Details

#calculateObject

No input args calculate the window values



21
22
23
24
25
26
27
28
# File 'lib/strategies/window/window.rb', line 21

def calculate
    values = []
    for n in 0...size
        values << @equation.call(n)
    end
    @values = values
    @data = values
end

#make_odd(num) ⇒ Object

Make the number of datapoints in the window odd so that it can be used for all types of filters



33
34
35
# File 'lib/strategies/window/window.rb', line 33

def make_odd(num)
    num.odd? ? num : num + 1
end

#to_signalObject

Return window values as a Digiproc::DigitalSignal



38
39
40
# File 'lib/strategies/window/window.rb', line 38

def to_signal
    Digiproc::DigitalSignal.new(data: values)
end