Communications Toolbox | ![]() ![]() |
Random Signals
Random signals are useful for simulating noise, errors, or signal sources. Besides built-in MATLAB functions like rand
and randn
, you can also use these functions from this toolbox:
wgn
, for generating white Gaussian noise
randsrc
, for generating random symbols
randint
, for generating uniformly distributed random integers
randerr
, for generating random bit error patterns
While randsrc
and randint
are suitable for representing sources, randerr
is more appropriate for modeling channel errors.
White Gaussian Noise
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.
To generate complex white Gaussian noise whose power is 2 Watts, across a load of 60 ohms, use either of the commands below. Notice that the ordering of the string inputs does not matter.
To send a signal through an additive white Gaussian noise channel, use the awgn
function.
Random Symbol Matrices
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.)
If you want 1 to be twice as likely to occur as either 3 or 5, then use the command below to prescribe the skewed distribution. Notice that 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.
Random Integer Matrices
The randint
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.
If your desired range is [0,10] instead of [2,10] then you can use either of the commands below. They produce different numerical results, but use the same distribution.
Random Bit Error Patterns
The randerr
function generates matrices whose entries are either 0 or 1. However, its options are rather different from those of randint
, because randerr
is meant for testing error-control coding. For example, the command below generates a 5-by-4 binary matrix having the property that each row contains exactly one 1.
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) would introduce exactly one error into each codeword.
On the other hand, if you want to perturb each codeword by introducing one error with probability 0.4 and two errors with probability 0.6, then the command below should replace the one above.
% 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 randerr affects only the number of 1s in each row, not their placement.
|
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. Notice that 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 = randint(100,1,2); % Two possible values binarymatrix3 = randerr(100,1,[0 1;.5 .5]); % No 1s, or one 1
![]() | Random Signals and Error Analysis | Error Rates | ![]() |