Class: DSP::Decimator
- Inherits:
-
Object
- Object
- DSP::Decimator
- 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 sample 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
Instance Method Summary collapse
- #call(waveform) ⇒ Waveform
-
#initialize(factor, taps: DEFAULT_TAPS) ⇒ Decimator
constructor
A new instance of Decimator.
Constructor Details
#initialize(factor, taps: DEFAULT_TAPS) ⇒ Decimator
Returns a new instance of Decimator.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dsprb/decimator.rb', line 15 def initialize(factor, taps: DEFAULT_TAPS) @factor = Integer(factor) @taps = Integer(taps) raise ArgumentError, "factor must be at least one, got #{@factor}" unless @factor >= 1 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.
11 12 13 |
# File 'lib/dsprb/decimator.rb', line 11 def factor @factor end |
#kernel ⇒ ::Array[::Float] (readonly)
Returns the value of attribute kernel.
11 12 13 |
# File 'lib/dsprb/decimator.rb', line 11 def kernel @kernel end |
#taps ⇒ ::Integer (readonly)
Returns the value of attribute taps.
11 12 13 |
# File 'lib/dsprb/decimator.rb', line 11 def taps @taps end |
Class Method Details
.factor_for(sample_rate, target) ⇒ ::Integer
13 |
# File 'lib/dsprb/decimator.rb', line 13 def self.factor_for(sample_rate, target) = [(sample_rate / target).floor, 1].max |