Class: Noyes::LiveCMN
- Inherits:
-
Object
- Object
- Noyes::LiveCMN
- 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
- #<<(dct) ⇒ Object
-
#initialize(dimensions = 13, init_mean = 45.0, window_size = 100, shift = 160) ⇒ LiveCMN
constructor
A new instance of LiveCMN.
- #reset ⇒ Object
- #update ⇒ Object
Methods included from NoyesFilterDSL
Constructor Details
#initialize(dimensions = 13, init_mean = 45.0, window_size = 100, shift = 160) ⇒ LiveCMN
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
#<<(dct) ⇒ Object
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 |
#reset ⇒ Object
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 |
#update ⇒ Object
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 |