Module: Radio::Filter::MixDecimateFir

Includes:
SetupFir
Defined in:
lib/radio/filters/fir.rb

Instance Method Summary collapse

Methods included from SetupFir

#decimation_fir=, #decimation_mix=, #interpolation_fir=, #interpolation_mix=

Instance Method Details

#call(data) {|out| ... } ⇒ Object

Yields:

  • (out)


227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/radio/filters/fir.rb', line 227

def call data
  data_size = data.size
  @decimation_phase /= @decimation_phase.abs
  out_size = data_size / @decimation_size
  out_size += 1 if @decimation_size - @decimation_pos <= data_size % @decimation_size
  out = NArray.scomplex out_size
  out_count = 0
  i = 0
  while i < data_size
    want = (@decimation_size - @decimation_pos).round
    remaining = data_size - i
    space = @decimation_fir_size - @decimation_fir_pos
    actual = [want,remaining,space].min
    new_fir_pos = @decimation_fir_pos + actual
    @decimation_buf[@decimation_fir_pos...new_fir_pos] = data[i...i+actual]
    @decimation_fir_pos = new_fir_pos
    @decimation_fir_pos = 0 if @decimation_fir_pos == @decimation_fir_size
    @decimation_pos += actual
    if @decimation_pos >= @decimation_size
      @decimation_pos -= @decimation_size
      j = @decimation_fir_coef[@decimation_fir_pos].mul_accum @decimation_buf, 0
      out[out_count] = j * @decimation_phase *= @decimation_inc
      out_count += 1
    end
    i += actual
  end
  yield out unless out.empty?
end