Representing Words for Linear Block Codes

The cyclic, Hamming, and generic linear block code functionality in this toolbox offers you multiple ways to organize bits in messages or codewords. These topics explain the available formats:

To learn how to represent words for BCH or Reed-Solomon codes, see Representing Words for BCH Codes or Representing Words for Reed-Solomon Codes.

Binary Vector Format

Your messages and codewords can take the form of vectors containing 0s and 1s. For example, messages and codes might look like msg and code in the lines below.

n = 6; k = 4; % Set codeword length and message length
% for a [6,4] code.
msg = [1 0 0 1 1 0 1 0 1 0 1 1]'; % Message is a binary column.
code = encode(msg,n,k,'cyclic'); % Code will be a binary column.
msg'
code'

The output is below.

ans =

  Columns 1 through 5 

      1            0            0            1            1      

  Columns 6 through 10 

      0            1            0            1            0      

  Columns 11 through 12 

      1            1      


ans =

  Columns 1 through 5 

      1            1            1            0            0      

  Columns 6 through 10 

      1            0            0            1            0      

  Columns 11 through 15 

      1            0            0            1            1      

  Columns 16 through 18 

      0            1            1      

In this example, msg consists of 12 entries, which are interpreted as three 4-digit (because k = 4) messages. The resulting vector code comprises three 6-digit (because n = 6) codewords, which are concatenated to form a vector of length 18. The parity bits are at the beginning of each codeword.

Binary Matrix Format

You can organize coding information so as to emphasize the grouping of digits into messages and codewords. If you use this approach, then each message or codeword occupies a row in a binary matrix. The example below illustrates this approach by listing each 4-bit message on a distinct row in msg and each 6-bit codeword on a distinct row in code.

n = 6; k = 4; % Set codeword length and message length.
msg = [1 0 0 1; 1 0 1 0; 1 0 1 1]; % Message is a binary matrix.
code = encode(msg,n,k,'cyclic'); % Code will be a binary matrix.
msg
code

The output is below.

msg =

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


code =

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

Decimal Vector Format

Your messages and codewords can take the form of vectors containing integers. Each element of the vector gives the decimal representation of the bits in one message or one codeword.

The syntax for the encode command must mention the decimal format explicitly, as in the example below. Notice that /decimal is appended to the fourth argument in the encode command.

n = 6; k = 4; % Set codeword length and message length.
msg = [9;5;13]; % Message is a decimal column vector.
% Code will be a decimal vector.
code = encode(msg,n,k,'cyclic/decimal')

The output is below.

code =

    39
    20
    54


© 1994-2005 The MathWorks, Inc.