Class: PWN::SDR::Decoder::DECT::DemodIQ
- Inherits:
-
Object
- Object
- PWN::SDR::Decoder::DECT::DemodIQ
- Defined in:
- lib/pwn/sdr/decoder/dect.rb
Overview
Streaming I/Q energy/burst demod for Base.run_iq.
Instance Method Summary collapse
- #feed_iq(samples, rate: nil) ⇒ Object
-
#initialize(rate:, protocol:, modulation:, extra: {}) ⇒ DemodIQ
constructor
A new instance of DemodIQ.
Constructor Details
#initialize(rate:, protocol:, modulation:, extra: {}) ⇒ DemodIQ
Returns a new instance of DemodIQ.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pwn/sdr/decoder/dect.rb', line 12 def initialize(rate:, protocol:, modulation:, extra: {}) @rate = rate.to_f @protocol = protocol @modulation = modulation @extra = extra @floor = nil @in_burst = false @burst_t0 = nil @peak = -200.0 @burst_n = 0 @threshold = (extra[:threshold] || 8.0).to_f end |
Instance Method Details
#feed_iq(samples, rate: nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pwn/sdr/decoder/dect.rb', line 25 def feed_iq(samples, rate: nil, &) @rate = rate.to_f if rate m2 = PWN::SDR::Decoder::DSP.mag_sq(iq: samples) hop = [(@rate / 1000.0).round, 1].max i = 0 while i < m2.length win = m2[i, hop] break if win.nil? || win.empty? ms = win.sum / win.length lvl = ms.positive? ? (10.0 * Math.log10(ms)) : -120.0 @floor = @floor.nil? ? lvl : ((@floor * 0.98) + (lvl * 0.02)) delta = lvl - @floor if delta >= @threshold unless @in_burst @in_burst = true @burst_t0 = Time.now @peak = lvl end @peak = lvl if lvl > @peak elsif @in_burst @in_burst = false @burst_n += 1 dur_ms = ((Time.now - @burst_t0) * 1000).round msg = { protocol: @protocol, event: 'burst', source: 'iq', burst_no: @burst_n, peak_dbfs: @peak.round(1), floor_dbfs: @floor.round(1), delta_db: (@peak - @floor).round(1), duration_ms: dur_ms, modulation: @modulation, sample_rate: @rate.to_i }.merge(@extra.except(:threshold)) # protocol-specific enrichment msg.merge!(self.class.enrich(msg)) if self.class.respond_to?(:enrich) msg[:summary] = format( '%<p>s IQ-burst #%<n>d peak=%<pk>+.1f dBFS Δ=%<d>.1f dB dur=%<ms>d ms', p: @protocol, n: @burst_n, pk: @peak, d: @peak - @floor, ms: dur_ms ) yield msg if block_given? end i += hop end end |