Class: Digiproc::Strategies::DifferentialEncodingStrategy
- Inherits:
-
Object
- Object
- Digiproc::Strategies::DifferentialEncodingStrategy
- Defined in:
- lib/strategies/code/differential_encoding_strategy.rb
Overview
Class/Strategy for for encoding a string of bits ENCODES SIGNAL PER M-ARY PSK CODING STRATEGY, SEE HW6 ELEG 635 use the generic DPSK equation for M = 2. We will apply the ORIGINAL signal Dn to the equation βn = (2l−1)π % 2π, l ⩽ M for the phase mapping, and M then the differential signal will be created by saying our transmitted bit will be αn = αn−1 + βn
Class Method Summary collapse
-
.decode(bits, m = 2) ⇒ Object
Does not simulate a reciever, it just does the inverse algorithm to retrieve the original message Currently incorrect TODO: fix this method.
-
.encode(arr, m = 2, beginning_val = "0") ⇒ Object
Encoding an incoming array of bits into an array of encoded phase angles Requires an input of an array, and has optional arguments of m (number of bits per symbol) And a beginning value (a starting reference phase angle).
-
.phase_shift_eqn(m = nil) ⇒ Object
Required via the protocol for an encoding strategy, but this algorithm does not require a phase shift so the lambda will return the input.
-
.phase_to_sym(m = nil) ⇒ Object
Required via the protocol for an encoding strategy, but this algorithm does not require a phase shift so the lambda will return the input.
Class Method Details
.decode(bits, m = 2) ⇒ Object
Does not simulate a reciever, it just does the inverse algorithm to retrieve the original message Currently incorrect TODO: fix this method
36 37 38 39 40 41 42 |
# File 'lib/strategies/code/differential_encoding_strategy.rb', line 36 def self.decode(bits, m = 2) encoded = [] for i in 1...bits.length do encoded << ((-1 * bits[i - 1].to_f + bits[i].to_f) % (2 * Math::PI)).to_s end encoded.map{|phase| decode_phase(m)[phase.to_f]} end |
.encode(arr, m = 2, beginning_val = "0") ⇒ Object
Encoding an incoming array of bits into an array of encoded phase angles Requires an input of an array, and has optional arguments of m (number of bits per symbol) And a beginning value (a starting reference phase angle). Outputs an array of phase angles Unline previous encoding strategies, this does not XOR the bits and then phase shift those encoded bits. Instead, the bits are transformed into frequencies which are then added to dealyed versions of themselves modulo 2pi
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/strategies/code/differential_encoding_strategy.rb', line 19 def self.encode(arr, m = 2, beginning_val = "0") beginning_val = beginning_val.to_s(2) unless beginning_val.is_a? String encoded = [beginning_val] arr = arr.map(&:to_s) for i in 0...arr.length do curr_phase = to_phase(m)[arr[i].to_i(2).to_f] last_phase = encoded.last.to_f encoded << ((curr_phase + last_phase) % (2 * Math::PI)).to_s end encoded end |
.phase_shift_eqn(m = nil) ⇒ Object
Required via the protocol for an encoding strategy, but this algorithm does not require a phase shift so the lambda will return the input
47 48 49 |
# File 'lib/strategies/code/differential_encoding_strategy.rb', line 47 def self.phase_shift_eqn(m = nil) ->(l){ l } end |
.phase_to_sym(m = nil) ⇒ Object
Required via the protocol for an encoding strategy, but this algorithm does not require a phase shift so the lambda will return the input
54 55 56 |
# File 'lib/strategies/code/differential_encoding_strategy.rb', line 54 def self.phase_to_sym(m = nil) ->(l){ l } end |