cyclgen

Produce parity-check and generator matrices for cyclic code

Syntax

h = cyclgen(n,pol)
h = cyclgen(n,pol,opt)
[h,g] = cyclgen(...)
[h,g,k] = cyclgen(...)

Description

For all syntaxes, the codeword length is n and the message length is k. A polynomial can generate a cyclic code with codeword length n and message length k if and only if the polynomial is a degree-(n-k) divisor of x^n-1. (Over the binary field GF(2), x^n-1 is the same as x^n+1.) This implies that k equals n minus the degree of the generator polynomial.

h = cyclgen(n,pol) produces an (n-k)-by-n parity-check matrix for a systematic binary cyclic code having codeword length n. The row vector pol gives the binary coefficients, in order of ascending powers, of the degree-(n-k) generator polynomial. Alternatively, you can specify pol as a polynomial character vector. For more information, see Representation of Polynomials in Communications Toolbox.

h = cyclgen(n,pol,opt) is the same as the syntax above, except that the argument opt determines whether the matrix should be associated with a systematic or nonsystematic code. The values for opt are 'system' and 'nonsys'.

[h,g] = cyclgen(...) is the same as h = cyclgen(...), except that it also produces the k-by-n generator matrix g that corresponds to the parity-check matrix h.

[h,g,k] = cyclgen(...) is the same as [h,g] = cyclgen(...), except that it also returns the message length k.

Examples

collapse all

Create parity check and generator matrices for a binary cyclic code having codeword length 7 and message length 4.

Create the generator polynomial using cyclpoly.

pol = cyclpoly(7,4);

Create the parity check and generator matrices. The parity check matrix parmat has a 3-by-3 identity matrix embedded in its leftmost columns.

[parmat,genmat,k] = cyclgen(7,pol)
parmat = 3×7

1     0     0     1     1     1     0
0     1     0     0     1     1     1
0     0     1     1     1     0     1

genmat = 4×7

1     0     1     1     0     0     0
1     1     1     0     1     0     0
1     1     0     0     0     1     0
0     1     1     0     0     0     1

k = 4

Create a parity check matrix in which the code is not systematic. The matrix parmatn does not have an embedded 3-by-3 identity matrix.

parmatn = cyclgen(7,pol,'nonsys')
parmatn = 3×7

1     1     1     0     1     0     0
0     1     1     1     0     1     0
0     0     1     1     1     0     1

Create the parity check and generator matrices for a (7,3) binary cyclic code. As this is a systematic code, there is a 4-by-4 identity matrix in the leftmost columns of parmat2.

parmat2 = cyclgen(7,'1 + x^2 + x^3 + x^4')
parmat2 = 4×7

1     0     0     0     1     1     0
0     1     0     0     0     1     1
0     0     1     0     1     1     1
0     0     0     1     1     0     1