Communications Toolbox | ![]() ![]() |
Representing Messages and Codewords
Each message or codeword is an ordered grouping of symbols. The next few subsections illustrate the various ways that these symbols may be organized or interpreted as input and output.
Binary Vector Format
One straightforward MATLAB format for messages and codewords is a vector of 0s and 1s. That is, 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' ans = 1 0 0 1 1 0 1 0 1 0 1 1 code' ans = Columns 1 through 12 0 0 1 0 0 1 1 0 1 0 1 0 Columns 13 through 18 0 1 1 0 1 1
In this example, msg
consists of 12 entries, which are interpreted as three four-digit (since k
= 4) messages. The resulting vector code
comprises three six-digit (since n
= 6) codewords, which are concatenated to form a vector of length eighteen.
Binary Matrix Format
You can also organize coding information so as to emphasize the grouping of digits in a single message or codeword. The code below illustrates this by listing each four-digit message on a separate row in msg
and each six-digit codeword on a separate 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 msg = 1 0 0 1 1 0 1 0 1 0 1 1 code code = 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 1 1
For all coding techniques except Reed-Solomon, the message matrix must have k
columns. The corresponding code matrix has n
columns.
Reed-Solomon Coding Using Binary Matrix Format. For Reed-Solomon codes, the message matrix must have m columns, where m is an integer greater than or equal to 3 that satisfies n
= 2m-1.
Decimal Format
Another way to process the same information is to regard each of the three rows of msg
and code
above as binary representations of decimal integers. MATLAB then accepts the corresponding decimal integers as valid messages, and returns decimal integers as codewords.
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') code = 36 21 54
Note The three examples above used cyclic coding. The formats for messages and codes are similar for Hamming, generic linear, and BCH codes. |
Reed-Solomon Coding Using Decimal Format. For Reed-Solomon coding using decimal formats, the message matrix must have k
columns. Each entry in the matrix must be an integer between 0 and n
. The example below illustrates the decimal format for Reed-Solomon coding using the encode
command.
m = 3; n = 2^m-1; k = 4; % Set codeword length and message length. msgdec = [1 6 4 1; 0 0 4 3]; % Message is a decimal matrix. % Code will be a decimal vector. codedec = encode(msgdec,n,k,'rs/decimal') codedec = 0 4 3 1 6 4 1 3 7 5 0 0 4 3
Exponential Format (Reed-Solomon Code Only)
For Reed-Solomon coding using exponential formats, the message matrix must have k
columns. Each entry of the matrix must be an integer between -1 and n
-1. The example below is the exponential-form counterpart of the Reed-Solomon example from the previous section.
m = 3; n = 2^m-1; k = 4; % Set codeword length and message length. msg = [0 5 3 0; -1 -1 3 2]; % Message is an exponential-form matrix. % Code will be an exponential-form matrix. code = encode(msg,n,k,'rs/power');
The name "exponential format" comes from one of MATLAB's standard formats for elements of GF(2m). This format uses integers from -1 to 2m-2, where the symbol -Inf
is sometimes substituted for -1. See Exponential Format for definitions.
![]() | Block Coding Terminology | Representing Block Coding Parameters | ![]() |