Class: Noyes::LiveCMN

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

Overview

Normalizes cepstrum means and applies them. Dimensionality remains unchanged. NOTE: This class resets itself automatically if bounds drift too much. Possibly these bounds should be parameterized.

Instance Method Summary (collapse)

Methods included from NoyesFilterDSL

#+, #|

Constructor Details

- (LiveCMN) initialize(dimensions = 13, init_mean = 45.0, window_size = 100, shift = 160)

Returns a new instance of LiveCMN



6
7
8
9
10
11
12
# File 'lib/ruby_impl/live_cmn.rb', line 6

def initialize dimensions=13, init_mean=45.0, window_size=100, shift=160
  @init_mean = init_mean; @shift = shift; @ws = window_size
  @sums = Array.new dimensions, 0
  @means = Array.new dimensions, 0
  @means[0] = @init_mean
  @frame_count = 0
end

Instance Method Details

- (Object) <<(dct)



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_impl/live_cmn.rb', line 13

def << dct
  raise "Wrong number of dimensions" if dct[0].size != @means.size
  dct.map do |mfc|
    cmn = Array.new @means.size
    @means.size.times do |i|
      @sums[i] += mfc[i]
      cmn[i] = mfc[i] - @means[i]
    end
    @frame_count += 1
    update if @frame_count > @shift
    cmn
  end
end

- (Object) reset



37
38
39
40
41
42
# File 'lib/ruby_impl/live_cmn.rb', line 37

def reset
  @sums.map! {0}
  @means.map! {0}
  @means[0] = @init_mean
  @frame_count = 0
end

- (Object) update



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ruby_impl/live_cmn.rb', line 26

def update
  per_frame = 1.0 / @frame_count
  @means = @sums.map {|x| x * per_frame}
  
  if @means.first > 70 || @means.first < 5
    reset
  else
    @sums = @sums.map {|x| x * per_frame * @ws}
    @frame_count = @ws
  end
end