Module: Radio::Utils
- Defined in:
- lib/radio/utils/misc.rb,
lib/radio/utils/firpm.rb,
lib/radio/utils/window.rb
Defined Under Namespace
Classes: FirPM
Constant Summary collapse
- FIRPM_CACHE_VERSION =
1
- FIRPM_CACHE_FILENAME =
File. '~/.radio_firpm_cache'
- @@firpm_cache =
{}
- @@firpm_mtime =
nil
Class Method Summary collapse
- .firpm(options) ⇒ Object
- .hamming_window(array, w = nil) ⇒ Object
- .hamming_window!(array, width = nil) ⇒ Object
- .kaiser_estimate(options) ⇒ Object
Class Method Details
.firpm(options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/radio/utils/firpm.rb', line 31 def firpm out = nil File.open(FIRPM_CACHE_FILENAME, File::CREAT|File::RDWR) do |f| f.flock(File::LOCK_EX) if f.mtime != @@firpm_mtime @@firpm_cache = YAML::load(f) unless @@firpm_cache and @@firpm_cache[:version] == FIRPM_CACHE_VERSION @@firpm_cache = {version:FIRPM_CACHE_VERSION} end f.seek 0 @@firpm_mtime = f.mtime end firpm = FirPM.new() out = @@firpm_cache[firpm.] unless out out = firpm.to_a @@firpm_cache[firpm.] = out f.truncate 0 YAML::dump @@firpm_cache, f end end out end |
.hamming_window(array, w = nil) ⇒ Object
31 32 33 |
# File 'lib/radio/utils/window.rb', line 31 def hamming_window array, w = nil hamming_window! array.dup end |
.hamming_window!(array, width = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/radio/utils/window.rb', line 20 def hamming_window! array, width = nil n = -1 width ||= array.size w = width - 1 array.collect! do |v| n += 1 0.54 - 0.46 * Math.cos((PI2 * n) / w) end end |
.kaiser_estimate(options) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/radio/utils/misc.rb', line 23 def kaiser_estimate ripple = [:passband].to_f * [:stopband] numer = -20.0 * Math.log10(ripple) - 13 denum = 14.6 * [:transition] taps = (numer/denum).round type = [:type] || :odd if type == :even taps +=1 if taps.odd? else taps +=1 if taps.even? end taps end |