Number of bit errors and bit error rate (BER)
compares the unsigned binary representation of elements in
ratio] = biterr(
x to those
y. The function returns
number, the number of
bits that differ in the comparison, and
ratio, the ratio of
number to the total number of bits. The function determines the order
in which it compares
y based on their sizes.
For more information, see the Algorithms section.
Bit Error Rate Computation
Create two binary matrices.
x = [0 0; 0 0; 0 0; 0 0]
x = 4×2 0 0 0 0 0 0 0 0
y = [0 0; 0 0; 0 0; 1 1]
y = 4×2 0 0 0 0 0 0 1 1
Determine the number of bit errors.
numerrs = biterr(x,y)
numerrs = 2
Compute the number of column-wise errors .
numerrs = biterr(x,y,,'column-wise')
numerrs = 1×2 1 1
Compute the number of row-wise errors.
numerrs = biterr(x,y,,'row-wise')
numerrs = 4×1 0 0 0 2
Compute the number of overall errors. Behavior is the same as the default behaviour.
numerrs = biterr(x,y,,'overall')
numerrs = 2
Estimate Bit Error Rate for 64-QAM in AWGN
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 these 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 demodulated 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 by using the
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')
x,y — Inputs to be compared (as separate arguments)
vector | matrix
Inputs to be compared, specified as separate arguments, as a vector or matrix of
nonnegative integer elements. The function converts each element of
y to its unsigned binary
representation for comparison.
k — Maximum number of bits for input elements
Maximum number of bits for input elements of
y, specified as a positive integer. If the number of bits
required for binary representation of any element in
y is greater than
k, the function
If you do not set
k, the function sets it as the number of bits
in the binary representation of the largest element in
flag — Flag to override default settings
Flag to override default settings of the function, specified as
'column-wise'. Flag specifies how the function compares elements in
x,y and computes the output. For more information, see the
number — Number of bit errors
nonnegative integer | integer vector
Number of bit errors, returned as a nonnegative integer or integer vector.
individual — Results of each individual binary comparison
Results of each individual binary comparison, returned as a matrix whose dimensions
are those of the larger of inputs
Each element specifies the number of bits by which the elements in the pair differ. For
more information, see the Algorithms
Comparing Inputs Based on Sizes
The function uses the sizes of
determine the order in which it compares their elements.
If inputs are matrices of the same dimensions, then the function compares the inputs element by element.
numberis a nonnegative integer in this case. For example, see case (a) in the figure.
If one input is a matrix and the other input is a column vector, then the function compares each column of the matrix element by element with the column vector. The number of rows in the matrix must be equal to the length of the column vector. In other words, if the matrix has dimensions m-by-n, then the column vector must have dimensions m-by-1. For example, see case (b) in the figure.
If one input is a matrix and the other input is a row vector, then the function compares each row of the matrix element by element with the row vector. The number of columns in the matrix must be equal to the length of the row vector. In other words, if the matrix has dimensions m-by-n, then the row vector must have dimensions 1-by-n. For example, see case (c) in the figure.
Comparing Inputs Based on Flag
This table describes how the output is computed based on the different values of
x is considered as a matrix in this table
and the size of
y is varied.
|Size of ||Type of Comparison||Total Number of Bits|
|Matrix||Element by element||Total number of bit errors|
|mth row of ||Column vector whose elements represent the bit errors in each row|
|mth column of ||Row vector whose elements represent the bit errors in each column|
|Row vector||Total number of bit errors|
|Column vector whose elements represent the bit errors in each row of
|Column vector||Total number of bit errors|
|Row vector whose elements represent bit errors in each column of