Class: Noyes::DCT

Inherits:
Object
  • Object
show all
Includes:
Math, NoyesFilterDSL
Defined in:
lib/ruby_impl/dct.rb,
lib/common/noyes_dsl.rb

Overview

Takes the discrete cosing transform. Converts an n x m matrix to an n x order matrix. ncol should be set to m.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from NoyesFilterDSL

#+, #|

Methods included from Math

#dot_product, log2, max, min

Constructor Details

- (DCT) initialize(order, ncol)

Returns a new instance of DCT



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ruby_impl/dct.rb', line 9

def initialize order, ncol
  @melcos = []
  order.times do |i|
    freq = PI * i.to_f / ncol
    ldct = Array.new ncol
    ncol.times do |j|
      ldct[j] = cos(freq * (j + 0.5)) / order # [1]
    end
    @melcos << ldct
  end
  @melcos
end

Instance Attribute Details

- (Object) melcos

Returns the value of attribute melcos



8
9
10
# File 'lib/ruby_impl/dct.rb', line 8

def melcos
  @melcos
end

Instance Method Details

- (Object) <<(data)



22
23
24
25
26
# File 'lib/ruby_impl/dct.rb', line 22

def << data
  data.map do |dvec|
    @melcos.map {|m| dot_product m, dvec}
  end
end