Source code for hermespy.fec.cyclic_redundancy_check
# -*- coding: utf-8 -*-"""========================Cyclic Redundancy Checks========================Cyclic Redundancy Check (CRC) channel coding schemes introduce redundancy in order to detect the occurrenceof errors within a block of coded bits after reception.CRC codings usually only detect errors, they do not correct them."""from__future__importannotationsfromtyping_extensionsimportoverrideimportnumpyasnpfromhermespy.coreimportRandomNode,Serializable,SerializationProcess,DeserializationProcessfrom.codingimportEncoder__author__="Tobias Kronauer"__copyright__="Copyright 2024, Barkhausen Institut gGmbH"__credits__=["Tobias Kronauer","Jan Adler"]__license__="AGPLv3"__version__="1.5.0"__maintainer__="Jan Adler"__email__="jan.adler@barkhauseninstitut.org"__status__="Prototype"
[docs]classCyclicRedundancyCheck(Encoder,RandomNode,Serializable):"""Cyclic Redundancy Check Mock. This channel coding step mocks CRC algorithms by appending a random checksum of :math:`Q` :meth:`.check_block_size` bits to data bit blocks of size :math:`K_n` :meth:`.bit_block_size`. The achieved coding rate is therefore .. math:: R_{n} = \\frac{K_n}{K_n + Q} \\mathrm{.} """__bit_block_size:int# Number of bits per encoded block.__check_block_size:int# Number of bits appended to bit blocks.def__init__(self,bit_block_size:int,check_block_size:int)->None:""" Args: bit_block_size (int): Number of bits per encoded block. check_block_size (int): Number of bits appended to bit blocks. """Encoder.__init__(self)RandomNode.__init__(self)Serializable.__init__(self)self.bit_block_size=bit_block_sizeself.check_block_size=check_block_size
@propertydefbit_block_size(self)->int:returnself.__bit_block_size@bit_block_size.setterdefbit_block_size(self,value:int)->None:ifvalue<1:raiseValueError("CRC bit block size must be greater or equal to one")self.__bit_block_size=value@propertydefcheck_block_size(self)->int:"""Number of appended check bits per bit block. Returns: int: Number of check bits :math:`Q`. Raises: ValueError: If `check_block_size` is smaller than zero. """returnself.__check_block_size@check_block_size.setterdefcheck_block_size(self,value:int)->None:ifvalue<0:raiseValueError("Number of check bits must be greater or equal to zero")self.__check_block_size=value@propertydefcode_block_size(self)->int:returnself.__bit_block_size+self.__check_block_size