Class: DSP::Dct::Two
- Inherits:
-
Object
- Object
- DSP::Dct::Two
- Extended by:
- Prepared
- Defined in:
- lib/dsprb/dct.rb,
sig/dsprb.rbs
Overview
Instance Attribute Summary collapse
-
#count ⇒ ::Integer
readonly
Returns the value of attribute count.
-
#length ⇒ ::Integer
readonly
Returns the value of attribute length.
Class Method Summary collapse
Instance Method Summary collapse
- #call(values) ⇒ ::Array[::Float]
-
#initialize(length, count) ⇒ Two
constructor
A new instance of Two.
Methods included from Prepared
extended, prepared, prepared_count
Constructor Details
#initialize(length, count) ⇒ Two
Returns a new instance of Two.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dsprb/dct.rb', line 13 def initialize(length, count) @length = Check.positive!(Integer(length), "length") @count = Check.positive!(Integer(count), "count") @basis = Array .new(@count) do |coefficient| Array.new(@length) { |index| Math.cos(Math::PI * coefficient * (index + 0.5) / @length) }.freeze end .freeze freeze end |
Instance Attribute Details
#count ⇒ ::Integer (readonly)
Returns the value of attribute count.
9 10 11 |
# File 'lib/dsprb/dct.rb', line 9 def count @count end |
#length ⇒ ::Integer (readonly)
Returns the value of attribute length.
9 10 11 |
# File 'lib/dsprb/dct.rb', line 9 def length @length end |
Class Method Details
.for(length, count) ⇒ Two
11 |
# File 'lib/dsprb/dct.rb', line 11 def self.for(length, count) = prepared([length, count]) { new(length, count) } |
Instance Method Details
#call(values) ⇒ ::Array[::Float]
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dsprb/dct.rb', line 25 def call(values) Array.new(@count) do |coefficient| row = @basis[coefficient] total = 0.0 index = 0 while index < @length total += values[index] * row[index] index += 1 end total end end |