ldpc.code_util
- ldpc.code_util.codewords(H)
Computes all of the the codewords of the code corresponding to the parity check matrix H. The codewords are given by the span of the nullspace.
- Parameters
H (numpy.ndarray) – A parity check matrix.
- Returns
A matrix where each row corresponds to a codeword
- Return type
numpy.ndarray
Note
If you want to calculate a basis of the codewords use ldpc.mod2.nullspace.
Examples
>>> H=np.array([[0, 0, 0, 1, 1, 1, 1],[0, 1, 1, 0, 0, 1, 1],[1, 0, 1, 0, 1, 0, 1]]) >>> print(codewords(H)) [[0 0 0 0 0 0 0] [0 0 0 1 1 1 1] [0 0 1 0 1 1 0] [0 0 1 1 0 0 1] [0 1 0 0 1 0 1] [0 1 0 1 0 1 0] [0 1 1 0 0 1 1] [0 1 1 1 1 0 0] [1 0 0 0 0 1 1] [1 0 0 1 1 0 0] [1 0 1 0 1 0 1] [1 0 1 1 0 1 0] [1 1 0 0 1 1 0] [1 1 0 1 0 0 1] [1 1 1 0 0 0 0] [1 1 1 1 1 1 1]]
- ldpc.code_util.compute_code_distance(H)
Computes the distance of the code given by parity check matrix H. The code distance is given by the minimum weight of a nonzero codeword.
Note
The runtime of this function scales exponentially with the block size. In practice, computing the code distance of codes with block lengths greater than ~10 will be very slow.
- Parameters
H (numpy.ndarray) – The parity check matrix
- Returns
The code distance
- Return type
int
- ldpc.code_util.compute_column_row_weights(H)
Returns the upper bounds on the row and column weights of parity check matrix
- Parameters
H (numpy.ndarray) – The parity check matrix
- Returns
int – The maximum column-weight
int – The maximum row-weight
- ldpc.code_util.construct_generator_matrix(H)
Constructs a generator matrix from a parity check H. The generator matrix G satisfies the condition:
H@G.T = 0.
Each of the columns of the generator matrix is a nullspace vector of the matrix H.
- Parameters
H (numpy.ndarray) – A binary matrix in numpy.ndarray format.
- Returns
The generator matrix in numpy.ndarray format
- Return type
numpy.ndarray
Examples
>>> H=np.array([[0, 0, 0, 1, 1, 1, 1],[0, 1, 1, 0, 0, 1, 1],[1, 0, 1, 0, 1, 0, 1]]) >>> G=construct_generator_matrix(H) >>> assert (H@G.T%2).any()==False >>> print(G) [[1 1 1 0 0 0 0] [0 1 1 1 1 0 0] [0 1 0 1 0 1 0] [0 0 1 1 0 0 1]]
- ldpc.code_util.get_code_parameters(H)
Returns the code parameters in [n,k,d] notation where n is the block length, k is the number of encoed bits and d is the code distance.
- Parameters
H (numpy.ndarray) – The parity check matrix
- Returns
n (int) – The block length
k (int) – The number of encoded bits
d (int) – The code distance
r (int) – The rank of the parity check matrix
m (int) – The number of checks (rows in the parity check matrix)
- ldpc.code_util.get_ldpc_params(H)
Returns the upper bounds on the row and column weights of parity check matrix
- Parameters
H (numpy.ndarray) – The parity check matrix
- Returns
int – The maximum column-weight
int – The maximum row-weight
- ldpc.code_util.search_cycles(H, girth, row=None, terminate=True, exclude_rows=[])
Searches (and counts) cycles of a specified girth.
- Parameters
H (numpy.ndarray) – The parity check matrix
girth (int) – The girth (length) of the code cycles to search for
row (int, optional) – Default value is None. If a row is specified, the function returns the local girth for that row. If row=None, then the global girth is calculated.
terminate (int, optional) – Default value is True. If set to True, the search function will terminate as soon as the first cycle of the specefied girth is found
exclude_rows (list, optional) – The rows of the parity check to ignore. This is useful when you are filling an empty matrix.
- Returns
bool, if Terminate=True – True if a cycle of specified girth is found. False if no cycles are found.
int, if Terminate=False – If terminate is set to true, the function will count the number of cycles of the specified girth
- ldpc.code_util.systematic_form(H)
Converts H into systematic form so that:
H=[I,A]
- Parameters
H (numpy.ndarray) – A parity check matrix
- Returns
The parity check matrix in systematic form
- Return type
numpy.ndarray