Main Content

comm.ErrorRate

Compute bit or symbol error rate of input data

Description

The comm.ErrorRate object compares input data from a transmitter with input data from a receiver and calculates the error rate as a running statistic. To obtain the error rate, the object divides the total number of unequal pairs of data elements by the total number of input data elements from one source.

To compute the error rate:

  1. Create the comm.ErrorRate object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Description

example

errorRate = comm.ErrorRate creates an error rate calculator System object™. This object computes the error rate of the received data by comparing it to the transmitted data.

example

errorRate = comm.ErrorRate(Name=Value) sets Properties using one or more name-value arguments. For example, ReceiveDelay = 5 specifies that the received data lags behind the transmitted data by five samples.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Number of samples by which the received data lags behind the transmitted data, specified as a nonnegative integer. Use this property to align the samples for comparison in the transmitted and received input data vectors.

Data Types: double

Number of data samples that the object ignores at the beginning of the comparison, specified as a nonnegative integer. Use this property to ignore the transient behavior of both input signals.

Data Types: double

Samples to consider, specified as one of these values.

  • Entire frame — Compare all the samples of the received data to those of the transmitted frame

  • Custom — Set the indices of the samples to consider when making comparisons in the CustomSamples property

  • Input port — Set the indices of the samples to consider when making comparisons in the ind input

Data Types: char | string

Indices of the samples to consider when comparing data, specified as a positive integer or column vector of positive integers. The default value is an empty vector, which corresponds to the object using all samples from the received frame.

Dependencies

To enable this property, set the Samples property to Custom.

Data Types: double

Enable the reset input, specified as a logical 1 (true) or 0 (false).

Data Types: logical

Usage

Description

example

Y = errorRate(tx,rx) counts the number of differences between transmitted and received data vectors tx and rx, respectively.

example

Y = errorRate(tx,rx,ind) counts the number of differences between the transmitted and received data vectors based on sample indices ind. To enable this syntax, set the Samples property to Input port.

Y = errorRate(___,reset) resets the error count when you set the reset input as a nonzero value. To enable this syntax, set the ResetInputPort property to 1 (true).

Input Arguments

expand all

Transmitted data vector, specified as a scalar or column vector.

Note

If you specify the tx or rx input as a scalar, the object compares this value with all elements of the other input. If you specify both inputs as vectors, they must have the same size.

This object accepts variable-size inputs. After the object is locked, you can change the size of each input channel, but you cannot change the number of channels. For more information, see Variable-Size Signal Support with System Objects.

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

Received data vector, specified as a scalar or column vector.

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

Indices of the samples to consider when comparing data, specified as a positive integer or column vector of positive integers.

Dependencies

To enable this input, set the Samples property to Input port.

Data Types: single | double

Reset error count, specified as a logical 1 (true) or 0 (false). To reset the error count between calls to the object, set this property to a nonzero value.

Dependencies

To enable this input, set the ResetInputPort property to 1 (true).

Data Types: double | logical

Output Arguments

expand all

Difference between transmitted and received data, returned as a column vector of the form [R; N; S], where

  • R is the error rate

  • N is the number of errors

  • S is the number of samples compared

Data Types: double

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

Examples

collapse all

Create two binary vectors and determine the error statistics.

Create a bit error rate counter object.

errorRate = comm.ErrorRate;

Create a binary data vector.

tx = [1 0 1 0 1 0 1 0 1 0]';

Introduce errors to the first and last bits.

rx = tx;
rx(1) = ~rx(1);
rx(end) = ~rx(end);

Calculate the difference between the transmitted and received data.

y = errorRate(tx,rx);

Display the bit error rate.

y(1)
ans = 0.2000

Display the number of errors.

y(2)
ans = 2

Display the total number samples used for comparison.

y(3)
ans = 10

Create an 8-DPSK modulator and demodulator pair that work with binary data.

dpskModulator = comm.DPSKModulator( ...
    ModulationOrder=8,BitInput=true);
dpskDemodulator = comm.DPSKDemodulator( ...
    ModulationOrder=8,BitOutput=true);

Create an error rate calculator, accounting for the three bit (one symbol) transient caused by the differential modulation.

errorRate = comm.ErrorRate( ...
    ComputationDelay=3,Samples="Input port");

Calculate and display the BER for 10 frames for the specified sample indices.

BER = zeros(10,1);
ind = (1:3:96)';

for i = 1:10
    tx = randi([0 1],96,1);      % Generate binary data
    modData = dpskModulator(tx); % Modulate
    rxSig = awgn(modData,7);     % Pass through AWGN channel
    rx = dpskDemodulator(rxSig); % Demodulate
    y = errorRate(tx,rx,ind);    % Compute error statistics
    BER(i) = y(1);               % Save BER data
end
BER
BER = 10×1

    0.0968
    0.1111
    0.0737
    0.0787
    0.0881
    0.0838
    0.0807
    0.0784
    0.0836
    0.0846

Extended Capabilities

Version History

Introduced in R2012a

expand all