Communications System Toolbox™ provides sinks and display devices that facilitate analysis of communication system performance. You can implement devices using either System objects, blocks, or functions.
You can use blocks or functions to generate random data to simulate a signal source. In addition, you can use Simulink blocks such as the Random Number block as a data source. You can open the Random Data Sources sublibrary by double-clicking its icon (found in the Comm Sources library of the main Communications System Toolbox block library).
The randsrc
function generates random matrices
whose entries are chosen independently from an alphabet that you specify,
with a distribution that you specify. A special case generates
bipolar matrices.
For example, the command below generates a 5-by-4 matrix whose entries are independently chosen and uniformly distributed in the set {1,3,5}. (Your results might vary because these are random numbers.)
a = randsrc(5,4,[1,3,5]) a = 3 5 1 5 1 5 3 3 1 3 3 1 1 1 3 5 3 1 1 3
If you want 1 to be twice as likely to occur as either 3 or
5, use the command below to prescribe the skewed distribution. The
third input argument has two rows, one of which indicates the possible
values of b
and the other indicates the probability
of each value.
b = randsrc(5,4,[1,3,5; .5,.25,.25]) b = 3 3 5 1 1 1 1 1 1 5 1 1 1 3 1 3 3 1 3 1
In MATLAB, the randi
function generates
random integer matrices whose entries are in a range that you specify. A
special case generates random binary matrices.
For example, the command below generates a 5-by-4 matrix containing random integers between 2 and 10.
c = randi([2,10],5,4) c = 2 4 4 6 4 5 10 5 9 7 10 8 5 5 2 3 10 3 4 10
If your desired range is [0,10] instead of [2,10], you can use either of the commands below. They produce different numerical results, but use the same distribution.
d = randi([0,10],5,4); e = randi([0 10],5,4);
In Simulink^{®}, the Random Integer Generator and Poisson Integer Generator blocks both generate vectors containing random nonnegative integers. The Random Integer Generator block uses a uniform distribution on a bounded range that you specify in the block mask. The Poisson Integer Generator block uses a Poisson distribution to determine its output. In particular, the output can include any nonnegative integer.
In MATLAB^{®}, the randerr
function generates
matrices whose entries are either 0 or 1. However, its options are
different from those of randi
, because randerr
is
meant for testing error-control coding. For example, the command below
generates a 5-by-4 binary matrix, where each row contains exactly
one 1.
f = randerr(5,4) f = 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 0
You might use such a command to perturb a binary code that consists
of five four-bit codewords. Adding the random matrix f
to
your code matrix (modulo 2) introduces exactly one error into each
codeword.
On the other hand, to perturb each codeword by introducing one error with probability 0.4 and two errors with probability 0.6, use the command below instead.
% Each row has one '1' with probability 0.4, otherwise two '1's
g = randerr(5,4,[1,2; 0.4,0.6])
g =
0 1 1 0
0 1 0 0
0 0 1 1
1 0 1 0
0 1 1 0
Note:
The probability matrix that is the third argument of |
As another application, you can generate an equiprobable binary 100-element column vector using any of the commands below. The three commands produce different numerical outputs, but use the same distribution. The third input arguments vary according to each function's particular way of specifying its behavior.
binarymatrix1 = randsrc(100,1,[0 1]); % Possible values are 0,1. binarymatrix2 = randi([0 1],100,1); % Two possible values binarymatrix3 = randerr(100,1,[0 1;.5 .5]); % No 1s, or one 1
In Simulink, the Bernoulli Binary Generator block generates random bits and is suitable for representing sources. The block considers each element of the signal to be an independent Bernoulli random variable. Also, different elements need not be identically distributed.
Construct noise generator blocks in Simulink to simulate communication links.
You can construct random noise generators to simulate channel noise by using the MATLAB Function block with random number generating functions. Construct different types of channel noise by using the following combinations.
Distribution | Block | Function |
---|---|---|
Gaussian | MATLAB Function | randn |
Rayleigh | MATLAB Function | randn |
Rician | MATLAB Function | randn |
Uniform on a bounded interval | MATLAB Function | rand |
See Random Noise Generators for an example of how Rayleigh and Rician distributed noise is created.
In MATLAB, the wgn
function generates
random matrices using a white Gaussian noise distribution. You specify
the power of the noise in either dBW (decibels relative to a watt),
dBm, or linear units. You can generate either real or complex noise.
For example, the command below generates a column vector of length 50 containing real white Gaussian noise whose power is 2 dBW. The function assumes that the load impedance is 1 ohm.
y1 = wgn(50,1,2);
To generate complex white Gaussian noise whose power is 2 watts, across a load of 60 ohms, use either of the commands below. The ordering of the string inputs does not matter.
y2 = wgn(50,1,2,60,'complex','linear'); y3 = wgn(50,1,2,60,'linear','complex');
To send a signal through an additive white Gaussian noise channel,
use the awgn
function. See AWGN Channel for more
information.
You can use blocks in the Sequence Generators sublibrary of the Communications Sources library to generate sequences for spreading or synchronization in a communication system. You can open the Sequence Generators sublibrary by double-clicking its icon in the main Communications System Toolbox block library.
Blocks in the Sequence Generators sublibrary generate
The following table lists the blocks that generate pseudorandom or pseudonoise (PN) sequences. The applications of these sequences range from multiple-access spread spectrum communication systems to ranging, synchronization, and data scrambling.
Sequence | Block |
---|---|
Gold sequences | Gold Sequence Generator |
Kasami sequences | Kasami Sequence Generator |
PN sequences | PN Sequence Generator |
All three blocks use shift registers to generate pseudorandom sequences. The following is a schematic diagram of a typical shift register.
All r registers in the generator update their values at each time step according to the value of the incoming arrow to the shift register. The adders perform addition modulo 2. The shift register can be described by a binary polynomial in z, g_{r}z^{r} + g_{r-1}z^{r-1} + ... + g_{0}. The coefficient g_{i} is 1 if there is a connection from the ith shift register to the adder, and 0 otherwise.
The Kasami Sequence Generator block and the PN Sequence Generator block use this polynomial description for their Generator polynomial parameter, while the Gold Sequence Generator block uses it for the Preferred polynomial [1] and Preferred polynomial [2] parameters.
The lower half of the preceding diagram shows how the output sequence can be shifted by a positive integer d, by delaying the output for d units of time. This is accomplished by a single connection along the dth arrow in the lower half of the diagram.
The Barker Code Generator block generates Barker codes to perform synchronization. Barker codes are subsets of PN sequences. They are short codes, with a length at most 13, which are low-correlation sidelobes. A correlation sidelobe is the correlation of a codeword with a time-shifted version of itself.
Orthogonal codes are used for spreading to benefit from their perfect correlation properties. When used in multi-user spread spectrum systems, where the receiver is perfectly synchronized with the transmitter, the despreading operation is ideal.
Code | Block |
---|---|
Hadamard codes | Hadamard Code Generator |
OVSF codes | OVSF Code Generator |
Walsh codes | Walsh Code Generator |
The Comm Sinks block library contains scopes for viewing three types of signal plots:
The following table lists the blocks and the plots they generate.
Block Name | Plots |
---|---|
Eye Diagram | Eye diagram of a signal |
Constellation Diagram | Constellation diagram and signal trajectory of a signal |
An eye diagram is a simple and convenient tool for studying the effects of intersymbol interference and other channel impairments in digital transmission. When this software product constructs an eye diagram, it plots the received signal against time on a fixed-interval axis. At the end of the fixed interval, it wraps around to the beginning of the time axis. As a result, the diagram consists of many overlapping curves. One way to use an eye diagram is to look for the place where the eye is most widely opened, and use that point as the decision point when demapping a demodulated signal to recover a digital message.
The Eye Diagram block produces eye diagrams. This block processes discrete-time signals and periodically draws a line to indicate a decision, according to a mask parameter.
Examples appear in View a Sinusoid and View a Modulated Signal.
A constellation diagram of a signal plots the signal's value at its decision points. In the best case, the decision points should be at times when the eye of the signal's eye diagram is the most widely open.
The Constellation Diagram block produces a constellation diagram from discrete-time signals. An example appears in View a Sinusoid.
A signal trajectory is a continuous plot of a signal over time. A signal trajectory differs from a scatter plot in that the latter displays points on the signal trajectory at discrete intervals of time.
The Constellation Diagram block
produces signal trajectories. The Constellation Diagram block
produces signal trajectories when the ShowTrajectory
property
is set to true. A signal trajectory connects all points of the input
signal, irrespective of the specified decimation factor (Samples
per symbol
)
The following model produces a constellation diagram and an eye diagram from a complex sinusoidal signal. Because the decision time interval is almost, but not exactly, an integer multiple of the period of the sinusoid, the eye diagram exhibits drift over time. More specifically, successive traces in the eye diagram and successive points in the scatter diagram are near each other but do not overlap.
To open the model,
enter doc_eyediagram
at the MATLAB command
line. To build the model, gather and configure these blocks:
Sine Wave, in the Sources library of the DSP System Toolbox™ (not the Sine Wave block in the Simulink Sources library)
Set Frequency to .502
.
Set Output complexity to Complex
.
Set Sample time to 1/16
.
Constellation Diagram, in the Comm Sinks library
On the Constellation Properties panel,
set Samples per symbol to 16
.
Eye Diagram, in the Comm Sinks library
On the Plotting Properties panel,
set Samples per symbol to 16
.
On the Figure Properties panel,
set Scope position to figposition([42.5
55 35 35]);
.
Connect the blocks as shown in the preceding figure. From the
model window's Simulation menu, choose Model
Configuration parameters. In the Configuration
Parameters dialog box, set Stop time to 250
.
Running the model produces the following scatter diagram plot.
The points of the scatter plot lie on a circle of radius 1. Note that the points fade as time passes. This is because the box next to Color fading is checked under Rendering Properties, which causes the scope to render points more dimly the more time that passes after they are plotted. If you clear this box, you see a full circle of points.
The Constellation Diagram block displays a circular trajectory.
In the eye diagram, the upper set of traces represents the real part of the signal and the lower set of traces represents the imaginary part of the signal.
This multipart example creates an eye diagram, scatter plot, and signal trajector plot for a modulated signal. It examines the plots one by one in these sections:
The following model modulates a random signal using QPSK, filters the signal with a raised cosine filter, and creates an eye diagram from the filtered signal.
To open the model,
enter doc_signaldisplays
at the MATLAB command
line. To build the model, gather and configure the following blocks:
Random Integer Generator, in the Random Data Sources sublibrary of the Comm Sources library
Set M-ary number to 4
.
Set Sample time to 0.01
.
QPSK Modulator Baseband, in PM in the Digital Baseband sublibrary of the Modulation library of Communications System Toolbox, with default parameters
AWGN Channel, in the Channels library of Communications System Toolbox, with the following changes to the default parameter settings:
Set Mode to Signal-to-noise
ratio (SNR)
.
Set SNR (dB) to 15
.
Raised Cosine Transmit Filter, in the Comm Filters library
Set Filter shape to Normal
.
Set Rolloff factor to 0.5
.
Set Filter span in symbols to 6
.
Set Output samples per symbol to 8
.
Set Input processing to Elements
as channels (sample based)
.
Eye Diagram, in the Comm Sinks library
Set Samples per symbol to 8
.
Set Symbols per trace to 3
.
This specifies the number of symbols that are displayed in each trace
of the eye diagram. A trace is any one of the
individual lines in the eye diagram.
Set Traces displayed to 3
.
Set New traces per display to 1
.
This specifies the number of new traces that appear each time the
diagram is refreshed. The number of traces that remain in the diagram
from one refresh to the next is Traces displayed minus New
traces per display.
On the Rendering Properties panel,
set Markers to +
to indicate
the points plotted at each sample. The default value of Markers is
empty, which indicates no marker.
On the Figure Properties panel,
set Eye diagram to display to In-phase
only
.
When you run the model, the Eye Diagram displays the following diagram. Your exact image varies depending on when you pause or stop the simulation.
Three traces are displayed. Traces 2 and 3 are faded because Color
fading under Rendering Properties is
selected. This causes traces to be displayed less brightly the older
they are. In this picture, Trace 1 is the most recent and Trace 3
is the oldest. Because New traces per display is
set to 1
, only Trace 1 is appearing for the first
time. Traces 2 and 3 also appear in the previous display.
Because Symbols per trace is set to 3
,
each trace contains three symbols, and because Samples per
trace is set to 8
, each symbol contains
eight samples. Note that trace 1 contains 24 points, which is the
product of Symbols per trace and Samples
per symbol. However, traces 2 and 3 contain 25 points each.
The last point in trace 2, at the right border of the scope, represents
the same sample as the first point in trace 1, at the left border
of the scope. Similarly, the last point in trace 3 represents the
same sample as the first point in trace 2. These duplicate points
indicate where the traces would meet if they were displayed side by
side, as illustrated in the following picture.
You can view a more realistic eye diagram by changing the value
of Traces displayed to 40
and
clearing the Markers field.
When the Offset parameter is set to 0
,
the plotting starts at the center of the first symbol, so that the
open part of the eye diagram is in the middle of the plot for most
points.
The following model creates a scatter plot of the same signal considered in Eye Diagram of a Modulated Signal.
To build the model, follow the instructions in Eye Diagram of a Modulated Signal but replace the Eye Diagram block with the following block:
Constellation Diagram, in the Comms Sinks library
Set Samples per symbol to 2
.
Set Offset to 0
.
This specifies the number of samples to skip before plotting the first
point.
Set Symbols to display to 40
.
When you run the simulation, the Constellation Diagram block displays the following plot.
The plot displays 30 points. Because Color fading under Rendering Properties is selected, points are displayed less brightly the older they are.
The following model creates a signal trajectory plot of the same signal considered in Eye Diagram of a Modulated Signal.
To build the model, follow the instructions in Eye Diagram of a Modulated Signal but replace the Eye Diagram block with the following block:
Constellation Diagram , in the Comms Sinks library
Set Samples per symbol to 8
.
Set Symbols displayed to 40
.
This specifies the number of symbols displayed in the signal trajectory.
The total number of points displayed is the product of Samples
per symbol and Symbols displayed.
Set New symbols per display to 10
.
This specifies the number of new symbols that appear each time the
diagram is refreshed. The number of symbols that remain in the diagram
from one refresh to the next is Symbols displayed minus New
symbols per display.
When you run the model, the Constellation Diagram displays a trajectory like the one below.
The plot displays 40 symbols. Because Color fading under Rendering Properties is selected, symbols are displayed less brightly the older they are.
See Constellation Diagram of a Modulated Signal to compare the preceding signal trajectory to the scatter plot of the same signal. The Constellation Diagram block connects the points displayed by the Constellation Diagram block to display the signal trajectory.
If you increase Symbols displayed to 100
,
the model produces a signal trajectory like the one below. The total
number of points displayed at any instant is 800, which is the product
of the parameters Samples per symbol and Symbols
displayed.