MATLAB Hamming Codes
MATLAB Hamming Codes
MATLAB Hamming Codes
Objective: to reduce the error rate in Channel Noise Model by using a Hamming
code.
Tools: MATLAB, Simulink, Communications Blockset.
Procedure:
A. Start MATLAB by double-clicking the MATLAB icon or go to start and
program, then search for the MATLAB program folder and then click the
MATLAB.
B. Type in simulink to open a new window. Click on the Communications
Blockset, it will open all sub-libraries of communications.
1. Type channeldoc at the MATLAB prompt to open the channel noise model. Then
save the model as my_hamming in the directory where you keep your work files.
2. Drag the following two Communications Blockset blocks from the Simulink
Library Browser into the model window:
Hamming Encoder block, from the Block sublibrary of the Error Detection
and Correction library
Hamming Decoder block, from the Block sublibrary of the Error Detection
and Correction library
3. Click the right border of the model and drag it to the right to widen the model
window.
4. Move the Binary Symmetric Channel block, the Error Rate Calculation block, and
the Display block to the right by clicking and dragging. This creates more space
between the Binary Symmetric Channel block and the blocks next to it. The model
should now look like the following figure.
5. Click the Hamming Encoder block and drag it on top of the line between the
Bernoulli Binary Generator block and the Binary Symmetric Channel block, to the
right of the branch point, as shown in the following figure. Then release the mouse
button. The Hamming Encoder block should automatically connect to the line
from the Bernoulli Binary Generator block to the Binary Symmetric Channel
block.
6. Click the Hamming Decoder block and drag it on top of the line between the
Binary Symmetric Channel block and the Error Rate Calculation block.
Double-click the Bernoulli Binary Generator block and make the following changes to
the parameter settings in the block's dialog box, as shown in the following figure:
You can change the label that appears below a block to make it more informative. For
example, to change the label below the Display block to "Error Rate Display," first
select the label with the mouse. This causes a box to appear around the text. Enter the
changes to the text in the box.
You can display the sizes of data frames in different parts of the model by selecting
Signal dimensions from the Port/signal displays submenu of the Format menu at the
top of the model window. This is shown in the following figure. The line leading out
of the Bernoulli Binary Generator block is labeled [4x1], indicating that its output
consists of column vectors of size 4. Because the Hamming Encoder block uses a
[7,4] code, it converts frames of size 4 into frames of size 7, so its output is labeled
[7x1].
To display the channel errors produced by the Binary Symmetric Channel block, add a
Scope block to the model. This is a good way to see whether your model is
functioning correctly. The example shown in the following figure shows where to
insert the Scope block into the model.
Make the following changes to the parameters for the blocks you added to the model.
Scope Block
The Scope block displays the channel errors and uncorrected errors. To configure the
block,
Widen the scope window until it is roughly three times as wide as it is high.
You can do this by clicking the right border of the window and dragging the
border to the right, while pressing the mouse button.
Relational Operator
Set Relational Operator to ~= in the block's dialog box. The Relational Operator block
compares the transmitted signal, coming from the Bernoulli Random Generator block,
with the received signal, coming from the Hamming Decoder block. The block
outputs a 0 when the two signals agree and a 1 when they disagree.
When you run the model, the Scope block displays the error data. At the end of each
5000 time steps, the scope appears as shown in the following figure. The scope then
clears the displayed data and displays the next 5000 data points.
The upper scope shows the channel errors generated by the Binary Symmetric
Channel block. The lower scope shows errors that are not corrected by channel
coding.
Click the Stop button on the toolbar at the top of the model window to stop the scope.
To zoom in on the scope so that you can see individual errors, first click the middle
magnifying glass button at the top left of the Scope window. Then click one of the
lines in the lower scope. This zooms in horizontally on the line. Continue clicking the
lines in the lower scope until the horizontal scale is fine enough to detect individual
errors. A typical example of what you might see is shown in the figure below.
The wider rectangular pulse in the middle of the upper scope represents two 1s. These
two errors, which occur in a single codeword, are not corrected. This accounts for the
uncorrected errors in the lower scope. The narrower rectangular pulse to the right of
the upper scope represents a single error, which is corrected.
When you are done observing the errors, select Simulation > Stop.
Explain how to send the error data to the MATLAB workspace for more detailed
analysis.