Main Content

biterr

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

Description

[number,ratio] = biterr(x,y) compares the unsigned binary representation of elements in x to those in 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 x and y based on their sizes. For more information, see the Algorithms section.

example

[number,ratio] = biterr(x,y,k) also specifies k, the maximum number of bits for each element in x and y. If the unsigned binary representation of any element in x or y is more than k digits, the function errors.

[number,ratio] = biterr(x,y,k,flag) specifies a flag to override default settings for how the function compares the elements and computes the outputs. For more information, see the Algorithms section.

example

[number,ratio,individual] = biterr(___) returns the binary comparison result of x and y as matrix individual. You can specify any of the input argument combination from the previous syntaxes.

Examples

collapse all

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 behavior.

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

Convert the EbN0 values to SNR.

snrdB =convertSNR(EbNoVec,"ebno","snr",BitsPerSymbol=k);

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.

The while loop continues to process data until either 200 errors are encountered or 1e7 bits are transmitted.

for n = 1:length(snrdB)
    % 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,1);
        dataSym = bit2int(dataIn,k);
        
        % QAM modulate using 'Gray' symbol mapping
        txSig = qammod(dataSym,M);
        
        % Pass through AWGN channel
        rxSig = awgn(txSig,snrdB(n),'measured');
        
        % Demodulate the noisy signal
        rxSym = qamdemod(rxSig,M);
        % Convert received symbols to bits
        dataOut = int2bit(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 berawgn function.

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

Figure contains an axes object. The axes object with xlabel Eb/No (dB), ylabel Bit Error Rate contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Estimated BER, Theoretical BER.

Input Arguments

collapse all

Inputs to be compared, specified as separate arguments, as a vector or matrix of nonnegative integer elements. The function converts each element of x and y to its unsigned binary representation for comparison.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Maximum number of bits for input elements of x and y, specified as a positive integer. If the number of bits required for binary representation of any element in x or y is greater than k, the function errors.

If you do not set k, the function sets it as the number of bits in the binary representation of the largest element in x and y.

Data Types: single | double

Flag to override default settings of the function, specified as 'overall', 'row-wise', or 'column-wise'. Flag specifies how the function compares elements in inputs x,y and computes the output. For more information, see the Algorithms section.

Data Types: string | char

Output Arguments

collapse all

Number of bit errors, returned as a nonnegative integer or integer vector.

Data Types: single | double

Bit error rate, returned as a scalar. ratio is the number of bit errors, number, to the total number of bits used in the binary representation. The total number of bits is k times the number of entries in the smaller of the inputs x,y.

Results of each individual binary comparison, returned as a matrix whose dimensions are those of the larger of inputs x and y. Each element specifies the number of bits by which the elements in the pair differ. For more information, see the Algorithms section.

Data Types: single | double

Algorithms

collapse all

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a

expand all