Class: Radio::PSK31::Decoder
- Inherits:
-
Object
- Object
- Radio::PSK31::Decoder
- Defined in:
- lib/radio/psk31/decoder.rb
Instance Attribute Summary collapse
-
#mode ⇒ Object
:bpsk or :qpsk or :qpsklsb.
Instance Method Summary collapse
- #call(iq) ⇒ Object
-
#initialize ⇒ Decoder
constructor
A new instance of Decoder.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Decoder
Returns a new instance of Decoder.
23 24 25 26 |
# File 'lib/radio/psk31/decoder.rb', line 23 def initialize @mode = :bpsk reset end |
Instance Attribute Details
#mode ⇒ Object
:bpsk or :qpsk or :qpsklsb
21 22 23 |
# File 'lib/radio/psk31/decoder.rb', line 21 def mode @mode end |
Instance Method Details
#call(iq) ⇒ Object
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 67 68 69 |
# File 'lib/radio/psk31/decoder.rb', line 37 def call iq @prev_i = @this_i @prev_q = @this_q @this_i = iq.real @this_q = iq.imag vect_y = @prev_i*@this_i + @prev_q*@this_q if @mode == :bpsk bit = vect_y >= 0.0 ? 1 : 0 else vect_x = @prev_i*@this_q - @this_i*@prev_q if vect_y == 0.0 # atan2 errors on (0,0) angle = PI elsif @mode == :qpsklsb angle = PI + Math.atan2(vect_y, -vect_x) else # :qpsk or :bpsk angle = PI + Math.atan2(vect_y, vect_x) end bit = viterbi angle end if bit==0 and @prev_bit==0 if @code != 0 @code >>= 2 @code &= 0x07FF ch = VARICODE_DECODE_TABLE[@code] yield ch if ch @code = 0 end else @code <<= 1 @code |= bit @prev_bit = bit end end |
#reset ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/radio/psk31/decoder.rb', line 28 def reset @prev_i = 0.0 @prev_q = 0.0 @this_i = 0.0 @this_q = 0.0 @code = 0 @prev_bit = false end |