Communications Toolbox    
hammgen

Produce parity-check and generator matrices for Hamming code

Syntax

Description

For all syntaxes, the codeword length is n. n has the form 2m-1 for some positive integer m greater than or equal to 3. The message length, k, has the form n-m.

h = hammgen(m) produces an m-by-n parity-check matrix for a Hamming code having codeword length n = 2m-1. m is a positive integer greater than or equal to 3. The message length of the code is n-m. The binary primitive polynomial used to produce the Hamming code is MATLAB's default primitive polynomial for GF(2m), represented by gfprimdf(m).

h = hammgen(m,pol) produces an m-by-n parity-check matrix for a Hamming code having codeword length n = 2m-1. m is a positive integer greater than or equal to 3. The message length of the code is n-m. pol is a row vector that gives the coefficients, in order of ascending powers, of the binary primitive polynomial for GF(2m) that is used to produce the Hamming code. hammgen produces an error if pol represents a polynomial that is not, in fact, primitive.

[h,g] = hammgen(...) is the same as h = hammgen(...) except that it also produces the k-by-n generator matrix g that corresponds to the parity-check matrix h. k, the message length, equals n-m, or, 2m-1-m.

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

Examples

The command below exhibits the parity-check and generator matrices for a Hamming code with codeword length 7 = 23-1 and message length 4 = 7-3.

The command below, which uses 1 + x2 + x3 as the primitive polynomial for GF(23), shows that the parity-check matrix depends on the choice of primitive polynomial. Notice that h1 below is different from h in the example above.

Algorithm

Unlike gftuple which processes one m-tuple at a time, hammgen generates the entire sequence from 0 to 2m-1. The computation algorithm uses all previously computed values to produce the computation result.

See Also
gftuple, gfrepcov, gfprimck, gfprimfd, gfprimdf


 gfweight hank2sys