The software described in this document is furnished under a license agreement. The software may be used
or copied only under the terms of the license agreement. No part of this manual may be photocopied or
reproduced in any form without prior written consent from The MathW orks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation
by, for, or through the federal government of the United States. By accepting delivery of the Program
or Documentation, the government hereby agrees that this software or documentation qualifies as
commercial computer software or commercial computer software documentation as such terms are used
or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and
conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern
theuse,modification,reproduction,release,performance,display,anddisclosureoftheProgramand
Documentation by the federal government (or other entity acquiring for or through the federal government)
and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the
government’s needs or is inconsistent in any respect with federal procurement law, the government agrees
to return the Program and Docu mentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
The MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
June 2001Online onlyNew for Version 2.0.2 (Release 12.1)
July 2002First printingRevised for Version 2.5 (Release 13)
June 2004Online onlyRevised for Version 3.0 (Release 14)
October 2004Second printingRevised for Version 3.0.1 (Release 14SP1)
March 2005Online onlyRevised for Version 3.1 (Release 14SP2)
August 2005Third printingMinor Revision for V ersion 3.1
September 2005 Online onlyRevised for Version 3.2 (Release 14SP3)
March 2006Online onlyRevised for Version 3.3 (Release 2006a)
September 2006 Online onlyRevised for Version 3.4 (Release 2006b)
March 2007Online onlyRevised for Version 3.5 (Release 2007a)
September 2007 Online onlyRevised for Version 3.6 (Release 2007b)
March 2008Fourth printingMajor Revision for Version 4.0 (Release 2008a)
October 2008Online onlyRevised for Version 4.1 (Release 2008b)
March 2009Online onlyRevised for Version 4.2 (Release 2009a)
September 2009 Online onlyRevised for Version 4.3 (Release 2009b)
March 2010Online onlyRevised for Version 4.4 (Release 2010a)
Running a Simulink Model .........................2-2
Section Overview
Opening the Model
Overview o f the Model
Quadrature Amplitude Modulation
Running a Simulation
Displaying the Error Rate
Setting Block Parameters
Displaying a Plot of Phase Noise
More Demos
Building a Simple Model
Section Overview
Using commstartup to Set Simulation Parameters
Opening a New Model Window
Opening Block Libraries
Moving Blocks into the Model Window
Connecting Blocks
Setting Block Parameters
Setting Simulation Parameters
Running the Model
Adding Noise to the Model
Saving a Model
Frames and Frame-Based Processing
..................................2-2
................................2-2
.............................2-3
...................2-4
..............................2-5
..........................2-6
...........................2-7
.....................2-8
...................................... 2-10
........................... 2-11
..................................2-11
...... 2-12
...................... 2-12
............................ 2-13
................ 2-14
.................................2-15
........................... 2-16
...................... 2-17
................................2-18
.......................... 2-19
...................................2-21
................. 2-22
v
Discrete Signals and Sample Times ...................2-22
Continuous Signals
................................2-22
Building a Channel Noise Model
Section Overview
Overview o f the Model
Selecting Blocks for the Channel Noise Model
Setting Parameters in the Channel Noise Model
Connecting the Blocks
Running the Channel Noise Model
Reducing the Error Rate Using a Hamming Code
Section Overview
Building the Hamming Code Model
Using the Hamming Encoder and Decoder Blocks
Setting Parameters in the Hamming Code Model
Labeling the Display Block
Running the Hamming Code Model
Displaying Frame Sizes
Adding a Scope to the Model
Setting Parameters in the Expanded Model
Observing Channel Errors with the Scope
Modeling a Channel with Modulation
Section Overview
Building the BPSK Model
Setting Parameters in the BPSK Model
Running the BPSK Model
..................................2-24
............................. 2-24
.............................. 2-27
..................................2-30
.......................... 2-33
............................ 2-34
..................................2-39
........................... 2-39
........................... 2-41
.................... 2-24
.......... 2-25
........ 2-26
................... 2-28
................... 2-31
................... 2-33
........................ 2-34
............ 2-35
............. 2-37
............... 2-39
............... 2-41
..... 2-30
....... 2-32
....... 2-32
viContents
Reducing the Error Rate with a Cyclic Code
Section Overview
Building the Cyclic Code Model
Running the Cyclic Code Model
Verifying the Symbol Period
Using a Probe Block to Determine Symbol Period
Building a Frequency-Shift Keying Model
Section Overview
Building the FSK Mo de l
Setting Parameters in the FSK Model
Running the FSK Model
Learning About Delays in the Model
Learning About Multirate Models
Using Sample Time Colors to Check Sample Times
.................... 2-52
...... 2-53
Building a Convolutional Code Model
Section Overview
Building the Convolutional Code Model
Understanding the Blocks in the Model
Setting Parameters in the Convolutional Code Model
Running the Convolutional Code Model
..................................2-54
............... 2-54
............... 2-54
............... 2-55
............... 2-57
Using Communications Blockset Software with
MATLAB
3
SendingDatatotheMATLABWorkspace ............3-2
Section Overview
Using a Signal To Workspace Block
Configuring the Signal To Workspace Block
Viewing the Error Rate Data in the Workspace
Sending Signal and Error D ata to the Workspace
Viewing the Signal and Error Data in the Workspace
Analyzing Signal and Error Data
..................................3-2
...................3-2
............3-3
.........3-3
.......3-4
.....................3-6
.... 2-56
....3-5
Running Simulations from the Command Line
Section Overview
Running a Single Simulation
Running Multiple Simulations
Plotting the Results of Multiple Simulations
Running Multiple Simulations Using BERTool
Importing Data from the MATLAB Workspace
Section Overview
Simulating a Signal by Importing Data
Simulating Noise with Imported Data
Simulating Noise with Specified Error Patterns
Setting Sample Times and Samples per Frame
Learning More
..................................3-7
........................3-7
.......................3-8
........... 3-10
..................................3-13
................ 3-13
................. 3-14
....................................3-19
.......3-7
......... 3-10
....... 3-13
......... 3-15
......... 3-16
vii
Online Help ...................................... 3-19
Demos
The MathWorks Online
.......................................... 3-19
............................ 3-20
List of Examples
A
Getting Started ....................................A-2
Index
viiiContents
Introduction
• “Communications Blockset Product Overview” on page 1-2
• “Installing Communications Blockset Software” on page 1-3
1
1 Introduction
Communications Blockset Product Overview
The Communications Blockset product extends Simulink®software with a
comprehensive library of blocks to design and simulate the physica l layer
of communication systems and components. The blockset helps you design
communications systems and their semiconductor components, such as
commercial or defense wireless and wireline systems.
The key feature s of the blockset are
• Blocks for designing and simulating the physical layer of communications
systems, including modulation, source and channel encoding, channels,
and equalization
• The ability to tune models and visualize the results
• Hierarchical, block-based models for visually conveying complex designs
• Integration with Communications Toolbox™ software for posts imulation
analysis
1-2
Installing Communications Blockset™ Software
Installing Communications Blockset Software
To build and run the models in this manual, you mu s t first install
Communications Blockset™ software and the products it requires, which
are listed below:
• MATLAB
• Simulink Software
• Signal Processing Toolbox™ Software
• Communications Toolbox Software
• Signal Processing Blockset™ Software
You can find instructions for insta ll in g these products in the MATLAB
installation documentation for your platform. To determine what products
are installed on your system, enter
This displays information about the version of MATLAB you are running,
including a list of all toolboxes an d blocksets installed on your system.
®
Software
ver in the MATLAB Command Window.
1-3
1 Introduction
1-4
Building Models
This chapter introduces you to Simulink and Communications Blockset
software. The chapter begins by showingyouhowtorunanexistingSimulink
model and how to build a simple model. It then explains how to build typical
models of communication systems using Communications Blockset software.
These models sho w you how to use the blockset and illustrate some of its
important features.
• “Running a Simulink Model” on page 2-2
• “Building a Simple Model” on page 2-11
2
• “Building a Channel Noise Model” on page 2-24
• “Reducing the Error Rate Using a Hamming Code” on page 2-30
• “Modeling a Channel with Modulation” on page 2-39
• “Reducing the Error Rate with a Cyclic Code” on page 2-42
• “Building a Frequency-Shift Keying Model” on page 2-47
• “Building a Convolutional Code Model” on page 2-54
2 Building Models
Running a Simulink Model
In this section...
“Section Overview” on page 2-2
“Opening the M odel” on page 2-2
“Overview of the Model” on page 2-3
“Quadrature Amplitude Modulation” on page 2-4
“Running a Simulation” on page 2-5
“Displaying the Error Rate” on page 2-6
“Setting Block Parameters” on page 2-7
“Displaying a Plot of Phase Noise” on page 2-8
“More Demos” on pag e 2-10
Section Over view
This section describes a demo model of a communications system that comes
with Communications Blockset software. The model displays a scatter plot of
a signal with added noise. The purpose of this section is to familiarize you
with the basics of Simulink models and how they function.
2-2
The section takes you through some key elements of working with this model.
Opening the Model
To open the m odel, first start MATLAB. In the M ATLA B Command Window ,
enter
commphasenoise at the prompt. This opens the model in a new window,
as shown in the following figure.
Running a Simulink®Model
Overview of the Model
The Simulink model shown in the preceding section, “Opening the Model”
on page 2-2, simulates the effect of phase noise on quadrature amplitude
modulation (QAM) of a signal. The Simulink model is a graphical
representation of a mathematical model of a communication system that
generates a random signal, modulates it using QAM, and adds noise to
simulate a channel. The model also contains components for displaying the
symbol error rate and a scatter plot of the modulated signal.
The blocks and lines in the Simulink model describe mathematical
relationships among signals and states:
• The Random Integer Generator block, labeled Random Integer, generates a
signal consisting of a sequence of random integers between zero and 255
• The Rectangular QAM Modulator Baseband block, to the right of the
Random Integer Generator block, modulates the sig nal using b aseband
256-ary QAM.
• The AWGN Channel block models a noisy channel by adding white
Gaussian noise to the modulated signal.
2-3
2 Building Models
• The Phase Noise block introduces noise in the angle of its complex input
signal.
• The Rectangular QAM Demodulator Baseband block, to the right of the
Phase Noise block, demodulates the signal.
In addition, the following blocks in the model help you interpret the
simulation:
• The Discrete-Time Scatter Plot Scope block, labeled AWGN plus Phase
Noise, displays a scatter plot of the signal with added noise.
• The Error Rate Calculation block counts symbols that differ between the
received signal and the transmitted signal.
• The Display block, at the far right of the model window, displays the
symbol error rate (SER), the total number of errors, and the total number
of symbols processed during the simulation.
All these blocks are included in Communications Blockset and Simulink
applications. You can find more detailed information about these blocks by
right-clicking the block and selecting Help from the context menu.
2-4
Quadrature Amplitude Modulation
This model simulates quadrature amplitude modulation (QAM), which is
amethodforconvertingadigitalsignaltoacomplexsignal. Themodel
modulates the signal onto a sequence of complex numbers that lie on a lattice
of points in the complex plane, called the constellation of the signal. The
constellation for baseband 256-ary QAM is shown in the following figure.
Running a Simulink®Model
Constellation for 256-ary QAM
Running a Simulation
To run a simulation, select Simulation > Start from the top of the model
window. The simulation stops automatically at the Stop time,whichis
specified in the Configuration Parameters dialog box. You can stop the
simulation at any time by selecting Stop from the Simulation menu at the
top of the model window (or, on Microsoft Windows, by clicking the Stop
buttononthetoolbar).
When you run the model, a new window appears, displaying a scatter p lot of
the modulated signal with added noise, as shown in the following figure.
2-5
2 Building Models
2-6
Scatter Plot of Signal Plus Noise
The points in the scatter plot do not lie exactly on the constellation shown in
thefigureConstellationfor256-aryQAMonpage2-5becauseoftheadded
noise. Theradialpatternofpointsisduetotheadditionofphasenoise,which
alters the angle of the complex modulated signal.
Displaying the Error Rate
The Display block displays the number of errors introduced by the channel
noise. When you run the simulation, three small boxes appear in the block,
as shown in the following figure, displaying the vector output from the Error
Rate Calculation block.
Error Rate Display
The block displays th e output as follows:
• The first entry is the symbol error rate ( SER).
• The second entry is the total number of errors.
Running a Simulink®Model
• The third entry is the total number of comparisons made. The notation
1e+004 is shorthand for 10
4
.
Setting Block Parameters
You can control the way a Simulink block functions by setting its parameters.
To view or change a block’s parameters, double-click the block. This opens a
dialog box, sometimes called the block’s mask. For example, the dialog box for
the Phase Noise block is shown in the following figure.
Dialog for the Phase Noise Block
To change the am ount of phase noise, click in the Phase noise level
(dBc/Hz) field and enter a new value. Then click OK.
Alternatively, you can enter a variable name, such as
phasenoise,inthe
field. You can then set a value for that variable in the MATLAB Command
Window, for example by entering
phasenoise = 2. Setting parameters in the
Command Window is convenient if you need to run multiple simulations with
different parame ter values. See the section “Running Multiple Simulations”
on page 3-8.
2-7
2 Building Models
You can also change the amount of noise in the AWGN Channel block.
Double-click the block to open its dialog box, and change the value in the
Es/No parameter field. This changes the signal to noise ratio, in dB.
Decreasing the value of Es/No increases the noise level.
You can experiment with the model by changing these or other parameters
and then running a simulation. For example,
• Change Phase noise level (dBc/Hz) to
Phase Noise block.
• Change Es/No to
This removes nearly all noise from the model. W hen you now run a
simulation, the scatter plot appears as in the figure Constellation for 256-ary
QAM on page 2-5.
100 in the dialog for the AWGN Channel block.
-150 in the dialog box for the
Displaying a Plot of Phase Noise
Double-click the block labeled “Disp la y Figure” at the bottom left of the model
window. Thisdisplaysaplotshowingthe results of multiple simulations.
2-8
Running a Simulink®Model
Plot of BE
Each cur
fixed am
You can
values
Multip
scrip
R at Different Noise Levels
ve is a plot of bit error rate as a function of signal to noise ratio for a
ount of phase noise.
create plots like this by running multiple simula tions with different
for the Phase noise level (dBc/Hz) and Es/No parameters. “Running
le Simulations” on page 3-8 describes how to do this with a MATLAB
t, using variables for the parameters.
2-9
2 Building Models
More Demos
You can find Communications Blockset demos in the M A TLAB Help browser.
1 To open the Help browser, type doc at the MATLAB command line.
2 To see a list of demo categories, expand the Communications Blockset
node in the Help browser, then click the Demos node.
The Communications Blockset display in the Help browser.
You can find more demos for the Simulink software by typing
MATLAB command line.
demo at the
2-10
Building a Simple Model
In this section...
“Section Overview” on page 2-11
“Using commstartup to Set Simulation Parameters” on page 2-12
“Opening a New Model W indow” on page 2-12
“Opening Block Libraries” on page 2-13
“Moving Blocks into the Model Window” on page 2-14
“Connecting Blocks” on page 2-15
“Setting Block Parameters” on page 2-16
“Setting Simulation Parameters” on page 2-17
“Running the Model” on page 2-18
“Adding Noise to the Model” on page 2-19
“Saving a Model” on page 2-21
Building a Simple Model
“Frames and Frame-Based Processing” on page 2-22
“Discrete Signals and Sample Times” on page 2-22
“Continuous Signals” on page 2-22
Section Over view
In the previous section, you ran a model that was already built. This section
explains how to build a simple Simulink model that displays a sine wave in
ascope.
Building a model usually involves several iterations, as you decide which
blocks to include and what parameter settings to make. In the example in
this section, you refine the model by adding noise.
For more detailed information on building models, see the Simulink
documentation.
2-11
2 Building Models
Using commstart
Before starting
commstartup
at the M ATLAB p
This
• Sets the Simu
• Sets default
models
Communicat
data types
types, suc
Communica
model. Th
current M
each MATL
If you bu
to use Si
the mod
ild a model without entering
mulink blocks that output signals with Boolean data types, turn off
el’s Boolean logic signals parameter by entering
to build the model, enter
rompt.
link Boolean logic s ignals parameter to
simulation parameters that are optimal for communications
ions Blockset software does not support signals with Boolean
. If you want to use Simulink b locks that output Boolean data
h as the Logical Operator block, in a model with blocks from
tions Blockset software, enter
e
commstartup settings apply to any models you create d uring the
ATLAB session. You must enter
AB session to establish these settings.
up to Set Simulation Parameters
Off
commstartup before buildin g the
commstartup at the beginning of
commstartup and subsequently decide
2-12
set_param('my_model', 'BooleanDataType', 'off')
where
Openi
The f
sele
mode
my_model.mdl is the name of the model.
ng a New Model Window
irst step in building a model is to open a new model window. To do so,
ct File > New > M odel,andthenselectModel. This opens an empty
l window, as shown in the following figure.
Building a Simple Model
Opening Block Libraries
The next step is to select the blocks for the model. These blocks are contained
in libraries. To view the libraries for the products you have installed, type
simulink at the MATLAB prompt (or click the Simulink buttonon the
MATLAB toolbar). The Simulink Library Browser appears.
2-13
2 Building Models
2-14
Simulink Library Browser
The left pane displays the installed products, each of which has i ts own library
of blocks. To open a library, click the + signnexttothenameoftheblockset
in the left pane. This displays the contents of the library in the right pane.
You can find the blocks you need to build models of communication systems in
Communications Blockset, Signal Processing Blockset, and Simulink libraries.
Moving Blocks into the Model Window
The next step in building the model is to move blocks from the Simulink
Library Browser into the model window. To do so,
1 Click the + sign next to Signal Processing Blockset intheleftpaneof
the Library Browser. This displays a list of the Signal Processing Blockset
libraries.
Building a Simple Model
2 Click Signal Processing Sources in the left pane. This displays a list of
the Signal Processing Sources library blocks in the right pane. If you do not
see the Sine Wa ve block, scroll down the list until it is visible.
3 Click the Sine Wave block and drag it into the model window.
4 Click Signal Processing Sinks intheleftpaneoftheLibraryBrowser.
5 Scroll down in the right pane of the Library Browser until you see the
Vector Scope block, and drag the block into the model window to the right
oftheSineWaveblock.
Once a block is in the model window, you can move it to another position by
dragging the block with the mouse.
Dragging a Block into a Model Window
Connecting Blocks
The small arrowhead pointing outward from the right side of the Sine Wave
block is an output port for the data the block generates. The arrowhead
pointing inward on the Vector Scope block is an input port. To connect the two
blocks, click the output port of the Sine Wave block and drag the mouse toward
the input port of the Vector Scope block, as shown in the following figure.
2-15
2 Building Models
When the pointer is on the input port of the Vector Scope block, release the
mouse button. You should see a solid arrow appear, as in the following figure.
Ifyoudonotseeasolidarrowhead,youhavenotmadeaconnection. Inthis
case, click the arrowhead again, drag it a ll the way to the Vector Scope’s input
port, and release the mouse button.
2-16
Setting Block Parameters
To set parameters for the Sine Wave block, double-click the block to open its
dialog box, as shown in the following figure. Change the following parameters
by clicking in the field next to the parameter, deleting the default setting, and
entering the new setting in its place:
1 Set Amplitude to 5.
2 Set Frequency to 30.
3 Set Samples per frame to 100.
4 Click OK.
Note You must set Samples per frame to a value larger than 1 to see an
image of the sine wave in the Scope block.
Building a Simple Model
Dialog Box for the Sine Wave Block
Setting Simulation Parameters
In addition to individual block parameters, the model also has overall
simulation parameters. To view the current settings,
1 Select the Simulation menu at the top of the model window.
2 Select Configuration parameters to open the Configuration
Parameters dialog box, as shown in the following figure.
2-17
2 Building Models
Configura
If you typ
inf
set to
Setting S
stop it b
The Stop
run tim
and you
The set
param
To conserve memory in a model, click Data Import/Export on the left,
Note
lear the boxes next to Time and Output under Save to workspace
and c
eright.
on th
ning the Model
Run
the model by selecting Simulation > Start. When you do so, a scope
Run
ndow appears, displaying a sine wave, as shown in the following figure.
wi
tion Parameters Dialog Box
ed
commstartup before creating the model, the Stop time should be
.TheStop time determinesthetimeatwhichthesimulationends.
top time to
y selecting Stop from the Simulation menu.
time is not the actual time it takes to run a simulation. The actual
e for a simulation depends on factors such as the model’s complexity
r computer’s clock speed.
tings in the Configuration Parameters dialog box affect only the
eters of the current model.
inf causes the simulation to run indefinitely, until you
2-18
Building a Simple Model
Sine Wave Displayed in a Scope
Note If you do not see the sine wave in the scope, make sure that the
Samples per frame parameterfortheSineWaveblockissetto
100.
When you are finished observing the simulation, select Simulation > Stop.
Adding Noise to the Model
You can add noise to the model using the AWGN Channel block, from the
Channels library of Communications Blockset software. The block adds white
Gaussian noise to the sine wave. Move the block from the Simulink Library
Browser into the model window, as described in “Moving Blocks into the
Model Window” on page 2-14. You can add the block to the model as follows:
1 Extend the line between the Sine Wave block and the Vector Scope block by
dragging the Vector Scope block to the right, to make room for the AWGN
Channel block.
2-19
2 Building Models
2 Click the AWGN block and drag it onto the line. This automatically
connects the Sine Wave block and the Vector Scope block to the AWGN
Channel block.
Sine Wave Plus Noise
Double-click the AWGN Channel block to open its dialog box, as shown in the
following figure. Click the down arrow in the Mode field and select
to noise ratio (SNR)
.
Signal
2-20
Dialog for the AWGN Channel Block
Now when you run the model, the scope clearly shows the added noise.
Building a Simple Model
Sine Wave with Noise Added
When you are finished observing the simulation, stop the model by selecting
Simulation > Stop.
Saving a Model
To sav e your mo de l for future use, select File > Save.Thefirsttimeyousave
the model, this displays the Save As dialog box. In the Save in field, select
thefolderwhereyouwanttosavethemodel. Itisbesttokeepyourworkfiles
in a separate folder from the files shipped with the product. In the File name
field, enter a name for the model, such as
To load the model in a future MATLAB session, first change your working
folder to the one where you saved the file. You can do this by selecting the
folder in the Current Folder field on the MATL AB toolbar. Then enter
in the MATLAB Command Window.
sine.mdl,andclickSave.
sine
2-21
2 Building Models
Frames and Frame
A frame is a seque
Samples per fram
100, so that eac
block to displa
Another impor
Blockset bloc
connect a sou
you can set th
required val
Hamming Cod
In frame-ba
simultane
processed
can greatl
blocks, t
sed processing, all the samples in a frame are processed
ously. In sample-based processing,ontheotherhand,samplesare
one at a time. The advantage of frame-based processing is that it
y increase the speed of a simulation. If you see d ouble lines between
he model uses frame-based processing.
Discrete
The Sine
discret
of a fixe
this ti
In the e
Sample
and Si
These
syste
Wave block in Signal Processing Blockset software generates a
e signal. This means that it updates the signal at integer multiples
d time interval, called the sample time. Y ou can set the length of
me interval in the Sample time parameter in the block’s dialog box.
xample described in “Building a Simple Model” on page 2-11, the
time has the default value of
gnal Processing Blockset source s generate discrete signals exclusively.
sources are primarily designed for modeling digital communication
ms.
nce of samples combined into a single vector. By setting
e to
h frame contains 100 samples. This enables the Vector Scope
yenoughdataforagoodpictureofthesinewave.
tant reason to set the frame size is that many Communications
ks require their inputs to be vectors of specific sizes. If you
rce block, such as the Sine Wave block, to one of these blocks,
e input size correctly by setting Samples per frame to the
ue. The model described in “Reducing the Error Rate U sing a
e” on page 2-30 shows how to do this.
Signals and Sample Times
-Based Processing
100 in the Sine W ave block, yo u set th e frame size to
1/1000. All Communications Blockset
2-22
arn more about sample times, see “Building a Frequency-Shift Keying
To le
l” on page 2-47.
Mode
tinuous Signals
Con
Simulink libraries also c on tain blocks that generate continuous signals.
The
s means that they update the signal at variable time intervals, whose
Thi
ngth is determined by the numerical solver the simulation uses. For
le
Building a Simple Model
example, the Sine Wave block in the Simulink Sources library can generate a
continuous sine wave.
Note Many blocks in Communications Blockset software a ccept only discrete
signals. To find out whether a block accepts continuous signals, consult the
reference page f or the block.
2-23
2 Building Models
Building a Channel Noise Model
In this section...
“Section Overview” on page 2-24
“Overview of the Model” on page 2-24
“Selecting Blocks for the Channel Noise Model” on pag e 2-25
“Setting Parameters in the Channel Noise Model” on page 2-26
“Connecting the Blocks” on page 2-27
“Running the Channel Noise Model” on page 2-28
Section Over view
This section shows how to build a simple model of a communication system.
The model, shown in the following figure, contains the most basic elements of
a communication system: a source for the signal, a channel with noise, and
means of detecting errors caused by noise.
2-24
Channel Noise Model
You are encouraged to build the model for yourself, as this is the best way to
learn how to use Communications Blockset software.
Overview of the Model
The channel noise model generates a random binary signal, and then switches
the symbols 0 and 1 in the signal, according to a specified error probability, to
simulate a channel with noise. The model then calculates the error rate and
displays the result. The model contains the following components.
Building a Channel Noise Model
Source
The source for the signal in this model is the Bernoulli Binary G enerator
block, which generates a random binary sequence.
Channel
The Binary Sy mmetric Channel blo ck simulates a channel with noise. The
block introduces random errors to the signal by changing a 0 to a 1 or the
reverse, with a probability specified by the Error probability parameter
in the block’s dialog.
Error Rate Calculation
The Error Rate Calculation block calculates the error rate of the channel. The
block has two input ports, labeled
the received signal. The block compares the two signals and checks for errors.
The output of the block is a vector with three entries:
• Bit error rate, which you expect to be approximately .01, because this is the
probability of error in the channel
Tx, for the transmitted signal, and Rx, for
• Number of errors
• Total number of bits that are transmitted
Display
The Display block displays the output of the Error Rate Calculation block, as
described in “Displaying the Error Rate” on page 2-6.
Selecting Blocks for the Channel Noise Model
To bu il d the model, f irst move i ts blocks into a new mo del win do w, as fol low s:
1 Type commstartup at the MATLAB prompt to set simulation parameters
for the model.
2 Type simulink attheMATLABprompttoopentheSimulinkLibrary
Browser.
3 From the menu, select File>New>Modelto open a new model window.
2-25
2 Building Models
4 Drag the following blocks from the Simulink Library Browser into the
model window:
• Bernoulli Binary Generator block, from the Random Data Sources
sublibrary of the Comm Sources library
• Binary Symmetric Channel block, from the Channels library
• Error Rate Calculation block, from the Comm Sinks library
• Display block, from the Simulink Sinks library
Setting Parameters in the Channel Noise Model
To set block parameters in the channel noise model, do the following:
1 Double-click the Bin a r y Symmetric Channel b lock and make the following
changes to the default parameters in the block’s dialog:
• Set Error probability to
• Clear the Output error vector check box. This removes the b lo ck’s
lower output port, which is not needed for this model.
2 Double-click the Error Rate Calculation block and make the following
changes to the default parameters in the block’s dialog:
• Set Output data to
• Select Stop simulation.
0.01.
Port to create a n output port for the block.
2-26
Building a Channel Noise Model
Selecting Stop simulation causesthesimulationtostopafterthetarget
number of errors occurs or the maximum number of symbols is reached.
Initial Seeds
The Bernoulli Binary Generator block and the Binary Symmetric Channel
block both use a random number generator to generate random sequences
of bits. In both blocks, the Initial seed parameter initializes the random
sequence. The initial seeds in the two blocks should have different values
to ensure that the source signal and the channel noise are statistically
independent. In general, initial seeds should have different va lu es in all
blocks that have an Initial seed parameter.
Connecting the Blocks
Next, connect the blocks as shown in the following figure. Make sure to
connect the arrow from the Binary Symmetric Channel block to the input port
labeled
“Connecting Blocks” on page 2-15.
Rx on the Error Rate Calculation block. To learn how to do this, see
2-27
2 Building Models
The next section explains how to draw the upper branch line in the model.
Drawing a Branch Line
The upper line leading from the Bernoulli Binary Generator block to the Error
Rate Calculation block, shown in the following figure, is called a branch line.
Branch lines carry the same signal to more than one block.
To draw the branch line, follow these steps:
1 Right-click the line between the Bernoulli Random Generator block and th e
3 Release the mouse button. The end of the branch line should connect to the
input port of the Error Rate Calculation block.
4 Click the horizontal section of the branch line and drag it upward until the
line is above the Binary Symmetric Channel block.
Tx on the Error Rate Calculation block.
2-28
The model should now appear as in the following figure.
Running the Channel Noise Model
To run the model, select Simulation > Start. After a few seconds, the model
stops automatically.
To see all three boxes in the Display block, you must enlarge the block
slightly, as follows:
Building a Channel Noise Model
1 Select the Display block and move the mouse pointer to one of the lower
corners of the block, so that a diagonal arrow appears on the corner, as
shown.
2 Drag the corn
appear, as sh
er of the block down with the mouse until three windows
own.
The Display block displays the following information:
• Bit error rate
• Number of errors
• Total number of bits that are transmitted
The exact values that appear will vary, depending on the Initial seed
parameters in the Bernoulli Binary Generator block and the Binary
Symmetric Channel block.
Because the Target number of errors in the dialog box for the Error Rate
Calculation block is set to
100, the simulation stops when 100 errors have
been detected.
To save the model, select File > Save, type a name for the model, such as
channelnoise,intheFile name fi eld, and click Save.
2-29
2 Building Models
Reducing the Error Rate Using a Hamming Code
In this section...
“Section Overview” on page 2-30
“Building the Hamming Code M odel” on page 2-31
“Using the Hamming Encoder and Decoder Blocks” on page 2-32
“Setting Parameters in the Hamming Code Model” on page 2-32
“Labeling the Display Block” on page 2-33
“Running the Hamming Code Model” on page 2-33
“Displaying Frame Sizes” on page 2-34
“Adding a Scope to the Model” on page 2-34
“Setting Parameters in the Expanded Model” on page 2-35
“Observing Channel Errors with the Scope” on page 2-37
2-30
Section Over view
This section describes how to reduce theerrorrateinthemodelshowninthe
figureChannelNoiseModelonpage2-24 by adding an error-correcting code.
The following figure shows an example that uses a Hamming code.
Hamming Code Model
You are encouraged to build the model for yourself. Alternatively, to open a
completed version of the model, type
doc_hamming at the MATLAB prompt.
Reducing the E rr or Rate Using a Hamming Code
Building the Ham
You can build the
in the figure Cha
1 Type doc_chann
model. Then sa
your work file
2 Drag the following two Communications Blockset blocks from the Simulink
Hamming code model by adding blocks to the model shown
nnel Noise Model on page 2-24. To do so, follow these steps:
el
ve the model as
s. See “Saving a Model” on page 2-21.
ming Code Model
at the MATLAB prompt to open the channel noise
my_hamming in the folder where you keep
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 B
block, an
creates
blocks n
inary Symmetric Channel block, the Error Rate Calculation
d the Display block to the right by clicking and dragging. This
more space between the Binary Symmetric Channel block and the
ext 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 Symm etric Channel block.
2-31
2 Building Models
6 Click the Hamming Decoder block and drag it on top o f the line between
the Binary Symmetric Channel block and the Error Rate Calculation block.
Using the Hamming Encoder and Decoder Blocks
The Hamming Encoder block encodes the data before it is sent through the
channel. The default code is the [7,4] Hamming code, which encodes message
words of length 4 into codewords of length 7. As a result, the block converts
frames of size 4 into frames of size 7. The code can correct one error in each
transmitted codeword.
For an [n,k] code, the input to the Hamming Encoder block must consist of
vectors of size k. In this example, k = 4.
2-32
The Hamming Decoder block decodes the data after it is sent through the
channel. If at most one error is created in a codeword by the channel, the
block decodes the word correctly. However, if more than one error occurs, the
Hamming Decoder block might decode incorrectly.
To learn more about the Communications Blockset block coding features, see
“Block Coding” in the online documentation for Communications Blockset.
Setting Parameters in the Hamming Code Model
Double-click the Bernoulli Binary Generator block and make the following
changestotheparametersettingsintheblock’sdialogbox,asshowninthe
following figure:
1 Select the box next to Frame-based outputs.
Samples per frame to
2 Set
mes of size 4, in order to meet the input requirement of the Hamming
fra
coder Block. See “Frames and Frame-Based Processing” on page 2-22
En
r more information about frames.
fo
4. This converts the output of the block into
Reducing the E rr or Rate Using a Hamming Code
Note Many Communications Blockset blocks, such as the Hamming
Encoder block, require their input to be a vector of a specific size. If you
connect a source block, such as the Bernoulli Binary Generator block, to
one of these blocks, select the box next to Frame-based outputs in the
dialog for the source, and set Samples per frame to the required value.
Labeling the Display Block
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.
Running the Hamming Code Model
To run the model, select Simulation > Start. The model terminates after
100 errors occur. The error rate, displayed in the top window of the Display
block, is approximately .001. You get slightly different results if you change
the Initial seed parameters in the model or run a simulation for a different
length of time.
You expect an error rate of approximately .001 for the following reason: The
probability of two or more errors occurring in a codew ord of length 7 is
1 – (0.99)
7
–7(0.99)6(0.01) = 0.002
2-33
2 Building Models
If the codewords with two or more errors are decoded randomly, you expect
about half the bits in the decoded message words to be incorrect. This
indicates that .001 is a reasonable value for the bit error rate.
To obtain a lower error rate for the same probability of error, try using a
Hamming code with larger parameters. To do this, change the parameters
Codeword length and Message length in the Hamming Encoder and
Decoderblockdialogboxes. Youalsohavetomaketheappropriatechanges
to the parameters of the Bernoulli Binary Generator block and the Binary
Symmetric Channel block.
Displaying Frame Sizes
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
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 l abeled
[4x1], indicat in g that its output consists o f column vectors of size 4.
[7x1].
2-34
Displaying Frame Sizes
Adding a Scope to the Model
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 exampleshowninthefollowingfigure
shows where to insert the Scope block into the m odel.
Reducing the E rr or Rate Using a Hamming Code
To build this model from the one shown in the figure Hamming Code Model
on page 2-30, follow these steps:
1 Drag the following blocks from the Simulink Library Browser into the
model window:
• Relational Operator block, from the Simulink Logic and Bit Operations
library
• Scope block, from the Simulink Sinks library
• Two copies of the Unbuffer block, from the Buffers sublibrary of the
Signal Processing Blockset Signal Management library
2 Double-click the Binary Symm etri c Channel block to open its dialog box,
and select Output error vector. This creates a second output port for the
block, which carries the error vector.
3 Double-click the Scope block and click the Parameters buttonon the
toolbar. Set Number of axes to
4 Connect the blocks as shown in the p receding figure. To learn how to do
2 and click OK.
this, see “Connecting Blocks” on page 2-15 and “Drawing a Branch Line”
on page 2-28.
Setting Parameters in the Expanded Model
Makethefollowingchangestotheparameters for the blocks you added to
the model.
2-35
2 Building Models
Error Rate Calculation Block
Double-click the Error Rate Calculation block and clear the box next to Stop
simulation in the block’s dialog box.
Scope Block
The Scope block displays the channel errors and uncorrected errors. To
configure the block,
1 Double-click the block to open the scope, if it is not already open.
2 Click the Parameters buttonon the toolbar.
3 Set Time range to 5000.
4 Click the Data history tab.
5 Type 30000 in the Limit data points to last field, and click OK.
The scope should now appear as shown.
2-36
To configure the axes, follow these steps:
1 Right-click the v ertical axis at the left side of the upper scope.
he context menu, select Axes properties.
2 In t
3 In the Y-min field, type -1.
Reducing the E rr or Rate Using a Hamming Code
4 In the Y-max field, type 2,andclickOK.
5 Repeat the same steps for the vertical axis of the lower scope.
6 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.
Observing Channel Errors with the Scope
When you run the model, the Scope block displays the error d ata. 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 n ext 5000 data points.
e with Model Running
Scop
pper scope shows the channel errors generated by the Binary Sym metric
The u
nnel block. The lower scope shows errors that are not corrected by
Cha
nnel coding.
cha
ick the Stop button on the toolbar at the top of the model window to stop
Cl
escope.
th
2-37
2 Building Models
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.
Zooming In on the Scope
2-38
The wider rectangular pulse in the middle of the upper scope represents two
1s. These two errors, w hich 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.
“Sending Signal and Error Data to the Workspace” on page 3-4 explains how
to send the error data to the MATLAB workspace for more detailed analysis.
Modeling a Channel with Modulation
In this section...
“Section Overview” on page 2-39
“Building the BPSK Model” on page 2-39
“Setting Parameters in the BPSK Model” on page 2-41
“Running the BPSK Model” on page 2-41
Section Over view
The Binary Symmetric Channel block, which simulates a channel with
noise, is useful for building models of channel coding. For other types of
applications, you might want to construct a more realistic model of a channel.
For example, you can add modulation and demodulation, and replace the
Binary Symmetric Channel block with an AWGN Channel block, which adds
white Gaussian noise to the channel. The following figure shows an example
that uses binary phase shift keying (BPSK).
Modeling a Channel with Modulation
BPSK Modulation Model
You are encouraged to build the model for yourself. Alternatively, to open a
completed version of the model, type
doc_bpsk at the MATLAB prompt.
Building the BPSK Model
You can build the BPSK model from the one shown in the figure Channel
Noise Model on page 2-24. To b uild t he model, follow these steps:
1 Enter doc_channel attheMATLABprompttoopenthechannelnoise
model, and then save the model as
your work files.
my_bpsk in the folder where you keep
2-39
2 Building Models
2 Delete the Binary Symmetric C hannel block from the model by
right-clicking the block and selecting Clear.
3 Move the following blocks from the Simulink Library Browser into the
model window, and insert them into the model a s shown in the following
figure:
• BPSK Modulator Baseband block, from PM in the Digital Baseband
Modulation sublibrary of the M od ulation library
• AWGN Channel block, from the Channels library
• BPSK Demodulator Baseband block, from PM in the Digital Baseband
Modulation sublibrary of the M od ulation library
The model should now appe ar as in the figure below .
2-40
Binary Phase Shift Keying
The BPSK Modulator and Demodulator Baseband blocks implement binary
phase shift keying (BPSK) modulation. BPSK is a method for modulating a
binary signal onto a complex waveform by shifting the phase of the complex
signal. In digital baseband BPSK, the symbols 0 and 1 are modulated to the
complex numbers exp(jt) and -exp(jt), respectively, where t is a fixed angle. In
this example, t = 0, so these numbers are just 1 and -1.
You can set the value of t in the Phase offset parameter in the dialog
boxes for the BPSK Modulator Baseband block and the BPSK Demodulator
Baseband block. The default value is
To learn more about the Communications Blockset digital modulation
features, see “Digital Modulation” in the online Communications Blockset
documentation.
0.
Modeling a Channel with Modulation
Setting Paramet
To set block para
1 Double-click t
2 Double-click the Error Rate Calculation block and make the following
changes to the default parameters in the block’s dialog:
• Set Output data to
• Select the box next to Stop simulation.
meters in the BPSK model, do the following:
he AWGN Channel block and set Es/No to
ers in the BPSK Model
4.2.
Port.
Running the BPSK Model
When you run the model, the Display block shows an error rate of
approximately 0.01, the same as in the channel noise model. The BPSK model
uses the BPSK Modulator Baseband, the AWGN Channel, and the BPSK
Demodulator Baseband blocks to simulate a channel with noise. This provides
a more realistic model of a channel than using just the Binary Symmetric
Channel block. You can also model other types of channel noise using blocks
from the Communications Blockset Channels library.
2-41
2 Building Models
Reducing the Error Rate with a Cyclic Code
In this section...
“Section Overview” on page 2-42
“Building the Cyclic Code Model” on page 2-42
“Running the Cyclic Code Model” on page 2-44
“Verifying the Symbol Period” on page 2-44
“Using a Probe Block to Determine Symbol Period” on page 2-45
Section Over view
YoucanimprovetheerrorrateinthemodelshowninthefigureBPSK
Modulation Model on page 2-39, for certain nois e levels, by adding channel
coding. An example that uses a binary cyclic code is shown below.
2-42
Building the Cyclic Code Model
You can build the cyclic code model by adding blocks to the BPSK model
shown in the figure BPSK Modulation Model on page 2-39. To build the
model, follow these steps:
1 Open the BPSK model by entering doc_bpsk at the MATLAB prompt. Save
the model as
2 Double-click the AWGN Channel block and s et Es/No to 7. This value is
chosen for this example to illustrate the benefit of using a code. If E
much lower than the value chosen here, then the E
by the additional coded bits will be greater than the coding gain provided
by the code.
my_cyclic in the folder where you keep your work files.
reduction caused
s/N0
s/N0
is
Reducing the Error Rate with a Cyclic Code
3 Run the simulation and note its error rate (for later comparison in
“Running the Cyclic Code Model” on page 2-44). The error rate appears in
the top entry of the Display block.
4 To introduce cyclic coding, drag these Communications Blockset blocks
from the Simulink Library Browser into the model window:
• Binary Cyclic Encoder block, from the Block sublibrary of the Error
Detection and Correction library
• Binary Cyclic Decoder block, from the Block sublibrary of the Error
Detection and Correction library
5 Widen the model window and connect the blocks as below.
6 Double-click the Bernoulli Binary Generator block and change these
parameters:
• Select Frame-based outputs.
• Set Samples per frame to
21 to match the input requirement of the
Binary Cyclic Encoder block.
7 Double-click the Binary Cyclic Encoder block and change these parameters:
• Set Codeword length N to
• Set Message length K to
31.
21.
Make the same changes in the Binary Cyclic Decoder block.
8 Double-click the AWGN Channel block and change these parameters:
• Set Es/No to
7+10*log10(21/31). The second term in this sum accounts
for the difference in symbol period compared to the original BPSK model.
• Set Symbol period to
21/31. For more information on setting Symbol
period,see“VerifyingtheSymbol Period” on page 2-44.
2-43
2 Building Models
With these parameter values, the AWGN channel block produces the same
amount of noise per symbol as in the BPSK model (without coding) in
which Es/No is
how much the cyclic code improves the bit error rate.
9 Double-click the Error Rate Calculation block and change this parameter:
7. The equivalence of the noise enables you to determine
• Set Maximum number of symbols to
simulation, producing a more reliable estimate for the error rate .
1e7.Thisextendsthe
Binary Cyclic Encoder and Decoder
The Binary Cyclic Encoder block implements a binary cyclic code. In this
example, the block has the following parameter settings:
• Codeword length N =
• Message length K = 21
Thecoderateisgivenby
Code rate
This example uses a rate 21/31 code. The codeword length N must have the
form 2
block must be a vector whose length is Message length.
The Binary Cyclic Decoder block decodes the demodulated signal. This block
must have the same parameter settings as the Binary Cyclic Encoder block.
M
- 1, where M is an integer greater than or equal to 3. The input to the
Message length
=
Codeword length
31
2-44
Running the Cyclic Code Model
When you run the simulation, the bit error rate is less than one-tenth of the
error rate in the model that does not have channel coding.
Verifying the Symbol Period
When you compare the cyclic code model to the BPSK model, which does
not have channel coding, the ratio of energy per information symbol to noise
spectral density, E
, should be the same in both models. You can u se the
b/N0
Reducing the Error Rate with a Cyclic Code
Symbol period and Es/No parameters in the AWGN Channel block to adjust
the amount of channel n oise so that E
coding. Because the cyclic code has rate 21/31, set Symbol period to
For a BPSK simulation with a rate K / N code, set Symbol period to
isthesameasinthemodelwithout
b/N0
21/31.
K/N
because there are K information symbols for each N channel symbols.
Note that Es/No, the ratio of energy per channel symbol to noise spectral
density, is not the same as E
EN ENKN
//log(/)
bs
00
10=−
. To convert between the two, use the formula
b/N0
where K / N is the ratio of information symbols to channel symbo ls. Changing
the Symbol period to
K/N has the same effect as subtracting 10*log10(K / N)
from the Es/No parameter.
Using a Probe Block to Determine Symbol Period
If you are unsure how to set the Symbol period, you can find the correct
value using a Probe block. To do so, follow these steps:
1 Drag these blocks from the Simulink Library Browser into the cyclic code
model window:
• Probe block, from the Simulink Signal Attributes library
• Two copies of the Terminator block, from the Simulink Sinks library
2 Double-click the Probe block and change thes e parameters:
• Clear the boxes next to Probe complex signal and Probe signal
dimensions.
• Select the boxes next to Probe width and Probe sample time.The
block now has two output ports.
3 Connect the blocks as shown in the next figure.
4 Select Edit > Update diagram. Simulink updates the display on the
Probe block, as in the next figure.
2-45
2 Building Models
The number after W in the Probe block tells you the frame size, which in this
case is 31. The first number after
You can determine the symbol period using the following formula.
Tf tells you the frame period, which is 21.
Symbol period
In this example, the symbol period is 21/31.
Frame period
=
Frame size
2-46
Building a Frequency-Shift Keying Model
In this section...
“Section Overview” on page 2-47
“Building the FSK Model” on page 2-48
“Setting Parameters in the FSK Model” on page 2-49
“Running the FSK Model” on page 2-50
“Learning About Delays in the Model” on page 2-51
“Finding the Delay in a Model” on page 2-51
“Learning About Multirate Models” on page 2-52
“Using Sample Time Colors to Check Sample Times” on page 2-53
Section Over view
Frequency-shift keying (FSK) is a standard modulation technique in which a
digital signal is modulated onto a sinusoidal carrier whose frequency shifts
between different values. The Bell Telephone System first used this technique
in their Model 103 modem. The model shown in the following figure is an
example of the baseband representation of FSK.
Building a Frequency-Shift Keying Model
FSK Model
2-47
2 Building Models
To open a completed version of t he model, type doc_fsk at the MATLAB
prompt.
Building the FSK Model
You can build the FSK model by adding blocks to the model shown in the
figure Channel Noise Model on page 2-24. To open the channel noise model,
enter
doc_channel at the MATLAB prompt. Then save the model as my_fsk in
the folder where you keep your work files. See “Saving a Model” on page 2-21.
You need to add the following blocks to the model:
M-FSK Modulator and Demodulator Baseband
The M-FSK Modulator Baseband block, from FM in the Digital Baseband
sublibrary of the Modulation library, modulates the binary signal using a
baseband representation of FSK modulation.
The M-FSK Demo dulator Baseband block, from FM in the Digital Baseband
sublibrary of the Modulation library, demodulates the base band signal.
2-48
AWGN Channe l
The AWGN Channel block, from the Channels library, models a channel using
additive white Gaussian noise. In this model, AWGN is more suitable than a
binary symmetric channel.
Relational Operator
The Relational Operator block, from the Simulink Logic and Bit Operations
library, compares the transmitted signal, from the Bernoulli Binary Generator
block, with the received signal, from the M-FSK Demodulator Baseband block.
The block outputs a 0 when the two signals agree, and a 1 when they differ.
Scope
The Scope block, from the Simulink Sinks library, displays the transmitted
signal, the received signal, and the output of the Relational Operator block.
To create three input ports for the block, follow these steps:
1 Double-click the block to open the scope.
Building a Frequency-Shift Keying Model
2 Click the Parameters buttonon the toolbar.
3 Set Number of axes to 3.
4 Set Time range to 1 and click OK.
To set the limits on the vertical axes,
1 Right-click the v ertical axis at the left side of the upper scope.
2 In the context menu, select Axes properties.
3 In the Y-min field, type -1.
4 In the Y-max field, type 2,andclickOK.
Repeat these steps for the middle and lower vertical axes.
Delay
The Delay block, from the Signal Processing Blocks et Signal Operations
library, delays the transmitted signal so that it can be accurately compared
with the received signal. Its purpose is explained further in “Learning About
Delays in the Model” on page 2-51.
Drag these blocks into the model window and connect them as shown in the
figure FSK Model on page 2-47. Remove the Binary Symmetric Channel
block becaus e it is no longer needed. The next section explains how to set the
parameters for these blocks.
Setting Parameters in the FSK Model
Make the following changes to the default parameter settings in the dialog
boxes for the blocks:
1 Double-click the Bernoulli Binary Generator block and make the following
changes to the default parameters in the block’s dialog box:
• Set Probability of a zero to
• Set Sample time to
1/1200.
0.5.
2-49
2 Building Models
2 Double-click the M-FSK Modulator Baseband block and make the following
changes to the default parameters in the block’s dialog box:
• Set M-ary number to
2. This specifies the number of frequencies in
the modulated signal.
• Set Frequency separation to
1000.Thisspecifiestheseparation
between the two frequencies of the modulated signal.
• Set Samples per symbol to
5. This causes the block to oversample
the incoming signal. Oversampling increases the sampling rate by a
factor of 5.
3 Double-click the M-FS K Demodulator Baseband block and make the same
changes to the block’s default parameters as for the M-FSK Modulator
Baseband block.
4 Double-click the AWGN Channel block and set Symbol period to 1/12 00.
5 Double-click the Error Rate Calculation block and make the following
changes to the default parameters in the block’s dialog box:
• Set Receive delay to
• Set Output data to
1.
Port.
Running the FSK Model
Set the Stop time parameter to 15 and run the model.
2-50
Displaying the Errors in the Scope
Double-click the Scope block to open the scope.
Building a Frequency-Shift Keying Model
The top window displays the transmitted signal. The middle window displays
the received signal. The bottom windowdisplaysa0wherethetwosignals
agree and a 1 where they differ.
Learning About Delays in the Model
Some blocks cause a signal to be delayed as it passes through a model,
because of the way they process data. For example, there is a delay of one
symbol period between the input signal to the M-FSK Modulator Baseband
block and the output signal from the M-FSK Demodulator Baseband block. As
a result, there is a delay of 1 between the transmitted and r eceived signals
in the model. “Finding the Delay in a Model” on page 2-51 shows how to
find the value of this delay.
Tocomparethesetwosignalsandcalculate the bit error rate correctly, you
need to delay the transmitted signal by 1 to synchronize it with the received
signal. ThisiswhyyousettheReceive delay to
Error Rate Calculation block, and left the Delay at its default value of
the Delay block.
1 in the dialog box for the
1 in
Note If the Error Rate Calculation block in a model gives an error rate close
to .5 for a random binary signal, you might not have taken into account delays
in the model. The block is probably comparing two unsynchronized signals.
Several blocks in the Communications Blockset Modulation library produce
delays. A list of these is given in “Delays in Digital Modulation” in the online
Communications Blockset documentation. The Viterbi D ecoder block, from
the Convolutional sublibrary of the Error Detection and Correction library,
also produces a delay equal to its Traceback depth parameter; see the
section “Viterbi Decoder” on page 2-56.
Finding the Delay in a Model
To find the delay between the transmitted and received signals in a model,
youcanuseaFindDelayblock. Todoso,insertthefollowingblocksinto
the FSK model:
• Find Delay, from the Utility Blocks library
2-51
2 Building Models
• Display, from the Simulink Sinks library
Connect the blocks as shown at the top right of the following figure.
2-52
When you run the simulation, the Display block labeled Display shows
that the delay is 1. You can use this information to set the Receive delay
parameter in the Error Rate Calculation block and the Delay parameter in
the Delay block.
Learning About Multirate Models
The model shown in the figure FSK Model on page 2-47 diffe rs from the
earlier models in that it contains signals with different sample times. The
Bernoulli Binary Generator block has a sample time of
Modulator Baseband block receives this signal and upsamples it at a rate of
five samples per symbol. As a result, the sample time of the block’s output
signal is 1/6000. A m odel that contains signals with different sample times
is called a multirate model.
The multiple sample times present in this model do not affect the bit error
rate of a simulation. But be aware that in other models, sample times can
affect the results of a simulation. This is usually the case when different
signals a re combined. See “Setting Sample Times and Samples per Frame”
on page 3-16 for an example of this.
1/1200.TheM-FSK
Building a Frequency-Shift Keying Model
Using Sample Tim
You can easily ch
selecting: FormDiagram.Wheny
according to th
Red blocks and
indicates the
different sa
blocks and li
time colors,
For frame-b
signals rat
If you need
aProbeblo
Period” o
her than sample times.
n page 2-45.
eck whether there are different sample times in a model by
at > Sample Time Display.Next,selectEdit > Update
ou do this, blocks and lines in the model are colored
eir sample times.
lines indicate the fastest sample time in the model. Green
second fastest sample time. Yellow blocks contain signals with
mple times. If all sample times in the model are the same, all
nes are colored red. For more information on displaying sample
see the Simu link documentation.
ased signals, the colors correspond to the frame p eriods of the
to determine the actual sample time of a signal, you can use
ck as described in “Using a Probe Block to Determine Symbol
e Colors to Check Sample Tim es
2-53
2 Building Models
Building a Convolutional Code Model
In this section...
“Section Overview” on page 2-54
“Building the Convolutional Code Model” o n page 2-54
“Understanding the Blocks in the Model” on page 2-55
“Setting Param eters in the Convolutional Code Model” on page 2-56
“Running the Convolutional C ode Model” o n page 2-57
Section Over view
The following model simulates the use of convolutional coding to send a signal
through a channel with noise.
2-54
Convolutional Code Model
To open a completed version of the model, enter doc_conv at the MATLAB
prompt.
Building the Convolutional Code Model
You can build the convolutional code model by adding blocks to the model
shown in the figure Channel Noise Model on page 2-24.
To build the model, follow these steps:
1 Enter doc_channel at the MATLAB Help browser to open the channel
noise model. Then save the model as
your work files.
elete the Binary Symmetric Channel block.
2 D
my_conv in the f older where y ou keep
Building a Convolutional Code Model
3 Drag the following blocks from the Simulink Library Browser into the
model window, and connect them as shown in the figure Convolutional
Code Model on page 2-54:
• Convolutional Encoder, from the Convolutional sublibrary of the Error
Detection and Correction library
• BPSK Modulator Baseband, from PM in the Digital Baseband
Modulation sublibrary of the M od ulation library
• Complex to Real-Imag, from the Simulink Math Operations library
• Viterbi Decoder, from the Convolutional sublibrary of the Error
Detection and Correction library
Understanding the Blocks in the Model
This model contains the blocks discussed in the following subsections.
Convolutional Encoder
The Convolutional Encoder block encodes the signal from the Bernoulli Binary
Generator. The example uses the industry standard rate 1/2 convolutional
code, with constraint length 7, defined by the following diagram.
First output
Input
1
1
-1
Z
1
1
-1
Z
1
1
-1
Z
1
0
-1
Z
00
0
-1
Z
Z
1
1
-1
1
Second output
Convolutional Encoder Schematic Block Diagram
The e ncoder structure is described by a pair of binary numbers, having the
same le ngth as the code’s constraint length, that specify the connections from
the delay cells t o modulo-2 addition nodes. The binary number for the upper
addition node is 1111001. A 1 indicates that the bit in the corresponding
delay cell (reading from left to right) is sent to the addition node, and a 0
2-55
2 Building Models
indicates that the bit is not sent. The binary number for the lower addition
node is 1011011. Converting these two binary numbers to octal gives the
pair [171,133]. You can enter this pair into the block’s dialog box by typing
poly2trellis(7, [171 133]) in th e field for Trellis Structure.
To learn more about the Communications Blockset convolutional coding
features, see “Convolutional Coding” in the online Communications Blockset
documentation.
Complex to Real-Imag
The Complex to Real-Imag block, labeled Re(u), receives the complex signal
and outputs its real part. Because the output BPSK Modulator Baseb an d
block has zero complex part, all of the signal is carried by the real part. You
can set this option by selecting
block’s dialog box. It is not necessary to demodulate the signal, because the
Viterbi Decoder block can accept unquantized inputs.
Real in the Output parameter fie ld in the
Viterbi Decoder
The Viterbi Decoder block decodes the signal using the Viterbi algorithm. The
Decision Type parameter is set to
real numbers from the Complex to Real-Imag block. The Traceback depth
parameter, which is set to
the b lock uses to construct each traceback path. This produces a delay of
between the input and output of the block. For more information on delays,
see “Finding the Delay in a Model” on page 2-51.
96, is the number of branches in the trellis that
Unquantized so that the block can accept
96
2-56
For an example of a convolutional coding model that uses soft-decision
decoding, see “Example: Soft-Decision Decoding” in the online
Communications Blockset documentation.
Setting Parameters in the Convolutional Code Model
To set parameters in the convolutional code model, do the following:
1 Double-click the Bernoulli Binary Generator block and select the box next
to Frame-based outputs in the block’s dialog box.
2 Double-click the AWGN Channel block and make the following changes to
the default parameters in the block’s dialog box:
• Set Es/No to -1.
Building a Convolutional Code Model
• Set Symbol period to
1/2. Becausethecoderateis1/2,thissetting
causes the block to produce the sam e amount of noise per channel symbol
as it would without channel coding. For more information, see “Verifying
the Symbol Period” on page 2-44.
3 Double-click the Error Rate Calculation block and make the following
changes to the default parameters in the block’s dialog box:
• Set Receive delay to
96. The Viterbi Decoder block creates a delay of
96,duetoitsTraceback depth setting.
• Select the box next to Stop simulation.
• Set Target number of errors to
100.
Running the Convolutional Code Model
When you run the model, you observe an error rate of approximately .003.
2-57
2 Building Models
2-58
UsingCommunications
BlocksetSoftwarewith
MATLAB
This chapter describe s how to use MATLAB to extend the capabilities of
Communications Blockset. The chapter explains how to run simulations from
the command line, and how to run multiple simulations. It also explains how
to transfer data between a modelandtheMATLABworkspace.
3
• “Sending Data to the MATLAB Workspace” on p age 3-2
• “Running Simulations from the Command Line” on page 3-7
• “Importing Data from the MATL AB Workspace” on page 3-13
• “Learning More” on page 3-19
3 Using Communications Blockset™ Software with MATLAB
®
Sending D ata to the MATLAB Workspace
In this section...
“Section Overview” on page 3-2
“Using a Signal To Workspace Block” on page 3-2
“Configuring the Signal To Workspace Block” on page 3-3
“Viewing the Error Rate Data in the Workspace” on page 3-3
“Sending Signal and Error Data to the Workspace” on page 3-4
“Viewing the Signal and Error Data in the Workspace” on page 3-5
“Analyzing Signal and Error Data” on page 3-6
Section Over view
This section explains h ow to send data from a Simulink model to the MATLAB
workspace so you can analyze the results of simulations in greater detail.
3-2
Using a Signal To Workspace Block
You can use a Signal To Workspace block, from Signal Processing Sinks
library of the Signal Processing Blockset application to send data to the
MATLAB workspace as a vector. For example, you can send the error rate
data from the Hamming code model, described in the section “Reducing the
Error Rate Using a Hamming Code” on page 2-30. To insert a Signal to
Workspace block into the m ode l, follow these steps:
1 Type doc_h ammi ng at the MATLAB Help browser to open the model.
2 Drag a Signal To Workspace block, from the Signal P rocessing Sinks
library, into the model window and connect it as shown in the following
figure.
Sending Data to the MATLAB®Works p ace
Hamming Code Model with a Signal To Workspace Block
Configuring the Signal To Workspace Block
To configure the Signal to Workspace block, follow these steps:
1 Double-click the block to display its dialog box.
2 Type hammcode_BER in the Variable name field.
3 Type 1 in the Limit data points to last field. This limits the output vector
to the values at the final time step of the simulation.
4 Click OK.
When you run a simulation, the model sends the output of the Error Rate
Calculation block to the workspace as a vector of size 3, called
After running a simulation, you can view the output of the Signal to
Workspace block by typing the following commands at the MATLAB prompt:
format short e
hammcode_BER
The vector output is the following:
hammcode_BER =
5.4066e-0031.0000e+0021.8496e+004
3-3
3 Using Communications Blockset™ Software with MATLAB
The command format short e displays the entries of the vector in
exponential form. The entries are as follows:
• The first entry is the error rate.
• The second entry is the total number of errors.
• The third entry is the total number of comparisons made.
Sending Signal and Error Data to the Workspace
To analyze the error-correction performance of the Hamming code, send the
transmitted signal, the received signal, and the error vectors, created by the
Binary Symmetric Channel block, to the workspace. An example of this is
shown in the following figure.
®
3-4
Sending Signal and Error Data to the Workspace
You can build this model from the one shown in the figure Hamming Code
Model on page 2-30. To build the model, follow these steps:
1 Type doc_hamming to open the model.
2 Doub
3 Drag three Signal To Workspace blocks, from the Signal Processing Sinks
le-click the Binary Symmetric Channel block to open its dialog box,
elect Output error vector. This creates an output port for the
and s
r data.
erro
library, into the model window and connect them as shown in the preceding
figure.
4 Double-click the left Signal To Workspace block.
Sending Data to the MATLAB®Works p ace
• Type Tx in the Variable nam e field in the block’s dialo g box. T he b lock
sends the transmitted signal to the workspace as an array called
Tx.
• In the Frames field, select
preserves each frame as a separate column of the array
Log frames separately (3-D array).This
Tx.
• Click OK.
5 Double-clickthemiddleSignalToWorkspaceblock:
• Type
• In the Frames field, select
errors in the Variable name field.
Log frames separately (3-D array).
• Click OK.
6 Double-click the right Signal To Workspace block:
• Type
• In the Frames field, select
Rx in the Variable name field.
Log frames separately (3-D array).
• Click OK.
Viewing the Signal and Error Data in the Workspace
After running a simulation, you can display individual frames of data. For
example, to display the tenth frame of
Tx(:,:,10)
This returns a column vector of length 4, corresponding to the length of a
message w ord. Usually, you should not type
the entire transmitted signal, which is very large.
Tx, at the M A TLAB prompt type
Tx by itself, because this displays
To display the corresponding frame of errors, type
errors(:,:,10)
This returns a column vector of length 7, corresponding to the length of
a codeword.
To display frames 1 through 5 of the transmitted signal, type
Tx(:,:,1:5)
3-5
3 Using Communications Blockset™ Software with MATLAB
Analyzing Signal and Error Data
You can use M ATLA B to analyze the data from a simulation. For example, to
identify the differences between the transmitted and received signals, type
diffs = Tx~=Rx;
The vector di ffs is the XOR of the vectors Tx and Rx.A1indiffs indicates
that
Tx and Rx differ at that position.
You can determine the indices of frames corresponding to message words that
are incorrectly decoded with the following MATLAB command:
error_indices = find(diffs);
A 1 in the vector not_equal indicates that there is at least one difference
between the corresponding frame o f
records the indices where Tx and Rx differ. To view the first incorrectly
decoded word, type
®
Tx and Rx.Thevectorerror_indices
3-6
Tx(:,:,error_indices(1))
To view the corresponding frame of errors, type
errors(:,:,error_indices(1))
Analyze this data to determine the error patterns that lead to incorrect
decoding.
Running Simulations from the Command Line
Running Simulations from the Command Line
In this section...
“Section Overview” on page 3-7
“Running a Single Simulation” on page 3-7
“Running Multiple Simulations” on page 3-8
“Plotting the Results of Multiple Simula t ions” on page 3-10
“Running Multiple Simulations Using BERTool” on page 3-10
Section Over view
This section describes how to run simulations from the command line using
the
sim command. This is especially useful for running multiple simulations
on a model.
Running a Single Simulation
As an example, to run the phase noise model, described in “Running a
Simulink Model” on page 2-2, from the command line, enter
sim('commphasenoise')
in the MATLAB Command Window. This runs the model in the background
without opening the model window. While the simulation is running, the
MATLAB prompt is unavailable and you cannot enter another MATLAB
command.
After the simulation stops, the p rompt reappears. You can then view the
results of the simulation by typing
It is not necessary to open the model window when running a simulation from
the command line. Usually you want to send the results of the simulation to
the MATLAB workspace, for example, if you are running multiple simulations
on a single model.
You can also specify simulation parameters from the command line. For
example, the command
commphasenoise to open the model.
3-7
3 Using Communications Blockset™ Software with MATLAB
sim('commphasenoise', 1000);
runs the model with a Stop time of 1000. This overrides the Stop time
setting in the Configuration Parameters dialog box. For more information on
running simulations, see the Simulink documentation.
Running Multiple Simulations
Youcanrunmultiplesimulations,with different parameters, from the
command line using a MATLAB script. This section describes how to run the
phase noise model with varying amounts of channel noise.
Preparing the Model
1 Type commphasenoise to open the model.
2 Drag a Signal To Workspace block, from the Signal P rocessing Sinks
library, into the model window and connect it as shown in the following
figure.
®
3-8
Phase Noise Model with a Signal To Workspace Block
3 Double-click the Signal To Workspace block and make these changes in
the block’s dialog box:
• Set Variable name to
• Set Limit data points to last to
ect Simulation > Configuration parameters and set Stop time to
4 Sel
.
inf
phase_err.
1.
Running Simulations from the Command Line
5 Enter the following commands in the MATLAB Command Window. This
creates variables for the simulation’s stopping criteria, as well as a vector
of E
6 Double-click the AWGN Channel block and set Es/No to EbNo+10*log10(8)
in the block’s dialog box. The variable EbNo represents the bit energy to
noise ratio. The term
10*log10(8) converts EbNo to Es/No,whichisthe
symbol energy to noise ratio. The 8 appears because there are eight bits
per channel symbol in 256-QAM.
7 Double-click the Error Rate Calculation block and make the following
changes in the block’s dialog box:
• Select Stop simulation.
• Set Target number of errors to
• Set Maximum number of symbols to
8 Save the model in your working folder under a different file name, such as
my_commphasenoise.
maxNumErrs.
maxNumBits.
Running the Simulation Multiple Times
Now that the model and variables are set up, you can run multiple
simulations, each with a different Es/No parameter. The following script runs
the simulations in a loop and stores the results in a matrix called
The simulations might take several minutes to run.
When the simulations have ended and the prompt reappears, enter the
following at the MATLAB prompt:
SER_Vec.
3-9
3 Using Communications Blockset™ Software with MATLAB
format short e
SER_Vec
This displays the results in a matrix. Each row is the output of the Error Rate
Calculation block for a single simulation. The first column, which gives the
error rates for each simulation, decreases, because the n oise level decreases
as
EbNo increases. The last column gives the number of symbols processed in
each simulation.
Plotting the Results of Multiple Simulations
Plot the symbol error rates by en tering the following commands.
The BERTool graphical user interface in Communications Toolbox can run
multiple Simulink simul ati on s and create a BER plot. This section de scrib es
Running Simulations from the Command Line
how to use BERTool with a modified commphasenoise model. For more
general instructions on using BERTool, see the BERTool section of the
Communications Toolbox documentation.
To create a BER plot for the phase noise model using BERTool, follow these
steps:
1 Follow the procedure in “Preparing the Model” on page 3-8, if you have not
already done so.
EbNo, maxNumErrs,andmaxNumBits are special variable
names that BERTool recognizes.
2 Drag two Integer to Bit Converter blocks from the Utility Blocks library
into the model. Insert them before the Error Rate Calculation block, as
shown below. This causes the Error Rate Calculation block to compute
a bit error rate instead of a symbol error rate. BERTool is designed to
compute bit error rates.
3 Double-click each of the Integer to Bit Converter blocks and set Number
of bits per integer to
4 Save the model in your working folder as my_commphasenoise_ber.mdl.
5 Open th
Windo
6 Click the Monte Carlo tab.
7 Make the following changes in the GUI:
e BERTool GUI by entering
w.
• Set Eb/No range to
• Set Simulation M-file or model to
• Set BER variable name to
• Set Number of errors to
8 in the dialog boxes.
bertool in the MATLAB Command
EbNoVec.
my_commphasenoise_ber.mdl.
phase_err.
200.
3-11
3 Using Communications Blockset™ Software with MATLAB
• Set Number of bits to 10^5.
8 Click Run.
BERTool runs the simulation multiple times, gathers bit error rate results,
and produces a plot like the following. (Although the shape resembles the plot
shown in “Plotting the Results of Mul t iple Si mulations” on page 3-10, the plot
there shows symbol error rates while the plot here shows bit error rates.)
®
3-12
Importing Data from the MATLAB®Works p ace
Importing Data from the MATLAB Workspace
In this section...
“Section Overview” on page 3-13
“Simulating a Signal by Importing Data” on page 3-13
“Simulating Noise with Imported Data” on page 3-14
“Simulating Noise with Specified Error Patterns” on page 3-15
“Setting Sample Times and Samples per Frame” on page 3-16
Section Over view
This section explains how to import data into a model directly from the
MATLAB workspace using the Signal From Workspace block, from the Signal
Processing Sources library. This enables you to run simulations on data that
you create in the workspace or import from outside MATLAB. You can also
create specific error patterns, such as burst errors, and import them into a
model to test error correction codes.
Simulating a Signal by Importing Data
To import a signal that you create in the workspace, you can use a Signal
From Workspace block as a source. An example is the model shown in the
following figure. This model is the same as the one shown in the figure
Channel Noise Model on page 2-24, except that the Bernoulli Binary
Generator block has been replaced with a Signal From Workspace block.
Importing a Signal from the Workspace
To build this model, follow these steps:
3-13
3 Using Communications Blockset™ Software with MATLAB
1 Enter doc_channel attheMATLABprompttoopenthechannelnoise
model. Then save it under a different name in the directory where you
keep your work files.
2 Replace the Bernoulli Binary Generator block with a Signal From
Workspace b lock, from the Signal Processing Sources library.
3 In the Signal from Workspace block’s dialog, change the Signal parameter
to
data (or another variable name).
®
Before using the model, define the vector
For example, type
defines
data as a random binary vector of length 10
data=randint(1,10^4); at the MATLAB prompt. This
data in the MATLAB w orkspace.
4
.
Next, select Simulation > Configuration Parameters and set the Stoptime parameter to
imports the random vector
Change the vector
length(data). Whenyourunasimulation,themodel
data into the model.
data in the MATLAB workspace to simulate a less random
signal, or import a signal from outside MATLAB.
Simulating Noise with Imported Data
You can also use the Signal From W orkspace block to simulate channe l noise
with specific error patterns, in order to test the performance of an error
correcting code. An example of this is shown in the following figure.
3-14
Using Data from the Workspace to Simulate Errors
Importing Data from the MATLAB®Works p ace
This example is similar to the model shown in the figure Hamming Code
Model on page 2-30, but instead of using the Binary Symmetric Channel block
to simulate noise, the model imports error data from the workspace.
To build this model, follow these steps:
1 Type doc_hamming at the MATLAB prompt to open the Hamming code
model. Then save the model under a different name in the folder where you
store your work files.
2 Delete the Binary Symmetric Channel block from the model.
3 Drag the following blocks into the model window:
• A Signal From Workspace block, from the Signal Processing Sources
library
• A Logical Operator block, from the Simulink Math Operations library
4 Connect these blocks as shown in the preceding figure.
5 Select Simulation > Configuration Parameters to open the
Configuration Parameters dialog box.
6 Type length(errors) in the Stop time field and click OK.
7 Double-click the Signal From Workspace block and make the following
changes to the default parameters in the block’s dialog box:
• Set Signal to
• Set Sample time to
• Set Samples per frame to
errors.
4/7.
7, to match the frame size of the signal
coming out of the Hamming Encoder block.
8 Double-click the Logical Operator block and set Operator to XOR in the
block’s dialog box.
Simulating Noise with Specified Error Patterns
To use the model in the figure Using Data from the Workspace to Simulate
Errors on page 3-14, you must first create a binary vector called
workspace to represent errors in the channel. A 1 in the vector represents
errors in the
3-15
3 Using Communications Blockset™ Software with MATLAB
an error in the channel, while a 0 represents no error. When you run a
simulation, the Logical Operator block performs the XOR operation on the
vector
errors and the signal.
®
For example, to create a vector of length 7x10
4
that contains exactly one 1
in each sequence of entries from 7n + 1 to 7(n + 1), enter the following at
the MATLAB prompt:
errors=[];
for n=1:10^4
p=randperm(7);
v=[1000000];
errors=[errors v(p)];
end
The function randperm generates a random permutation of the numbers 1
through 7. The vector
v, w hich has exactly one entry that is 1. The result is that the vector errors
v(p) applies the permutation to the entries of the vector
contains exactly one entry that is 1 in each sequence from 7n + 1 to 7(n+1).
Running a Simulation with Imported Error Data
Whenyourunasimulation,thebiterrorrateiszerobecausetheHamming
code can correct one error in each codeword.
To test the code with an error vector that creates two errors in each codeword,
change the vector
v to v=[1 1 0 0 0 0 0] in the preceding code.
3-16
Setting Sample Times and Samples per Frame
It is important to set the Sample time and Samples per frame parameters
correctly in the Signal From Workspace block, so that the block has the same
frame size and frame period as the Hamming Encoder block. This ensures
that errors coming from the Signal From Workspace block are synchronized
with channel symbols coming from the Hamming Encoder block. To determine
the correct sample time, use the following relationship:
Sample time
Frame period
=
Samples per frame
Importing Data from the MATLAB®Works p ace
The frame size of the signal coming from the Hamming Encoder block is 7.
You set the frame size by the Codeword length parameter in the block’s
dialog box. So you should set the Samples per frame parameter in the
Signal From Workspace block to
7.
The frame period of the Hamming Encoder block is 4, because the Bernoulli
Binary Generator block has a Sample time of
of
4.SosettheSample time parameter in the Signal From Workspace block
to
4/7 so that the frame period of the block is 4.
1 and a Sam ples per frame
If you are not sure what the frame sizes and frame periods of signals in the
model are, you can display them using a Probe block, as described in “Using a
Probe Block to Determine Symbol Period” on page 2-45. To do this, attach two
Probe blocks, one to the line leading out of the Hamming Encoder block and
one to the line leading out of the Signal From Workspace block. In the dialog
boxes for both Probe b lo cks, clear the check boxes next to Probe complexsignal an d Probe signal dimensions. Next, attach Terminator blocks to
the output ports of the Probe blocks. Then select Update diagram from the
Edit menu. The model should appear as in the following figure.
Hamming Code Model with Probe Blocks
Both Probe blocks should display a fram e size of 7 and a frame period of 4.
A quick way to check whether the frame periods of two signals are the same
is to select Sample time colors from the Port/signal displays submenu
3-17
3 Using Communications Blockset™ Software with MATLAB
of the Format menu. See“UsingSampleTimeColorstoCheckSample
Times” on page 2-53.
®
3-18
Learning More
In this section...
“Online Help” on page 3-19
“Demos” on page 3-19
“The MathWorks Online” on page 3-20
Online Help
To find online documentation, select Product Help from the Help menu in
the MATLAB desktop. This launches the Help browser. For a more detailed
explanation of any of the topics covered in this book, see the documentation
listed under Communications Blockset in the left pane of the Help browser.
Besides this book, Communications Blockset Getting Started Guide, the online
documentation contains the following topics:
Learning More
• “Using the Libraries” describes each of the core libraries of the blockset.
• “Modeling Communication Systems” illustrates techniques for modeling a
full communication s ystem .
• “Block Reference” provides descriptions of the Communications Blockset
libraries and lists the blocks in them.
• “Blocks — Alphabetical List” provides a detailed description of the blocks
in C ommunications Blockset software in alphabetical order.
The Help Navigator, in the left pane of the Help browser, supports string
searches. You can specify strings and theonlinemanualsthatyouwantto
search. To begin a search, click the Search tab. To view the index for the
documentation, click the Index tab.
Demos
ToseemoreCommunicationsBlocksetexamples,type
demo
3-19
3 Using Communications Blockset™ Software with MATLAB
at the MATLAB prompt. This opens the MATLAB Demo window. Double-click
Blocksets and then s elect Communications to list the available demos.
The MathWorks Online
To find the Communications Blockset documentation on the MathW orks Web
site, point your Web browser to
Use this list to find examples in the documentation.
A
A List of Examples
Getting Started
“Running a Simul
“Building a Simple Model” on page 2-11
“Building a Channel Noise Model” on page 2-24
“Modeling a Ch
“Reducing the Error Rate with a Cyclic Code” on page 2-42
“Building a Frequency-Shift Keying Model” on page 2-47
“Building a Co
“Sending Data to the MATLAB Workspace” on page 3-2
“Running Multiple Simulations” on page 3-8
“Importing