From 70bbe08bc4c049d53d45a26aefecef3da250e9c9 Mon Sep 17 00:00:00 2001 From: Andreas Tsouchlos Date: Thu, 10 Nov 2022 09:51:58 +0100 Subject: [PATCH] Fixed usage of n and k --- sw/decoders/maximum_likelihood.py | 3 ++- sw/decoders/proximal.py | 2 +- sw/utility/codes.py | 15 +++++++-------- sw/utility/simulations.py | 1 - 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/sw/decoders/maximum_likelihood.py b/sw/decoders/maximum_likelihood.py index 09ccf5d..23db856 100644 --- a/sw/decoders/maximum_likelihood.py +++ b/sw/decoders/maximum_likelihood.py @@ -25,6 +25,7 @@ class MLDecoder: """Generate a list of all possible codewords. :return: Numpy array of the form [[codeword_1], [codeword_2], ...] + (Each generated codeword is an element of [0, 1]^n) """ k, n = self._G.shape @@ -44,7 +45,7 @@ class MLDecoder: :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) + :return: Most probably sent codeword (element of [0, 1]^k) """ correlations = np.dot(self._codewords_bpsk, y) diff --git a/sw/decoders/proximal.py b/sw/decoders/proximal.py index c3f73d1..6cc64be 100644 --- a/sw/decoders/proximal.py +++ b/sw/decoders/proximal.py @@ -73,7 +73,7 @@ class ProximalDecoder: :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 codeword (element of [0, 1]^k) + :return: Most probably sent codeword (element of [0, 1]^n) """ s = np.zeros(self._n) x_hat = np.zeros(self._n) diff --git a/sw/utility/codes.py b/sw/utility/codes.py index 91d7ebb..4800e0f 100644 --- a/sw/utility/codes.py +++ b/sw/utility/codes.py @@ -4,7 +4,6 @@ Code from https://github.com/gnuradio/gnuradio/blob/master/gr-fec/python/fec/LDP import numpy as np -from enum import Enum # @@ -233,15 +232,15 @@ def get_systematic_H(G: np.array) -> np.array: :param G: Generator matrix of the systematic code :return: Parity check matrix H """ - n, k = G.shape + k, n = G.shape - I = G[:, :n] - assert np.array_equal(I, np.identity(n)) + I = G[:, :k] + assert np.array_equal(I, np.identity(k)) - P = G[:, n:] + P = G[:, k:] - H = np.zeros(shape=(k-n, n + k-n)) - H[:, :n] = P.T - H[:, n:] = np.identity(k-n) + H = np.zeros(shape=(n-k, k + n-k)) + H[:, :k] = P.T + H[:, k:] = np.identity(n-k) return H diff --git a/sw/utility/simulations.py b/sw/utility/simulations.py index a78ee89..b4471d5 100644 --- a/sw/utility/simulations.py +++ b/sw/utility/simulations.py @@ -18,7 +18,6 @@ def count_bit_errors(d: np.array, d_hat: np.array) -> int: return np.sum(d != d_hat) -# TODO: Fix uses of n, k, a everywhere def test_decoder(x: np.array, decoder: typing.Any, SNRs: typing.Sequence[float] = np.linspace(1, 4, 7),