Communications Toolbox | ![]() ![]() |
Representing Words for Binary Block Codes
Each message or codeword is an ordered grouping of symbols. The next few subsections illustrate the various ways that these symbols can be organized or interpreted as input and output. To process binary codes, see these topics:
Binary Vector Format
For binary codes, 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' 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 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
For binary codes, 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 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
Note
In the binary matrix format, the message matrix must have k columns. The corresponding code matrix has n columns. The parity bits are at the beginning of each row.
|
Decimal Vector Format
For binary codes, 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.
Note When you use the decimal vector format to represent binary words, MATLAB expects the leftmost bit to be the least significant bit. |
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. |
![]() | Block Coding Terminology | Parameters for Binary Block Codes | ![]() |