Académique Documents
Professionnel Documents
Culture Documents
Getting Started
Version 2
Web Newsgroup Technical support Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information Phone Fax Mail
508-647-7000 508-647-7001 The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site. Getting Started with the Communications Blockset COPYRIGHT 2001 by The MathWorks, Inc.
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 MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by or for the federal government of the United States. By accepting delivery of the Program, the government hereby agrees that this software qualifies as "commercial" computer software within the meaning of FAR Part 12.212, DFARS Part 227.7202-1, DFARS Part 227.7202-3, DFARS Part 252.227-7013, and DFARS Part 252.227-7014. The terms and conditions of The MathWorks, Inc. Software License Agreement shall pertain to the governments use and disclosure of the Program and Documentation, and shall supersede any conflicting contractual terms or conditions. If this license fails to meet the governments minimum needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to MathWorks. MATLAB, Simulink, Stateflow, Handle Graphics, and Real-Time Workshop are registered trademarks, and Target Language Compiler is a trademark of The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective holders.
Online only
Contents
Introduction
1
What Is the Communications Blockset? . . . . . . . . . . . . . . . . . 1-2 Related Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Using This Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 Who Should Read This Guide? . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 How to Use This Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6
Building Models
2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 New Simulink Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Building Models of Communication Systems . . . . . . . . . . . . . . 2-2 Running a Simulink Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Overview of the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Quadrature Amplitude Modulation (QAM) . . . . . . . . . . . . . . . . 2-6 Running a Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Error Rate Calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7 Error Rate Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 Setting Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 Displaying a Plot of Phase Noise . . . . . . . . . . . . . . . . . . . . . . . . 2-9 More Demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 Building a Simple Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 The Basic Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Opening Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Moving Blocks into the Model Window . . . . . . . . . . . . . . . . . . . Connecting Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Simulation Parameters . . . . . . . . . . . . . . . . . . . . . . . . . Running the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding Noise to the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Saving the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Finding Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Discrete Signals and Sample Times . . . . . . . . . . . . . . . . . . . . . Continuous Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Frames and Frame-Based Processing . . . . . . . . . . . . . . . . . . . . Building a Channel Noise Model . . . . . . . . . . . . . . . . . . . . . . . Selecting Blocks for the Channel Noise Model . . . . . . . . . . . . . Drawing a Branch Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Resizing a Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labeling a Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Components of the Channel Noise Model . . . . . . . . . . . . . . . . . Running the Channel Noise Model . . . . . . . . . . . . . . . . . . . . . . How Long to Run a Simulation . . . . . . . . . . . . . . . . . . . . . . . . . Choosing Seeds for Random Sources . . . . . . . . . . . . . . . . . . . . Reducing the Error Rate Using a Hamming Code . . . . . . . Building the Hamming Code Model . . . . . . . . . . . . . . . . . . . . . Hamming Encoder and Decoder . . . . . . . . . . . . . . . . . . . . . . . . Setting Parameters in the Hamming Code Model . . . . . . . . . . Running the Hamming Code Model . . . . . . . . . . . . . . . . . . . . . Displaying Frame Sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying the Errors in a Scope . . . . . . . . . . . . . . . . . . . . . . . . Observing the Errors in the Scope . . . . . . . . . . . . . . . . . . . . . . Modeling a Channel with Modulation . . . . . . . . . . . . . . . . . . Binary Phase Shift Keying . . . . . . . . . . . . . . . . . . . . . . . . . . . . Selecting Blocks for the BPSK Model . . . . . . . . . . . . . . . . . . . . Building the BPSK Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Parameters in the BPSK Model . . . . . . . . . . . . . . . . . . Running the BPSK Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2-11 2-13 2-15 2-16 2-17 2-19 2-20 2-22 2-22 2-23 2-23 2-23 2-24 2-25 2-27 2-27 2-27 2-28 2-29 2-29 2-29 2-31 2-31 2-32 2-33 2-34 2-34 2-35 2-38 2-40 2-40 2-41 2-41 2-41 2-42
ii
Contents
Selecting Blocks for the Cyclic Code Model . . . . . . . . . . . . . . . Setting Parameters in the Cyclic Code Model . . . . . . . . . . . . . Running the Cyclic Code Model . . . . . . . . . . . . . . . . . . . . . . . . Setting the Symbol Period . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying Frame Sizes and Frame Periods . . . . . . . . . . . . . . Building a Frequency-Shift Keying Model . . . . . . . . . . . . . . Selecting Blocks for the FSK Model . . . . . . . . . . . . . . . . . . . . . Setting Parameters in the FSK Model . . . . . . . . . . . . . . . . . . . Running the FSK Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Delays in the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Finding the Delay in the Model . . . . . . . . . . . . . . . . . . . . . . . . . Multirate Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Sample Time Colors to Check Sample Times . . . . . . . . Building a Convolutional Code Model . . . . . . . . . . . . . . . . . . Selecting Blocks for the Convolutional Code Model . . . . . . . . . Building the Convolutional Code Model . . . . . . . . . . . . . . . . . . Setting Parameters in the Convolutional Code Model . . . . . . . Running the Convolutional Code Model . . . . . . . . . . . . . . . . . .
2-43 2-44 2-45 2-45 2-45 2-47 2-48 2-50 2-51 2-53 2-54 2-56 2-56 2-58 2-58 2-60 2-60 2-61
3
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Sending Data to the MATLAB Workspace . . . . . . . . . . . . . . . Configuring the Signal To Workspace Block . . . . . . . . . . . . . . . Viewing the Output in the Workspace . . . . . . . . . . . . . . . . . . . . Sending Error Data to the Workspace . . . . . . . . . . . . . . . . . . . . Working with Error Data in the Workspace . . . . . . . . . . . . . . .
3-3 3-3 3-4 3-4 3-6
Running Simulations from the Command Line . . . . . . . . . . . 3-7 Running a Single Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Running Multiple Simulations . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8 Setting Parameters in the Phase Noise Model . . . . . . . . . . . . . . 3-9 Plotting the Results of Multiple Simulations . . . . . . . . . . . . . . 3-10
iii
Importing Data from the MATLAB Workspace . . . . . . . . . . Simulating a Signal by Importing Data . . . . . . . . . . . . . . . . . . Simulating Noise with Imported Data . . . . . . . . . . . . . . . . . . . Creating Error Patterns in the Workspace . . . . . . . . . . . . . . . Setting Sample Times and Samples per Frame . . . . . . . . . . . . Simulating Bursts of Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . Using an Interleaver Block to Reduce the Error Rate . . . . . . . Running the Interleaver Model . . . . . . . . . . . . . . . . . . . . . . . . . Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Online Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The MathWorks Online . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3-12 3-12 3-13 3-14 3-15 3-16 3-17 3-19 3-21 3-21 3-21 3-21
iv
1
Introduction
What Is the Communications Blockset? . . . . . . . . 1-2 Related Products . . . . . . . . . . . . . . . . . . 1-3 Installation . . . . . . . . . . . . . . . . . . . . 1-4
Using This Guide . . . . . . . . . . . . . . . . . . 1-5 Who Should Read This Guide? . . . . . . . . . . . . . 1-5 How to Use This Guide . . . . . . . . . . . . . . . . 1-5 Typographical Conventions . . . . . . . . . . . . . 1-6
Introduction
1-2
Related Products
Related Products
In addition to MATLAB, there are several other MathWorks products that are closely related to the Communications Blockset.
Note The toolboxes listed below include functions that extend MATLABs capabilities. The blocksets include blocks that extend Simulinks capabilities.
Product
Description
Simulink block libraries for the design and simulation of the IS-95A wireless communications standard MATLAB functions for modeling the physical layer of communications systems Simulink block libraries for the design, simulation, and prototyping of digital signal processing systems Tool that generates customizable C code from Simulink models and automatically builds programs that can run in real time in a variety of environments Tool for algorithm development, signal and linear system analysis, and time-series data modeling Interactive, graphical environment for modeling, simulating, and prototyping dynamic systems Tool for graphical modeling and simulation of complex control logic
Real-Time Workshop
Stateflow
1-3
Introduction
Installation
To build and run the models in this manual, the Communications Blockset and the products it requires (see below) must be installed: MATLAB Simulink Signal Processing Toolbox Communications Toolbox DSP Blockset You can find instructions for installing these products in the MATLAB Installation Guide for your platform. To determine what products are installed on your system, type ver at the MATLAB prompt. This displays information about which version of MATLAB you are running, including a list of all toolboxes and blocksets installed on your system. When you first start MATLAB, type commstartup at the MATLAB prompt. This sets simulation parameters that optimize the models you build with the Communications Blockset. You must type commstartup at each new MATLAB session. See the section Setting Simulation Parameters on page 2-17 to learn more about simulation parameters. The Communications Blockset provides demonstration files that show how to use the blockset to model communications systems. To launch these demos, type
demo
1-4
Run a Simulink model Build and run models of communication systems Display the results of a simulation Change simulation parameters Run simulations from the MATLAB command line Transfer data between a model and the MATLAB workspace
If you are an experienced user, Using the Communications Blockset provides more detailed and comprehensive information about the blockset. In particular, the Reference chapter provides a detailed description of the operation and parameters of each of the blocks in the blockset.
1-5
Introduction
Typographical Conventions
This manual uses some or all of these conventions.
Item Convention Used Monospace font Example
Example code
Function names/syntax
Monospace font
The cos function finds the cosine of each array element. Syntax line example is
MLGetVar ML_var_name
Keys Literal strings (in syntax descriptions in reference chapters) Mathematical expressions
letter
Monospace bold for literals
Italics for variables Standard text font for functions, operators, and constants
Monospace font
MATLAB output
Menu titles, menu items, dialog boxes, and controls New terms Omitted input arguments
letter Italics (...) ellipsis denotes all of the input/output arguments from preceding syntaxes.
Monospace italics
sysc = d2c(sysd,'method')
1-6
2
Building Models
Introduction . . . . . . . . . . . . . . . . . . . . 2-2 Running a Simulink Model Building a Simple Model . . . . . . . . . . . . . 2-4
. . . . . . . . . . . . . . 2-11
Building a Channel Noise Model . . . . . . . . . . . 2-24 Reducing the Error Rate Using a Hamming Code . . . 2-31 Modeling a Channel with Modulation . . . . . . . . 2-40 . . . . . 2-43
Reducing the Error Rate with a Cyclic Code Building a Frequency-Shift Keying Model Building a Convolutional Code Model
. . . . . . 2-47
. . . . . . . . 2-58
Building Models
Introduction
This chapter introduces you to Simulink and the Communications Blockset. The chapter begins by showing you how to run an existing Simulink model, and how to build a simple model. It then explains how to build typical models of communications systems using the Communications Blockset. These models show you how to use the blockset and illustrate some of its important features. We encourage you to build and run these models for yourself, as this is the best way to learn about the Communications Blockset.
2-2
Introduction
Building a Frequency-Shift Keying Model on page 2-47 describes a model of frequency shift keying. The section explains delays created by blocks in the model and how to compensate for them. Building a Convolutional Code Model on page 2-58 describes a model of convolutional coding.
2-3
Building Models
2-4
signal then moves in the direction of the arrows to other blocks in the model. The following sequence of blocks processes the signal: The Rectangular QAM Modulator Baseband block, to the right of the Random Integer Generator block, modulates the signal using 256-ary QAM. The modulated signal is made up of complex numbers because the model uses a baseband representation of the signal. The AWGN Channel block simulates a channel with noise, by adding additive white Gaussian noise (AWGN) to the modulated signal. The Phase Noise block adds random noise to the angle of the complex signal. The Rectangular QAM Demodulator Baseband block, to the right of the Phase Noise block, demodulates the signal. In addition, the model uses the following blocks to calculate the errors introduced by noise and display the results: The Discrete Time Eye and Scatter Diagrams block, labeled AWGN plus Phase Noise, displays a scatter plot of the signal with added noise. The Error Rate Calculation block compares the received signal with the transmitted signal and calculates the number of symbols that differ between the two signals. 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. Except for the Phase Noise block, which is specially designed for this demo, these are all standard blocks that are included in the Communications Blockset and Simulink. You can find more detailed information about any standard block by right-clicking on the block and selecting Help from the context menu. The rest of this section takes you through some key elements of working with this model, including: Running a simulation Error rate calculation Error rate display Setting block parameters Displaying a plot of phase noise
2-5
Building Models
Running a Simulation
To run a simulation, select the Simulation menu from the top of the model window and then select Start (or, on Microsoft Windows, click the Start button on the toolbar). The simulation will stop automatically at the Stop time, which is specified in the Simulation parameters dialog box see the section Setting Simulation Parameters on page 2-17. You can stop the simulation at any time
2-6
by selecting Stop from the Simulation menu at the top of the model window (or, on Microsoft Windows, by clicking the Stop button on the toolbar). When you run the model, a new window appears displaying a scatter plot of the modulated signal with added noise, as shown below.
The points in the scatter plot do not lie exactly on the constellation shown in Figure 2-2, due to the added noise. The radial pattern of points is due to the addition of phase noise, which alters the angle of the complex modulated signal.
2-7
Building Models
other labeled Rx for the received signal. The block compares the two signals and checks for errors. The output of the block is a vector with three entries: The symbol error rate (SER) The total number of errors The total number of comparisons made
The upper box displays the symbol error rate. The middle box displays the total errors received. The lower box displays the total number of comparisons made. The notation 1e+004 is shorthand for 104.
2-8
To change the amount of phase noise, click in the Phase noise field and type a new value. Then click OK. Alternatively, you can enter a variable name, such as phasenoise, in the field. You can then set a value for that variable at the MATLAB prompt in the Command Window, for example by typing phasenoise=2. Setting parameters at the command line is convenient if you need to run multiple simulations with different parameter values see the section Running Multiple Simulations on page 3-8. You can also change the amount of noise in the AWGN Channel block. Double-click on the block to bring up its mask, and change the value in the Es/ No parameter field. This changes the signal to noise ratio, in decibels. 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 to 0 in the mask for the Phase Noise block. Change Es/No to 100 in the mask for the AWGN Channel block. This essentially removes all noise from the model. When you now run a simulation, the scatter plot appears as in Figure 2-2.
2-9
Building Models
Each curve is a plot of bit error rate as a function of signal to noise ratio for a fixed amount of phase noise. You can create plots like this by running multiple simulations with different values for the Phase noise and Es/No parameters. The section Running Multiple Simulations on page 3-8 describes how to do this with a MATLAB script, using variables for the parameters.
More Demos
You can find more demos for the Communications Blockset by typing demo at the MATLAB prompt. This displays the MATLAB Demo Window. Double-click on Blocksets in the left-hand pane, and then select Communications. Select a demo in the right-hand pane, and then click Run.
2-10
Opening Libraries
The blocks that you need to build the model are contained in libraries. In addition to the main Simulink libraries, each of the blocksets has its own libraries, which contain blocks specifically designed for the blocksets intended applications. The most useful libraries for communications applications are contained in the Communications Blockset and the DSP Blockset.
2-11
Building Models
To view all of the libraries for the products you have installed, type simulink at the MATLAB prompt (or, on Microsoft Windows, click the Simulink icon on the MATLAB toolbar). If you are using Microsoft Windows, this displays the Simulink Library Browser, as shown below.
The left-hand pane displays the installed products. The right-hand pane displays the main Simulink libraries. Click the + sign next to DSP Blockset in the left-hand pane. This displays a list of the DSP Blockset libraries underneath DSP Blockset in the left-hand pane, as shown in Figure 2-8. Next, click on DSP Sources in the left-hand pane. This displays the blocks in the DSP Sources library. On a UNIX platform, typing simulink at the MATLAB prompt displays the Simulink Library window shown below.
2-12
To open a Simulink library, double-click its icon. To open libraries for other blocksets and toolboxes, double-click the Blocksets & Toolboxes icon. This opens a new window that displays the icons for the libraries. Double-click the icon of the library you wish to open.
2-13
Building Models
Next, move the Sine Wave and Vector Scope blocks from the Library Browser into the model window as follows:
1 Click the + sign next to DSP Blockset in the left pane of the Library
Browser. This displays the DSP Blockset libraries in the left pane.
2 Select DSP Sources in the left pane. This displays a list of the individual
blocks in the right pane of the Library Browser. Scroll down the list until you come to the Sine Wave block.
3 Click the Sine Wave block and drag it into the model window. To drag a
block, position the mouse pointer over the block icon, then press and hold down the mouse button. Move the pointer into the model window, then release the mouse button.
2-14
4 Select DSP Sinks in the left pane of the Library Browser. 5 Click the Vector Scope block in the right pane and drag it into the model
window. Position the Vector Scope block to the right of the Sine Wave block. Once a block is in the model window, you can move it to another position by clicking and dragging it while pressing the mouse button.
Connecting Blocks
The small arrowhead pointing outward from the right side of the Sine Wave block is an output port, which denotes the flow of data out of the block. The Vector Scope block has a small arrowhead pointing inward, which is an input port. To connect the two blocks, click the output port of the Sine Wave block and move the mouse toward the input port of the Vector Scope block, while pressing the mouse button, as shown below.
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 figure below.
2-15
Building Models
If you do not see a solid arrowhead, you have not made a good connection, and data will not flow between the blocks. In this case, click the arrowhead again, drag it all the way to the Vector Scopes input port, and release the mouse button.
2-16
Change the default parameters as follows: Set Amplitude to 5. Set Frequency to 30. Set Samples per frame to 100. See the section Frames and Frame-Based Processing on page 2-23 for information about frames. Click OK.
2-17
Building Models
One important parameter is Stop time, which determines the time at which the simulation ends. The default is 10.0 seconds. This is simulation time, not actual clock time. The actual run-time for a simulation depends on such factors as the models complexity and your computers clock speed. Click the field next to Stop time and change the setting to inf. This causes the simulation to run indefinitely, until you stop it by selecting Stop from the Simulation menu.
Note if you want to generate code using Real Time Workshop, select Fixed-step in the Type list under Solver options.
To conserve memory, click the Workspace I/O tab in the Simulation Parameters dialog box. Under Save to workspace, uncheck the boxes next to Time and Output. It is usually not necessary to save this data. Changing Simulation parameters settings only affects the parameters of the current model. The next section describes how to make these settings the defaults for any models you create in a MATLAB session.
2-18
2-19
Building Models
When you are finished observing the simulation, select Stop from the Simulation menu.
dragging the Vector Scope block to the right, to make room for the AWGN Channel block.
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.
Double-click on the AWGN Channel block to bring up its mask, as shown below.
2-20
Click on the down arrow in the Mode field and select Signal to noise (SNR). Now, when you run the model, the scope clearly show the added noise.
2-21
Building Models
When you are finished observing the simulation, stop the model by selecting Stop from the Simulation menu.
Finding Blocks
You can search for a block in the Simulink Library Browser by typing a keyword in the field next to Find, at the top of the Browser window, and
2-22
clicking Find. This displays the next block that contains the keyword. To repeat the search, click Find again.
Continuous Signals
The Simulink libraries also contain blocks that generate continuous signals. This means that they update the signal at variable time intervals, whose length is determined by the numerical solver the simulation uses. For example, the Sine Wave block in the Simulink Sources library can generate a continuos sine wave.
Note Many blocks in the Communications Blockset accept only discrete signals. To find out whether a block accepts continuous signals, consult the reference page for the block.
2-23
Building Models
The model generates a random binary signal, and then switches the symbols 0 and 1 in the signal according to a specified probability, to simulate a channel with noise. The model then calculates the error rate and displays the result. We encourage you to build the model for yourself, as this is the best way to learn how to use the Communications Blockset. To open a completed version of the model, click here in the MATLAB Help browser. Then save it in your Work directory as my_channelnoise to preserve the original model intact. The section explains how to: Select blocks for the model Draw a branch line Resize a block Label a block The section also explains: The components of the model How to run the model How long to run a simulation Choose seeds for random sources
2-24
2-25
Building Models
Set Output data to Port and click OK. This creates a new output port on the block. Next, connect the blocks as in Figure 2-17. To learn how to do this, see the section Connecting Blocks on page 2-15. The next section explains how to draw the upper branch line.
2-26
You can create more space between the branch line and the Binary Symmetric Channel block by clicking on horizontal section of the line and dragging it up in the model window.
Resizing a Block
In order to see all three boxes in the Display block, as in Figure 2-4, you must enlarge the block slightly. To do so, select the Display block and place the mouse pointer on one of the lower corners of the Display block, so that a diagonal arrow appears on the corner. Click on the arrow and drag it downward, until the height of the Display block is about one inch. The three windows will not appear until you run the model.
Labeling a Block
You can change the label that appears below a block to make the label more informative. For example, you can change the default label of the Display block to Error Rate Display. To do so, first select the label with the mouse, which causes a box to appear around the text. Then type changes to the text in the box.
2-27
Building Models
The Channel
The Binary Symmetric Channel block simulates a channel with noise. The block introduces random errors to the signal by changing a 0 to a 1, or vice versa, with a probability determined by the Error probability parameter in the blocks mask. Make the following changes to the default parameters in the blocks mask: Set Error probability to .01. Set Initial seed to a prime number greater than 30, such as 113, which is different from the Initial seed of the Bernoulli Random Binary Generator. This ensures that the random errors the Binary Symmetric Channel block generates are statistically independent from the source signal. See the section Choosing Seeds for Random Sources on page 2-29. Uncheck the box next to Output error vector. This removes the lower output port from the block. By default the Binary Symmetric Channel block has two output ports. The upper port outputs the signal. The lower port outputs a vector consisting of the errors the block generates. Since the error vector is not used in this model, you do not need the lower output port.
2-28
2-29
Building Models
blocks, such as the Binary Symmetric Channel block, also use the random number generator to simulate channel noise. All of these blocks have an Initial seed parameter, which sets the initial value of the random number generator. If your model contains more than one of these blocks, you should observe the following guidelines to ensure that the random sequences are statistically independent of each other: All seeds should be primes greater than 30. Any two blocks with an Initial seed parameter should have different seeds. You can choose seeds having these properties using the Communications Blocksets randseed function. At the MATLAB prompt, type the command
randseed
This returns a random prime number greater than 30. Typing randseed again produces a different prime number. If you add an integer argument, randseed always returns the same prime for that integer. For example, randseed(5) always returns the same answer. You can use randseed directly in a model by setting the Initial seed parameter of a block to randseed. However, if you want to reproduce the results of a simulation, you should add integer arguments to randseed, choosing different arguments for each block in the model that has an Initial seed. For example, in the model shown in Figure 2-17, double-click on the Bernoulli Random Binary Generator block and type randseed(1) in the Initial seed field of the blocks mask. Then double-click on the Binary Symmetric Channel block and type randseed(2) in the Initial seed field of that blocks mask. Repeating a simulation with these settings will always reproduce the same results, since the Initial seed values do not change. For more information about the randseed function, type doc randseed at the MATLAB prompt.
2-30
The section explains how to: Build the model Use the Hamming Encoder and Decoder blocks to implement a Hamming code. Set parameters in the model Run the model Display frame sizes Display the errors in a scope Observe the errors in a scope
2-31
Building Models
Next, add two blocks from the Communications Blockset to the model: Hamming Encoder block Hamming Decoder block You can find both of these blocks in the Block sublibrary of the Channel Coding library. To insert them into the model:
1 Lengthen the lines leading into and out of the Binary Symmetric Channel
block, by dragging the other blocks in the model away from the Binary Symmetric Channel.
2 Drag the Hamming Encoder block from the Simulink Library Browser into
the model window, and place it on top of the line between the Bernoulli Random Binary Generator block and the Binary Symmetric Channel block. This makes new connections automatically.
3 Drag the Hamming Decoder block into the model window and place it on top
of the line between the Binary Symmetric Channel block and the Error Rate Calculation block. To open a completed version of the model, click here in the MATLAB Help browser.
2-32
2-33
Building Models
2-34
To build this model from the Hamming code model shown in Figure 2-19, you need to add the following blocks: Relational Operator block from the Simulink Math library Scope block from the Simulink Sinks library
2-35
Building Models
Two Unbuffer blocks from the Buffers sublibrary of the DSP Signal Management library Drag these blocks, including two copies of the Unbuffer block, from the Simulink Library Browser into the model window. Before connecting them, you need to configure the Scope block. The next section describes how to do this.
on the toolbar.
2-36
Repeat the same steps for the vertical axis of the lower scope. Finally, widen the scope window until it is roughly three times as wide as it is high. You can do this by clicking on the right border of the window and dragging the border to the right, while pressing the mouse button. Connect the blocks as shown in Figure 2-21. To learn how to do this, see the sections Connecting Blocks on page 2-15 and Drawing a Branch Line on page 2-27. Double-click on the Error Rate Calculation block and uncheck the box next to Stop simulation. If you want to label the lines Channel errors and Uncorrected errors, do the following:
1 In the model window, right-click on the line coming out of the upper
Unbuffer block.
2 Select Signal properties from the context menu. 3 In the Signal name field type Channel errors. 4 Click OK.
Repeat the same steps for the line coming out of the lower Unbuffer block, but this time type Uncorrected errors in the Signal name field.
Relational Operator
Set Relational Operator to ~= in the blocks mask. The Relational Operator block compares the transmitted signal, coming from the Bernoulli Random
2-37
Building Models
Generator block, with the received signal, coming from the Hamming Decoder block. The block outputs a zero when the two signals agree and a one when the disagree. A one represents an error that is not corrected by the Hamming code.
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. When the scope is roughly 3/4 filled, 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 icon at the top left of the Scope window. Then click on one of the lines in the lower scope. This zooms in horizontally on the line. Continue clicking on one of 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, although you should not expect to see exactly the same picture.
2-38
The wider rectangular pulse in the middle of the upper scope represents two ones. These two errors, which occur in a single code word, 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, selecting Stop from the Simulation menu. The section Sending Error Data to the Workspace on page 3-4 explains how to send the error data to the MATLAB workspace for more detailed analysis.
2-39
Building Models
This section explains binary phase shift keying. It also explains how to: Select blocks for the model Build the model Set parameters in the model Run the model
2-40
2-41
Building Models
AWGN Channel
Set Initial seed to a prime greater than 30, such as 113, which is different from the Initial seed in the Bernoulli Random Binary Generator block. Set Es/No to -1.
2-42
This section explains how to: Select blocks for the model Set parameters in the model Run the model Set the symbol period Display frame sizes and frame periods
2-43
Building Models
AWGN Channel
Set Symbol period to 4/15. This setting is necessary so that the AWGN channel block will produce the same amount of noise per symbol as in the BPSK model without coding. This enables you to evaluate the improvement in bit error rate due to channel coding. For more information on setting Symbol period, see the section Setting the Symbol Period on page 2-45. Set Es/No to -1.
2-44
frame period symbol period = ----------------------------------frame size In this example, the symbol period is 4/15.
2-45
Building Models
The Probe block displays information about the model. Initially, all numbers displayed on the block icon are zero. Double-click the Probe block to display its mask. Uncheck the boxes next to Probe complex signal and Probe signal dimensions. Leave the boxes next to Probe width and Probe sample time checked. This reduces the number of output ports in the block to two. Connect the blocks as shown in Figure 2-26 below. Finally, select Update diagram from the Edit menu. The diagram should now appear as shown below.
The number after W in the Probe block icon tells you the signal width, which in this case is just the frame size of 15. The first number after Tf tells you the frame period, which is 4. When the signal is sample-based, the second value in the Probe block is the sample time, rather than the frame period. To learn more about sample times and frame periods, see the sections Multirate Models on page 2-56 and Using Sample Time Colors to Check Sample Times on page 2-56.
2-46
This section explains how to: Select blocks for the model Set parameters in the model Run the model The section also explains: Delays in the model and how to find the delay Multirate models Using sample time colors to check sample times
2-47
Building Models
Relational Operator
The Relational Operator block, from the Simulink Math library, compares the transmitted signal, from the Bernoulli Random Binary Generator block, with the received signal, from the M-FSK Demodulator Passband block. The block outputs a zero when the two signals agree, and a one when they differ.
Spectrum Scope
The Spectrum Scope block, from the DSP Sinks library, calculates the fast Fourier transform (FFT) of the signal and displays its spectrum. When you run the model, a scope appears as in Figure 2-28.
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:
1 Double-click on the block to open the scope. 2 Click the Properties icon 3 Set Number of axes to 3. 4 Set Time range to 1. 5 Click OK.
on the toolbar.
2-48
Repeat these steps for the middle and lower axes. When you run the model, you can double-click the Scope block to display the three signals, as in Figure 2-29.
Integer Delay
The Integer Delay Block, from the DSP Blockset Signal Operations library, delays the transmitted signal so that it can be accurately compared with the received signal. Its purpose is explained further in the section Delays in the Model on page 2-53. You also need the following blocks: Bernoulli Random Binary Generator AWGN Channel Error Rate Calculation Display Drag these blocks into the model window and connect them as shown in Figure 2-27. To open a completed version of the model, click here in the MATLAB Help browser. Then save it in your Work directory as my_fsk to preserve the original model intact.
2-49
Building Models
AWGN Channel
Set Initial seed to a prime greater than 30, which is different from the Initial seed in the Bernoulli Random Binary Generator block. Set Symbol period to 1/1200, to match the Symbol period in the M-FSK Modulator Passband block.
2-50
Spectrum Scope
Check the box next to Buffer input. This converts the input into frames so that the block can calculate the FFT. You can set the size of the frames by the Buffer size parameter. Set Buffer size to 1024. Set Buffer overlap to 256. Set Number of spectral averages to 20. Check the box next to Axis properties. Set Minimum Y-limit to -40. Set Maximum Y-limit to 20. These settings rescale the Y-axis.
Integer Delay
Set Delay to 2. The Integer Delay block delays the transmitted signal by the number of sample periods specified by the Delay parameter. For more information about delays, see the section Delays in the Model on page 2-53.
2-51
Building Models
Note the peaks at 9500 Hz and 10500 Hz, representing the integers one and zero, respectively. The peaks outside the range 9500-10500 Hz are side lobes, which are not relevant to the display.
2-52
The top window displays the transmitted signal. The middle window displays the received signal. The bottom scope displays a zero where the two signals agree and a one where they differ.
2-53
Building Models
with the received signal so that the Relational Operator block can compare them correctly.
Note If the Error Rate Calculation block in a model gives an error rate close to .5 for a random binary signal, you may 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 the section Delays in Digital Modulation in the Using the Communications Blockset. The Viterbi Decoder block, from the Convolutional sublibrary of the Channel Coding library, also produces a delay equal to its Traceback depth parameter see the section Viterbi Decoder on page 2-60.
model window.
3 Connect the line leading out of the Bernoulli Random Binary Generator
block to the Signal To Workspace block. You can do this by right-clicking on the line and moving the mouse pointer to the input port of the Signal From Workspace block while pressing the mouse button.
4 Double-click on the Signal To Workspace block to open its mask, and change
2-54
5 Drag another Signal To Workspace block, from the DSP Sinks library, into
the model window and connect it to the line leading out of the M-FSK Demodulator Passband block.
6 Double-click on the second Signal To Workspace block into the model
Stop time to 1.
When you are done, the model should appear as in the figure below.
Running the model sends the transmitted and received signals to the workspace as vectors called Tx and Rx, respectively. To find the delay between Tx and Rx, type the following commands at the MATLAB prompt.
[m,index]=max(xcorr(Rx,Tx)); L=length(Tx); delay=index-L
2-55
Building Models
MATLAB should return delay=2, which is the correct value of the delay. The xcorr function calculates the correlations between Tx and Rx when the two vectors are shifted in all possible ways that overlap. The maximum correlation occurs at the shifted distance corresponding to the true delay. You can test whether you have found the correct value for the delay using MATLABs isequal command, which returns a 1 when two vectors are equal, and a 0 when they differ. To do so, at the MATLAB prompt type
isequal(Tx(1:L-delay),Rx(delay+1:L))
MATLAB returns a 1 if the number of symbols Tx and Rx are offset by is delay. If you use this procedure and MATLAB returns a 0 to the isequal command, it may indicate that there is still noise present in the model.
Multirate Models
The FSK model in Figure 2-27 differs from the earlier models in that it contains signals with different sample times. The Bernoulli Random Binary Generator block has a sample time of 1/1200. The M-FSK Modulator Passband block receives this signal and upsamples it at a rate of eight samples per symbol. As a result, the sample time of the blocks output signal is 1/9600. A model 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 you should be aware that in other models, sample times can affect the results of a simulation. This is usually the case when different signals are combined. See the section Setting Sample Times and Samples per Frame on page 3-15 for an example of this.
2-56
and lines are colored red. For more information on sample time colors, see Using Simulink. For frame-based signals, the colors correspond to the frame periods of the signals rather than sample times. If you need to determine the actual sample time of a signal, you can use a Probe block as described in the section Displaying Frame Sizes and Frame Periods on page 2-45.
2-57
Building Models
This section explains how to: Select blocks for the model Build the model Set block parameters Run the model
Convolutional Encoder
The Convolutional Encoder block, from the Convolutional sublibrary of the Channel Coding library, encodes the signal from the Bernoulli Random Binary Generator. The example uses the industry standard rate 1/2 convolutional code, with constraint length seven, defined by the diagram below.
2-58
The encoder structure is described by a pair of binary numbers, having the same length as the codes constraint length, which specify the connections from the delay cells to modulo-2 addition nodes. The binary number for the upper addition node is 1111001. A one indicates that the bit in the corresponding delay cell (reading from left to right) is sent to the addition node, and a zero 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 blocks mask by typing poly2trellis(7, [171 133]) in the field for Trellis Structure. To learn more about the convolutional coding features of the Communications Blockset, see the chapter Convolutional Coding in Using the Communications Blockset.
Complex to Real-Imag
The Complex to Real-Imag block, from the Simulink Math library, receives the complex signal and outputs its real part. Since the output BPSK Modulator Baseband block has zero complex part, all of the signal is carried by the real part. You can set this option by selecting Real in the Output parameter field in the mask. It is not necessary to demodulate the signal since the Viterbi Decoder block can accept unquantized inputs.
2-59
Building Models
Viterbi Decoder
The Viterbi Decoder block decodes the convolutionally encoded signal using the Viterbi algorithm. The Decision Type parameter is set to Unquantized so that the block can accept real numbers from the Complex to Real-Imag block. The Traceback depth parameter, which is set to 96, is the number of branches in the trellis that the block uses to construct each traceback path. This produces a delay of 96 between the input and output of the block. See the section Finding the Delay in the Model on page 2-54. For an example of a convolutional coding model that uses soft-decision decoding, see the section Example: Soft-Decision Decoding in the Using the Communications Blockset.
AWGN Channel
Set Es/No to -1. Set Symbol period to 1/2. Since the code rate is 1/2, this setting causes the block to produce the same amount of noise per channel symbol as it would
2-60
without channel coding. For more information, see the section Setting the Symbol Period on page 2-45.
2-61
Building Models
2-62
3
Using MATLAB with the Communications Blockset
Introduction . . . . . . . . . . . . . . . . . . . . 3-2 Sending Data to the MATLAB Workspace Configuring the Signal To Workspace Block . Viewing the Output in the Workspace . . . Sending Error Data to the Workspace . . . Working with Error Data in the Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 3-3 3-4 3-4 3-6 3-7 3-7 3-8 3-9 3-10 3-12 3-12 3-13 3-14 3-15 3-16 3-17 3-19
Running Simulations from the Command Line Running a Single Simulation . . . . . . . . . . Running Multiple Simulations . . . . . . . . . Setting Parameters in the Phase Noise Model . . . Plotting the Results of Multiple Simulations . . . Importing Data from the MATLAB Workspace Simulating a Signal by Importing Data . . . . . Simulating Noise with Imported Data . . . . . . Creating Error Patterns in the Workspace . . . . Setting Sample Times and Samples per Frame . . Simulating Bursts of Errors . . . . . . . . . . Using an Interleaver Block to Reduce the Error Rate Running the Interleaver Model . . . . . . . . . Learning More . . . Online Help . . . . . Demos . . . . . . . The MathWorks Online . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Introduction
This chapter describes how to use MATLAB to expand the capabilities of the Communications Blockset. The chapter explains how to run simulations from the command line, and how to run multiple simulations. It also explains how to send data between a model and the MATLAB workspace. This enables you to analyze the results of simulations, and to import customized data into a model. This chapter covers the following topics: Sending Data to the MATLAB Workspace on page 3-3 shows how to write the results of simulations from a model to the MATLAB workspace, so that you can study them in greater detail. Running Simulations from the Command Line on page 3-7 shows how to run models from the MATLAB command line. This enables you to run multiple simulations with varying parameters. The section also shows how to plot the results of multiple simulations. Importing Data from the MATLAB Workspace on page 3-12 shows how to import data from the workspace into a model. This enables you to run simulations on data that you create in the workspace or import from outside MATLAB. The section also shows how to create specific error patterns, such as burst errors, to test a channel code. The section explains how to use the Interleaver block to reduce the error rate caused by burst errors. Learning More on page 3-21 describes other sources of information about the Communications Blockset.
3-2
3-3
Double-click on the Signal To Workspace block to display its mask. In the Variable name field type hammcode_BER. In the Limit data points to last field type 1. Then click OK. With these settings, the model sends only the final value of the bit error rate to the workspace, as a vector called hamming_BER.
The command format short e displays the entries of the vector in exponential form. 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.
3-4
You can build this model from the Hamming code model, shown in Figure 2-19. To open that model, click here in the MATLAB Help browser. Then save it in your Work directory under a different name to preserve the original model intact. To build the model:
1 Double-click on the Binary Symmetric Channel block to open its mask, and
check the box next to Output error vector. This creates an output port for the error data.
2 Drag three Signal To Workspace blocks from the DSP Sinks library into the
Variable name field in the blocks mask. In the Frames field, select Log frames separately (3-D array). Then click OK. The block sends the transmitted signal to the workspace as an array called Tx.
4 Double-click on the middle Signal To Workspace block and type errors in
the Variable name field. In the Frames field, select Log frames separately (3-D array). Then click OK. The block sends the error data to the workspace as an array called errors.
5 Double-click on the right Signal To Workspace block and type Rx in the
Variable name field. In the Frames field, select Log frames separately (3-D array). Then click OK. The block sends the received signal to the workspace as an array called Rx. The option Log frames separately (3-D array) preserves each frame as a separate column of the array. The columns in Tx and Rx have size four, corresponding to the length of message words. The columns in errors have size seven, corresponding to the length of code words. The Binary Symmetric Channel block adds a frame of errors to each code word modulo two. The third entry of each array is the number of the frame. After running a simulation, you can display individual frames of data. For example, to display the tenth frame of Tx, at the MATLAB prompt type
Tx(:,:,10)
3-5
Usually, you should not type Tx by itself, as this will display the entire transmitted signal, which is very large. To display the corresponding frame of errors, type
errors(:,:,10)
The vector diffs is the xor of the vectors Tx and Rx. A 1 in diffs 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 script.
not_equal=any(diffs); error_indices=find(not_equal);
A 1 in the vector not_equal indicates that there is at least one difference between the corresponding frame of Tx and Rx. The vector error_indices records the indices where Tx and Rx differ. To view the first incorrectly decoded word, type
Tx(:,:,error_indices(1))
You can analyze this data to determine the error patterns that lead to incorrect decoding.
3-6
at the MATLAB prompt. 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 type another MATLAB command.
Note To stop the simulation before its Stop time has elapsed, press Ctrl + C on the keyboard.
After the simulation stops, the prompt reappears. You can then view the results of the simulation by typing phasenoise_sim to open the model.
Note If you run a simulation from the command line with the model window open, you cannot access the model window while the simulation is running. If the models Stop time parameter is set to inf, you must press Ctrl + C on the keyboard to stop the simulation.
It is not necessary to open the model window when running a simulation from the command line, as usually you want to send the results of the simulation to
3-7
the MATLAB workspace for example, if you are running multiple simulations on a single model. You can also set simulation parameters from the command line. For example, the command
sim('phasenoise',1000);
runs the model with a Stop time of 1000. This overrides the Stop time setting in the Model parameters dialog box. For more information on running simulations, see Using Simulink.
3-8
AWGN Channel
Set Es/No to EbNodB+10*log10(8). The variable EbNodB represents bit energy to noise ratio. The term 10*log10(8) converts EsNodB to Es/No, which is the symbol energy to noise ratio. The term 8 is present because there are eight bits per channel symbol in 256-QAM.
Phase Noise
Set Phase noise (degrees) to 1.
Signal To Workspace
Set Variable name to phase_BER. Set Limit data points to last to 1. To set values for EbNodB in a vector, type the following command at the MATLAB prompt.
EbNoVec=20:.2:21;
You can now run six simulations, with Es/No parameter values given by these vector entries plus 10 log(8). The following script runs the simulations in a loop and stores the results in a matrix called BER_Vec. The simulations may take several minutes to run.
3-9
When the simulations have ended and the prompt reappears, type the following at the MATLAB prompt.
format short e BER_Vec
This displays the results in a matrix. Each row is the output of the Error Calculation Block for a single simulation. Notice that the first column, which gives the error rates for the six simulations, decreases. This is because the noise level decreases as EbNodB increases. The last column gives the number of symbols processed in each simulation.
3-10
This is a part of the plot shown in the section Displaying a Plot of Phase Noise on page 2-9, corresponding to phase noise of degree 1 and Eb/No values between 20 and 21.
3-11
To build this model, click here in the MATLAB Help browser to open the channel noise model in Figure 2-17. Then save it in your Work directory under a different name to preserve the original model intact.
1 Replace the Bernoulli Random Binary Generator block with a Signal From
3-12
2 In the Signal from Workspace blocks mask, change the Signal parameter to
Before using the model, you must define the define the vector data in the MATLAB workspace. For example, type data=randint(1,10^4); at the MATLAB prompt. This defines data as a random binary vector of length 104. Next, select Simulation parameters from the Simulation menu and set the Stop time parameter to length(data). When you run a simulation, the model imports the random vector data into the model. You can change the vector data in the MATLAB workspace to simulate a less random signal, or import a signal from outside MATLAB.
This example is similar to the Hamming code model shown in Figure 2-19, but instead of using the Binary Symmetric Channel block to simulate noise, the model imports error data from the workspace. To build this model, first click here in the MATLAB Help browser to open the model shown in Figure 2-19. Then save it in your Work directory under a different name to preserve the original model intact.
3-13
Then delete the Binary Symmetric Channel block from the model. Next, drag the following blocks into the model window: A Signal From Workspace block, from the DSP Sources library A Logical Operator block, from the Simulink Math library. Connect these blocks as shown in Figure 3-5. Make the following changes to the default block parameter settings.
Logical Operator
Set Operator to XOR.
3-14
The function randperm generates a random permutation of the integers one through seven. The vector v(p) applies the permutation to the entries of the vector v, which has exactly one entry 1. The result is that the vector errors contains exactly one entry 1 in each sequence from 7n + 1 to 7(n+1).
3-15
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 figure below.
Both Probe blocks should display a frame size of seven and a frame period of four. A quick way to check whether the frame periods of two signals are the same is to select Sample time colors from the Format menu. See the section Using Sample Time Colors to Check Sample Times on page 2-56.
3-16
To determine the ratio of the number of ones to the total number of symbols in the vector errors, type
sum(errors)/length(errors)
Your answer should be around 3/43, since after each sequence of three ones, the expected distance to the next sequence of ones is 40. Consequently, you expect to see three ones in 43 terms of the sequence. If you run a simulation with the new errors vector, using the Hamming code model in Figure 3-5, the error rate will be less than 3/43. The code in that model can correct one error per code word. When a sequence of three errors overlaps a code word by one, the code word with one error is corrected. You can compare the bit error rate in the model in Figure 3-5 with the bit error rate in the Hamming code model shown in Figure 2-19, which uses the Binary Symmetric Channel block to simulate independent random errors. First, click here in the MATLAB Help Browser to open the Hamming code model.Then save it in your Work directory under a different name to preserve the original model intact. Double-click on the Binary Symmetric Channel block to open its mask. Change Error probability to sum(errors)/length(errors). This makes the Error probability equal to the percentage of ones in the vector errors, so that you can compare the two models. When you run a simulation on the Hamming code model, you get a lower bit error rate than with the model in Figure 3-5, because the Hamming code is better able to correct independent errors than bursts of errors.
3-17
To build the model from the one in Figure 3-5, you need four new blocks: Two copies of the Buffer block from the Buffers sublibrary of the Signal Management library in the DSP Blockset A Random Interleaver block from the Block sublibrary of the Interleaving library in the Communications Blockset A Random Deinterleaver block from the Block sublibrary of the Interleaving library in the Communications Blockset Drag these blocks into the model window and connect them as in Figure 3-7. To open a completed version of the model, click here in the MATLAB Help browser.
3-18
order. This separates the errors, making it less likely for a code word to contain more than one error. Set Number of elements to 84 in the masks for the Random Interleaver and Random Deinterleaver blocks. This matches the Output buffer size setting in the Buffer block. While the Number of elements parameter can be any positive integer, the model is easier to configure if Number of elements is a multiple of the code word size, which is seven in this example. To learn more about block interleavers, see the section Block Interleavers in Using the Communications Blockset.
3-19
deinterleaved, the errors are distributed randomly about each frame of size 84. As a result, it is less likely that a code word will have more than one error and be decoded incorrectly.
3-20
Learning More
Learning More
You can learn more about the Communications Blockset from the following sources.
Online Help
To find online documentation, select Full Product Family 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, Getting Started with the Communications Blockset, the online documentation contains the following topics: Release Notes For details on the latest release, including new features Using the Communications Blockset Contains comprehensive information about all the features of the Communications Blockset. Reference Provides a detailed description of the functions and blocks in the Communications Blockset. The Help Navigator, in the left pane of the Help browser, supports string searches. You can specify strings and the online manuals that you want to search. To begin a search, click the Search tab. To view the index for the documentation, for the click the Index tab.
Demos
To see more Communications Blockset examples, type
demo
at the MATLAB prompt. This opens the MATLAB Demo window. Double-click on Blocksets and then select Communications to list the available demos.
3-21
3-22
Index
B
binary phase shift keying (BPSK) 2-40 block connecting 2-15 finding 2-22 labeling 2-27 moving into model 2-13 parameters 2-8 resizing 2-27 BPSK modulation model 2-40
I
importing data from the workspace 3-12 interleaver model 3-17
M
mask 2-8 MathWorks Web site 3-21 model building 2-11 saving 2-22
C
channel coding 2-24 channel noise model 2-24 constellation 2-6 continuous signals 2-23 cyclic code model 2-43
O
online help 3-21
Q
quadrature amplitude modulation (QAM) 2-6
D
demos 2-10 discrete signals 2-23 drawing a branch line 2-27
S
sample times 2-23 sample-based processing 2-23 samples per frame 2-23 seeds for random sources 2-29 sending data to the workspace 3-3 simulation how long to run 2-29 parameters 2-17 running 2-6 running from the command line 3-7 Simulink libraries 2-11 Simulink Library Browser 2-12
F
frame sizes, displaying 2-34 frame-based processing 2-23 frames 2-23 FSK model 2-47
H
Hamming code model 2-31 Help Navigator 3-21
I-1
Index
T
typographical conventions (table) 1-6
I-2