Compute number of bit errors and bit error rate (BER)
[number,ratio] = biterr(x,y)
[number,ratio] = biterr(x,y,k)
[number,ratio] = biterr(x,y,k,
[number,ratio,individual] = biterr(...)
biterr function compares unsigned binary
representations of elements in
x with those in
The schematics below illustrate how the shapes of
Each element of
be a nonnegative decimal integer;
each element into its natural unsigned binary representation.
a scalar or vector that indicates the number of bits that differ.
by the total number of bits. The total number
of bits, the size of
number, and the elements that
are determined by the dimensions of
by the optional parameters.
[number,ratio] = biterr(x,y) compares
the elements in
the largest among all elements of
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
which elements are compared:
matrices of the same dimensions, then
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
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
y to have
The total number of bits is
k times the number
of entries of the smaller of
An error occurs if the binary representation of an element of
require more than
[number,ratio] = biterr(x,y,k, is
similar to the previous syntaxes, except that
override the defaults that govern which elements
biterr computes the outputs. The possible
The table below describes the differences that result from various
combinations of inputs. As always,
by the total number of bits. If you do not provide
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
Comparing a Two-Dimensional Matrix x with Another Input y
|Shape of y||flg||Type of Comparison||number||Total Number of Bits|
|2-D matrix||Element by element||Total number of bit errors|
|mth row of ||Column vector whose entries count bit errors in each row|
|mth column of ||Row vector whose entries count bit errors in each column|
|Row vector||Total number of bit errors|
|Column vector whose entries count bit errors in each row of |
|Column vector||Total number of bit errors|
|Row vector whose entries count bit errors in each column of |
[number,ratio,individual] = biterr(...) returns
individual whose dimensions are those
of the larger of
individual corresponds to a comparison
between a pair of elements of
and specifies the number of bits by which the elements in the pair
Create two binary matrices.
x = [0 0; 0 0; 0 0; 0 0]
x = 0 0 0 0 0 0 0 0
y = [0 0; 0 0; 0 0; 1 1]
y = 0 0 0 0 0 0 1 1
Determine the number of bit errors.
numerrs = biterr(x,y)
numerrs = 2
Determine the number of errors computed column-wise.
numerrs = biterr(x,y,,'column-wise')
numerrs = 1 1
Compute the number of row-wise errors.
numerrs = biterr(x,y,,'row-wise')
numerrs = 0 0 0 2
Compute the number of overall errors. This has the same behavior as the default.
numerrs = biterr(x,y,,'overall')
numerrs = 2
Demodulate a noisy 64-QAM signal and estimate the bit error rate (BER) for a range of Eb/No values. Compare the BER estimate to theoretical values.
Set the simulation parameters.
M = 64; % Modulation order k = log2(M); % Bits per symbol EbNoVec = (5:15)'; % Eb/No values (dB) numSymPerFrame = 100; % Number of QAM symbols per frame
Initialize the results vector.
berEst = zeros(size(EbNoVec));
The main processing loop executes the following steps:
Generate binary data and convert to 64-ary symbols
QAM modulate the data symbols
Pass the modulated signal through an AWGN channel
Demodulate the received signal
Convert the demoduated symbols into binary data
Calculate the number of bit errors
while loop continues to process data until either 200 errors are encountered or 1e7 bits are transmitted.
for n = 1:length(EbNoVec) % Convert Eb/No to SNR snrdB = EbNoVec(n) + 10*log10(k); % Reset the error and bit counters numErrs = 0; numBits = 0; while numErrs < 200 && numBits < 1e7 % Generate binary data and convert to symbols dataIn = randi([0 1],numSymPerFrame,k); dataSym = bi2de(dataIn); % QAM modulate using 'Gray' symbol mapping txSig = qammod(dataSym,M); % Pass through AWGN channel rxSig = awgn(txSig,snrdB,'measured'); % Demodulate the noisy signal rxSym = qamdemod(rxSig,M); % Convert received symbols to bits dataOut = de2bi(rxSym,k); % Calculate the number of bit errors nErrors = biterr(dataIn,dataOut); % Increment the error and bit counters numErrs = numErrs + nErrors; numBits = numBits + numSymPerFrame*k; end % Estimate the BER berEst(n) = numErrs/numBits; end
Determine the theoretical BER curve using
berTheory = berawgn(EbNoVec,'qam',M);
Plot the estimated and theoretical BER data. The estimated BER data points are well aligned with the theoretical curve.
semilogy(EbNoVec,berEst,'*') hold on semilogy(EbNoVec,berTheory) grid legend('Estimated BER','Theoretical BER') xlabel('Eb/No (dB)') ylabel('Bit Error Rate')