Class: DSP::Decimator
- Inherits:
-
Object
- Object
- DSP::Decimator
- Extended by:
- Prepared
- Defined in:
- lib/dsprb/decimator.rb,
sig/dsprb.rbs
Constant Summary collapse
- DEFAULT_TAPS =
An odd tap count keeps the FIR linear phase, so decimation adds no group delay skew.
31- CUTOFF_RATIO =
Cutoff as a fraction of the decimated rate, leaving a transition margin below Nyquist.
0.45
Instance Attribute Summary collapse
-
#factor ⇒ ::Integer
readonly
Returns the value of attribute factor.
-
#kernel ⇒ ::Array[::Float]
readonly
Returns the value of attribute kernel.
-
#taps ⇒ ::Integer
readonly
Returns the value of attribute taps.
Class Method Summary collapse
- .factor_for(sample_rate, target) ⇒ ::Integer
- .for(factor, taps: DEFAULT_TAPS) ⇒ Decimator
- .to(waveform, target, taps: DEFAULT_TAPS) ⇒ Waveform
Instance Method Summary collapse
- #call(waveform) ⇒ Waveform
-
#initialize(factor, taps: DEFAULT_TAPS) ⇒ Decimator
constructor
A new instance of Decimator.
Methods included from Prepared
extended, prepared, prepared_count
Constructor Details
#initialize(factor, taps: DEFAULT_TAPS) ⇒ Decimator
Returns a new instance of Decimator.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dsprb/decimator.rb', line 23 def initialize(factor, taps: DEFAULT_TAPS) @factor = Check.at_least!(Integer(factor), 1, "factor") @taps = Integer(taps) raise ArgumentError, "taps must be a positive odd number, got #{@taps}" unless @taps.positive? && @taps.odd? @middle = (@taps - 1) / 2 @kernel = build_kernel.freeze freeze end |
Instance Attribute Details
#factor ⇒ ::Integer (readonly)
Returns the value of attribute factor.
13 14 15 |
# File 'lib/dsprb/decimator.rb', line 13 def factor @factor end |
#kernel ⇒ ::Array[::Float] (readonly)
Returns the value of attribute kernel.
13 14 15 |
# File 'lib/dsprb/decimator.rb', line 13 def kernel @kernel end |
#taps ⇒ ::Integer (readonly)
Returns the value of attribute taps.
13 14 15 |
# File 'lib/dsprb/decimator.rb', line 13 def taps @taps end |
Class Method Details
.factor_for(sample_rate, target) ⇒ ::Integer
15 |
# File 'lib/dsprb/decimator.rb', line 15 def self.factor_for(sample_rate, target) = [(sample_rate / target).floor, 1].max |
.for(factor, taps: DEFAULT_TAPS) ⇒ Decimator
17 |
# File 'lib/dsprb/decimator.rb', line 17 def self.for(factor, taps: DEFAULT_TAPS) = prepared([factor, taps]) { new(factor, taps: taps) } |
.to(waveform, target, taps: DEFAULT_TAPS) ⇒ Waveform
19 20 21 |
# File 'lib/dsprb/decimator.rb', line 19 def self.to(waveform, target, taps: DEFAULT_TAPS) self.for(factor_for(waveform.sample_rate, target), taps: taps).call(waveform) end |