From c90cddf30bc37d42eac72109fd0a60d6887381e4 Mon Sep 17 00:00:00 2001 From: Andreas Tsouchlos Date: Mon, 7 Nov 2022 11:07:39 +0100 Subject: [PATCH] Replaced for loop with builtin numpy function --- sw/decoders/naive_soft_decision.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/sw/decoders/naive_soft_decision.py b/sw/decoders/naive_soft_decision.py index 2440b31..5cc507b 100644 --- a/sw/decoders/naive_soft_decision.py +++ b/sw/decoders/naive_soft_decision.py @@ -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)]