Class: PWN::SDR::Decoder::ADSB::DemodIQ

Inherits:
Object
  • Object
show all
Defined in:
lib/pwn/sdr/decoder/adsb.rb

Overview

Streaming I/Q demod for Base.run_iq.

Instance Method Summary collapse

Constructor Details

#initialize(rate: 2_000_000) ⇒ DemodIQ

Returns a new instance of DemodIQ.



28
29
30
31
32
33
# File 'lib/pwn/sdr/decoder/adsb.rb', line 28

def initialize(rate: 2_000_000)
  @rate = rate.to_f
  @spb  = @rate / 1_000_000.0 # samples per µs (expect ~2)
  @mag  = []
  @seen = {}
end

Instance Method Details

#feed_iq(samples, rate: nil, &emit) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pwn/sdr/decoder/adsb.rb', line 35

def feed_iq(samples, rate: nil, &emit)
  @rate = rate.to_f if rate
  @spb  = @rate / 1_000_000.0
  m2 = PWN::SDR::Decoder::DSP.mag_sq(iq: samples)
  @mag.concat(m2)
  # Scan the entire buffer FIRST so frames that land earlier in a
  # multi-ms chunk are not discarded by the ring-buffer clamp below.
  # Only AFTER scan() has consumed what it can do we cap residual
  # history (frame + preamble headroom ≈ 0.5 ms, keep 50 ms).
  scan(&emit)
  max = (@rate * 0.05).to_i
  @mag.shift(@mag.length - max) if @mag.length > max
end