Communications Blockset | ![]() ![]() |
Examples of Block Coding
This section presents two example models. The first example processes a Hamming code using the binary format and the second example processes a Reed-Solomon code using the integer format.
Example: Hamming Code in Binary Format
This example shows very simply how to use an encoder and decoder. It illustrates the appropriate vector lengths of the code and message signals for the coding blocks. Also, because the Error Rate Calculation block accepts only scalars or frame-based column vectors as the transmitted and received signals, this example uses frame-based column vectors throughout. (It thus avoids having to change signal attributes using a block such as Convert 1-D to 2-D.)
To open the completed model, click here in the MATLAB Help browser. To build the model, gather and configure these blocks:
.5
.
randseed
function.
4
.
Connect the blocks as in the preceding figure. Also, use the Signal dimensions feature from the model window's Format menu. After updating the diagram if necessary (Update diagram from the Edit menu), the connector lines show relevant signal attributes. The connector lines are double lines to indicate frame-based signals, and the annotations next to the lines show that the signals are column vectors of appropriate sizes.
Example: Reed-Solomon Code in Integer Format
This example uses a Reed-Solomon code in integer format. It illustrates the appropriate vector lengths of the code and message signals for the coding blocks. It also exhibits error correction, using a very simplistic way of introducing errors into each codeword.
To open the completed model, click here in the MATLAB Help browser. To build the model, gather and configure these blocks:
15
.
randseed
function.
5
.
15
.
5
.
[0; 0; 0; 0; 0; ones(10,1)]
.
15
.
5
.
|-+
Connect the blocks as in the preceding figure. Also, from the model window's Simulation menu, choose Simulation parameters; then, in the Simulation Parameters dialog box, set Stop time to 500
.
The vector length numbers appear on the connecting lines only if you select Signal dimensions from the model's Format menu. Notice that the encoder accepts a vector of length 5 (which is K in this case) and produces a vector of length 15 (which is N in this case). The decoder does the opposite. Also, the Initial seed parameter in the Random Integer Generator block is a vector of length 5 because it must generate a message word of length 5.
Running the model produces the scope images below. Your plot of the error counts might differ somewhat, depending on your Initial seed value in the Random Integer Generator block. (To make the axis range exactly match that of the left scope in the figure, right-click the plot area in the scope and select Axes properties.)
The plot on the right is the number of errors that the decoder detected while trying to recover the message. Often the number is five because the Gain block replaces the first five symbols in each codeword with zeros. However, the number of errors is less than five whenever a correct codeword contains one or more zeros in the first five places.
The plot on the left is the difference between the original message and the recovered message; since the decoder was able to correct all errors that occurred, each of the five data streams in the plot is zero.
![]() | Using Block Encoders and Decoders Within a Model | Notes on Specific Block Coding Techniques | ![]() |