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.

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) 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

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


© 1994-2005 The MathWorks, Inc.