Main Content

cyclgen

Produce parity-check and generator matrices for cyclic code

Description

h = cyclgen(n,p) produces an (nk)-by-n parity-check matrix for a systematic binary cyclic code that has a codeword length n for the generator polynomial, p. To generate a cyclic code, the generator polynomial, p, must be a factor of Xn – 1.

h = cyclgen(n,p,opt) includes opt to specify whether the cyclic parity-check matrix is systematic or nonsystematic.

[h,g] = cyclgen(___), using any previous syntax, also returns the k-by-n generator matrix, g, which corresponds to the parity-check matrix, h.

[h,g,k] = cyclgen(___), using any previous syntax, also returns the message length, k.

example

Examples

collapse all

Create parity check and generator matrices for a binary cyclic code that has 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. Because this code is systematic, the parity check matrix parmat2 has a 4-by-4 identity matrix embedded in its leftmost columns.

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

Input Arguments

collapse all

Codeword length, specified as a positive integer. Over the binary field gf(2), (Xn – 1) is the same as (Xn + 1). This relation implies that the message length, k = nm, where m is the degree of the generator polynomial.

Generator polynomial coefficients in ascending order, specified as a string or binary row vector. To generate a cyclic code, you must specify the generator polynomial as a factor of Xn – 1, where n is the codeword length.

For more information on specifying p as a polynomial character vector, see Representation of Polynomials in Communications Toolbox.

Type of cyclic parity-check matrix, specified as one of these options:

  • "system" — Produces a systematic cyclic parity-check matrix. A systematic cyclic parity-check matrix includes an identity matrix embedded in its leftmost columns.

  • "nonsys" — Produces a nonsystematic cyclic parity-check matrix.

Output Arguments

collapse all

Parity-check matrix, returned as an m-by-n matrix. m is the degree of generator polynomial, p.

Data Types: double

Generator matrix, returned as a k-by-n matrix. The generator matrix, g, corresponds to the parity-check matrix, h.

Data Types: double

Message length, returned as an integer. The message length of the code k = nm, where m is the degree of generator polynomial, p.

Version History

Introduced before R2006a