Class: Radio::PSK31::BitDetect
- Inherits:
-
Object
- Object
- Radio::PSK31::BitDetect
- Defined in:
- lib/radio/psk31/bit_detect.rb
Constant Summary collapse
- AVG_SAMPLES =
50.freeze
- CHANGE_DELAY =
5
Instance Method Summary collapse
- #call(iq) {|iq| ... } ⇒ Object
-
#initialize ⇒ BitDetect
constructor
A new instance of BitDetect.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ BitDetect
Returns a new instance of BitDetect.
25 26 27 28 |
# File 'lib/radio/psk31/bit_detect.rb', line 25 def initialize @averages = Array.new 16 reset end |
Instance Method Details
#call(iq) {|iq| ... } ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/radio/psk31/bit_detect.rb', line 38 def call iq yield iq if @phase == @peak @peak = @next_peak if @phase == @change_at energy = iq.real**2 + iq.imag**2 @averages[@phase] = (1.0-1.0/AVG_SAMPLES)*@averages[@phase] + (1.0/AVG_SAMPLES)*energy @phase += 1 if @phase > 15 @phase = 0 max = -1e10 for i in 0...16 energy = @averages[i] if energy > max @next_peak = i @change_at = (i + CHANGE_DELAY) & 0x0F max = energy end end end end |
#reset ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/radio/psk31/bit_detect.rb', line 30 def reset @averages.fill 0.0 @phase = 0 @peak = 0 @next_peak = 0 @change_at = 0 end |