ba-thesis/sw/utility/encoders.py

26 lines
794 B
Python

import numpy as np
# TODO: Unify the interface regarding [0, 1]^n and [-1, 1]^n
# TODO: Should the encoder be responsible for mapping the message from [0, 1]^n to [-1, 1]^n?
# (ie. should the encoder perform modulation?)
class Encoder:
"""Class implementing an encoder for block codes.
"""
def __init__(self, G: np.array):
"""Construct a new Encoder object.
:param G: Generator matrix
"""
self._G = G
def encode(self, d: np.array) -> np.array:
"""Map a given dataword onto the corresponding codeword.
The returned codeword is mapped from [0, 1]^n onto [-1, 1]^n.
:param d: Dataword (element of [0, 1]^n)
:return: Codeword (already element of [-1, 1]^n)
"""
return np.dot(d, self._G) * 2 - 1