Class: Radio::PSK31::BitDetect

Inherits:
Object
  • Object
show all
Defined in:
lib/radio/psk31/bit_detect.rb

Constant Summary collapse

AVG_SAMPLES =
50.freeze
CHANGE_DELAY =
5

Instance Method Summary collapse

Constructor Details

#initializeBitDetect

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

Yields:

  • (iq)


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

#resetObject



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