Replaced for loop with builtin numpy function

This commit is contained in:
Andreas Tsouchlos 2022-11-07 11:07:39 +01:00
parent 2f1497b1b8
commit c90cddf30b

View File

@ -4,13 +4,13 @@ import itertools
class SoftDecisionDecoder:
"""This class naively implements a soft decision decoder. This decoder calculates
the posterior probability for each codeword and then chooses the one with the largest
probability.
"""This class naively implements a soft decision decoder. The decoder calculates
the correlation between the received signal and each codeword and then chooses the
one with the largest correlation.
"""
def __init__(self, G: np.array, H: np.array):
"""Construct a new SotDecisionDecoder object.
"""Construct a new SoftDecisionDecoder object.
:param G: Generator matrix
:param H: Parity check matrix
@ -39,16 +39,12 @@ class SoftDecisionDecoder:
def decode(self, y: np.array) -> np.array:
"""Decode a received signal.
This function assumes a BPSK-like modulated signal ([-1, 1]^n instead of [0, 1]^n)
and an AWGN channel.
This function assumes a BPSK-like modulated signal ([-1, 1]^n instead of [0, 1]^n).
:param y: Vector of received values. (y = x + n, where 'x' is element of [-1, 1]^m
and 'n' is noise)
:return: Most probably sent symbol
:param y: Vector of received values. (y = x + w, where 'x' is element of [-1, 1]^n
and 'w' is noise)
:return: Most probably sent dataword (element of [0, 1]^k)
"""
# TODO: Is there a nice numpy way to implement this for loop?
correlations = []
for c in self._codewords_bpsk:
correlations.append(np.dot(y, c))
correlations = np.dot(self._codewords_bpsk, y)
return self._datawords[numpy.argmax(correlations)]