Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# biterr

Compute number of bit errors and bit error rate (BER)

## Syntax

[number,ratio] = biterr(x,y)
[number,ratio] = biterr(x,y,k)
[number,ratio] = biterr(x,y,k,flg)
[number,ratio,individual] = biterr(...)

## Description

### For All Syntaxes

The biterr function compares unsigned binary representations of elements in x with those in y. The schematics below illustrate how the shapes of x and y determine which elements biterr compares.

Each element of x and y must be a nonnegative decimal integer; biterr converts each element into its natural unsigned binary representation. number is a scalar or vector that indicates the number of bits that differ. ratio is number divided by the total number of bits. The total number of bits, the size of number, and the elements that biterr compares are determined by the dimensions of x and y and by the optional parameters.

### For Specific Syntaxes

[number,ratio] = biterr(x,y) compares the elements in x and y. If the largest among all elements of x and y has exactly k bits in its simplest binary representation, the total number of bits is k times the number of entries in the smaller input. The sizes of x and y determine which elements are compared:

• If x and y are matrices of the same dimensions, then biterr compares x and y element by element. number is a scalar. See schematic (a) in the preceding figure.

• If one is a row (respectively, column) vector and the other is a two-dimensional matrix, then biterr compares the vector element by element with each row (resp., column) of the matrix. The length of the vector must equal the number of columns (resp., rows) in the matrix. number is a column (resp., row) vector whose mth entry indicates the number of bits that differ when comparing the vector with the mth row (resp., column) of the matrix. See schematics (b) and (c) in the figure.

[number,ratio] = biterr(x,y,k) is the same as the first syntax, except that it considers each entry in x and y to have k bits. The total number of bits is k times the number of entries of the smaller of x and y. An error occurs if the binary representation of an element of x or y would require more than k digits.

[number,ratio] = biterr(x,y,k,flg) is similar to the previous syntaxes, except that flg can override the defaults that govern which elements biterr compares and how biterr computes the outputs. The possible values of flg are 'row-wise', 'column-wise', and 'overall'. The table below describes the differences that result from various combinations of inputs. As always, ratio is number divided by the total number of bits. If you do not provide k as an input argument, the function defines it internally as the number of bits in the simplest binary representation of the largest among all elements of x and y.

Comparing a Two-Dimensional Matrix x with Another Input y

Shape of yflgType of ComparisonnumberTotal Number of Bits
2-D matrix 'overall' (default) Element by element Total number of bit errors k times number of entries of y
'row-wise'mth row of x vs. mth row of yColumn vector whose entries count bit errors in each row k times number of entries of y
'column-wise'mth column of x vs. mth column of yRow vector whose entries count bit errors in each column k times number of entries of y
Row vector 'overall'y vs. each row of xTotal number of bit errors k times number of entries of x
'row-wise' (default) y vs. each row of xColumn vector whose entries count bit errors in each row of xk times size of y
Column vector 'overall'y vs. each column of xTotal number of bit errors k times number of entries of x
'column-wise' (default) y vs. each column of xRow vector whose entries count bit errors in each column of xk times size of y

[number,ratio,individual] = biterr(...) returns a matrix individual whose dimensions are those of the larger of x and y. Each entry of individual corresponds to a comparison between a pair of elements of x and y, and specifies the number of bits by which the elements in the pair differ.

## Examples

### Example 1

The commands below compare the column vector [0; 0; 0] to each column of a random binary matrix. The output is the number, proportion, and locations of 1s in the matrix. In this case, individual is the same as the random matrix.

```format rat;
[number,ratio,individual] = biterr([0;0;0],randi([0 1],3,5))```

The output is

```number =

2            0            0            3            1

ratio =

2/3           0            0            1           1/3

individual =

1            0            0            1            0
1            0            0            1            0
0            0            0            1            1
```

### Example 2

The commands below illustrate the use of flg to override the default row-by-row comparison. number and ratio are scalars, and individual has the same dimensions as the larger of the first two arguments of biterr.

```format rat;
[number2,ratio2,individual2] = biterr([1 2; 3 4],[1 3],3,'overall')```

The output is

```number2 =

5

ratio2 =

5/12

individual2 =

0            1
1            3
```

### Example 3

The script below adds errors to 10% of the elements in a matrix. Each entry in the matrix is a two-bit number in decimal form. The script computes the bit error rate using biterr and the symbol error rate using symerr.

```x = randi([0 3],100); % Original signal
% Create errors to add to ten percent of the elements of x.
% Errors can be either 1, 2, or 3 (not zero).
errorplace = (rand(100,100) > .9); % Where to put errors
errorvalue = randi(3,100); % Value of the errors
errors = errorplace.*errorvalue;
y = rem(x+errors,4); % Signal with errors added, mod 4
format short
[num_bit,ratio_bit] = biterr(x,y,2)
[num_sym,ratio_sym] = symerr(x,y)```

Sample output is below. ratio_sym is close to the target value of 0.10. Your results might vary because the example uses random numbers.

```num_bit =

1304

ratio_bit =

0.0652

num_sym =

981

ratio_sym =

0.0981
```

### Example 4

The following example uses logical input arguments.

```SNR = 3; frameLen = 100;
x = randi([0 1], frameLen, 1);
y = awgn(2*x-1, SNR);
z = y > 0;
biterr(x, z)```

### Example 5

The following example uses logical input arguments.

```SNR = 5; frameLen = 100;
x = rand(100, 1) > 0.5;
y = awgn(2*x-1, SNR);
z = y > 0;
biterr(x, z)```