Class: DSP::MelFilterbank
- Inherits:
-
Object
- Object
- DSP::MelFilterbank
- Defined in:
- lib/dsprb/mel_filterbank.rb,
sig/dsprb.rbs
Defined Under Namespace
Classes: Band
Constant Summary collapse
- DEFAULT_FILTERS =
26- DEFAULT_LOW_HZ =
50.0- ENERGY_FLOOR =
Keeps the logarithm of a band that collected no energy finite.
1e-12
Instance Attribute Summary collapse
-
#bands ⇒ ::Array[Band]
readonly
Returns the value of attribute bands.
-
#filters ⇒ ::Integer
readonly
Returns the value of attribute filters.
-
#high ⇒ ::Float
readonly
Returns the value of attribute high.
-
#low ⇒ ::Float
readonly
Returns the value of attribute low.
-
#sample_rate ⇒ ::Float
readonly
Returns the value of attribute sample_rate.
-
#size ⇒ ::Integer
readonly
Returns the value of attribute size.
-
#warp ⇒ ::Float
readonly
Returns the value of attribute warp.
Instance Method Summary collapse
- #center_frequencies ⇒ ::Array[::Float]
- #energies(power) ⇒ ::Array[::Float]
-
#initialize(sample_rate:, size:, filters: DEFAULT_FILTERS, low: DEFAULT_LOW_HZ, high: nil, warp: 1.0) ⇒ MelFilterbank
constructor
warp rescales the band centers for vocal tract length normalization: values above 1 shift the bank upwards, suiting shorter vocal tracts.
- #log_energies(power) ⇒ ::Array[::Float]
Constructor Details
#initialize(sample_rate:, size:, filters: DEFAULT_FILTERS, low: DEFAULT_LOW_HZ, high: nil, warp: 1.0) ⇒ MelFilterbank
warp rescales the band centers for vocal tract length normalization: values above 1 shift the bank upwards, suiting shorter vocal tracts.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dsprb/mel_filterbank.rb', line 19 def initialize(sample_rate:, size:, filters: DEFAULT_FILTERS, low: DEFAULT_LOW_HZ, high: nil, warp: 1.0) @sample_rate = Float(sample_rate) @size = Integer(size) @filters = Integer(filters) @low = Float(low) @high = Float(high || (@sample_rate / 2.0)) @warp = Float(warp) validate! @bands = build_bands.freeze freeze end |
Instance Attribute Details
#bands ⇒ ::Array[Band] (readonly)
Returns the value of attribute bands.
15 16 17 |
# File 'lib/dsprb/mel_filterbank.rb', line 15 def bands @bands end |
#filters ⇒ ::Integer (readonly)
Returns the value of attribute filters.
15 16 17 |
# File 'lib/dsprb/mel_filterbank.rb', line 15 def filters @filters end |
#high ⇒ ::Float (readonly)
Returns the value of attribute high.
15 16 17 |
# File 'lib/dsprb/mel_filterbank.rb', line 15 def high @high end |
#low ⇒ ::Float (readonly)
Returns the value of attribute low.
15 16 17 |
# File 'lib/dsprb/mel_filterbank.rb', line 15 def low @low end |
#sample_rate ⇒ ::Float (readonly)
Returns the value of attribute sample_rate.
15 16 17 |
# File 'lib/dsprb/mel_filterbank.rb', line 15 def sample_rate @sample_rate end |
#size ⇒ ::Integer (readonly)
Returns the value of attribute size.
15 16 17 |
# File 'lib/dsprb/mel_filterbank.rb', line 15 def size @size end |
#warp ⇒ ::Float (readonly)
Returns the value of attribute warp.
15 16 17 |
# File 'lib/dsprb/mel_filterbank.rb', line 15 def warp @warp end |
Instance Method Details
#center_frequencies ⇒ ::Array[::Float]
49 |
# File 'lib/dsprb/mel_filterbank.rb', line 49 def center_frequencies = @centers |
#energies(power) ⇒ ::Array[::Float]
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dsprb/mel_filterbank.rb', line 32 def energies(power) @bands.map do |band| weights = band.weights offset = band.offset total = 0.0 index = 0 while index < weights.length total += weights[index] * power[offset + index] index += 1 end total end end |
#log_energies(power) ⇒ ::Array[::Float]
47 |
# File 'lib/dsprb/mel_filterbank.rb', line 47 def log_energies(power) = energies(power).map { |value| Math.log([value, ENERGY_FLOOR].max) } |