Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

comm.CRCDetector System object

Package: comm

Detect errors in input data using CRC

Description

The CRCDetector object computes checksums for its entire input frame.

To detect errors in the input data using cyclic redundancy code:

  1. Define and set up your CRC detector object. See Construction.

  2. Call step to detect errors according to the properties of comm.CRCDetector. The behavior of step is specific to each object in the toolbox.

    Note:   Starting in R2016b, instead of using the step method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

Construction

H = comm.CRCDetector creates a cyclic redundancy code (CRC) detector System object, H. This object detects errors in the input data according to a specified generator polynomial.

H = comm.CRCDetector(Name,Value) creates a CRC detector object, H, with each specified property set to the specified value. You can specify additional name-value pair arguments in any order as (Name1,Value1,...,NameN,ValueN).

H = comm.CRCDetector(POLY,Name,Value) creates a CRC detector object, H. This object has the Polynomial property set to POLY, and the other specified properties set to the specified values.

Properties

Polynomial

Generator polynomial

Specify the generator polynomial as a binary or integer row vector, with coefficients in descending order of powers, or as a polynomial character vector. The default is 'z^16 + z^12 + z^5 + 1'. If you set this property to a binary vector, its length must equal the degree of the polynomial plus 1. If you set this property to an integer vector, its value must contain the powers of the nonzero terms of the polynomial. For example, [1 0 0 0 0 0 1 0 1] and [8 2 0] represent the same polynomial, g(z)=z8+z2+1. The following table lists commonly used generator polynomials.

CRC methodGenerator polynomial
CRC-32'z^32 + z^26 + z^23 + z^22 + z^16 + z^12 + z^11 + z^10 + z^8 + z^7 + z^5 + z^4 + z^2 + z + 1'
CRC-24 'z^24 + z^23 + z^14 + z^12 + z^8 + 1'
CRC-16 'z^16 + z^15 + z^2 + 1'
Reversed CRC-16'z^16 + z^14 + z + 1'
CRC-8'z^8 + z^7 + z^6 + z^4 + z^2 + 1'
CRC-4 'z^4 + z^3 + z^2 + z + 1'

InitialConditions

Initial conditions of shift register

Specify the initial conditions of the shift register as a binary, double or single precision data type scalar or vector. The default is 0. The vector length is the degree of the generator polynomial that you specify in the Polynomial property. When you specify initial conditions as a scalar, the object expands the value to a row vector of length equal to the degree of the generator polynomial.

DirectMethod

Direct method (logical)

When you set this property to true, the object uses the direct algorithm for CRC checksum calculations. When you set this property to false, the object uses the non-direct algorithm for CRC checksum calculations. The default value for this property is false.

Refer to the Communications System Toolbox -> System Design -> Error Detection and Correction -> Cyclic Redundancy Check Coding -> CRC Algorithm section to learn more about the direct and non-direct algorithms.

ReflectInputBytes

Reflect input bytes

Set this property to true to flip the input data on a bytewise basis prior to entering the data into the shift register. When you set this property to true, the input frame length divided by the ChecksumsPerFrame property value minus the degree of the generator polynomial, which you specify in the Polynomial property, must be an integer multiple of 8. The default value of this property is false.

ReflectChecksums

Reflect checksums before final XOR

When you set this property to true, the object flips the CRC checksums around their centers after the input data are completely through the shift register. The default value of this property is false.

FinalXOR

Final XOR value

Specify the value with which the CRC checksum is to be XORed as a binary scalar or vector. The object applies the XOR operation just prior to appending the input data. The vector length is the degree of the generator polynomial that you specify in the Polynomial property. When you specify the final XOR value as a scalar, the object expands the value to a row vector with a length equal to the degree of the generator polynomial. The default value of this property is 0, which is equivalent to no XOR operation.

ChecksumsPerFrame

Number of checksums per input frame

Specify the number of checksums available at each input frame. The default is 1. If the length of the input frame to the step method equals N and the degree of the generator polynomial equals P, then NCheckSumsPerFrame×P must be divisible by ChecksumsPerFrame. The object sets the size of the message word as NCheckSumsPerFrame×P, after the checksum bits have been removed from the input frame. This message word corresponds to the first output of the step method. The step method then outputs a vector, with length equal to the value that you specify in this property.

For example, you can set the input codeword size to 16 and the generator polynomial to a degree of 3. Then, you can set the InitialConditions property to 0 and this property to 2 When you do so, the system object:

  1. Computes two checksums of size 3. One checksum comes from the first half of the received codeword, and the other from the second half of the received codeword.

  2. Concatenates the two halves of the message word as a single vector of length 10. Then, outputs this vector through the first output of the step method.

  3. Outputs a length 2 binary vector through the second output of the step method.

The vector values depend on whether the computed checksums are zero. A 1 in the i-th element of the vector indicates that an error occurred in transmitting the corresponding i-th segment of the input codeword.

Methods

cloneCreate CRC detector object with same property values
getNumInputsNumber of expected inputs to step method
getNumOutputsNumber of outputs from step method
isLockedLocked status for input attributes and nontunable properties
releaseAllow property value and input characteristics changes
resetReset states of CRC detector object
stepDetect errors in input data using CRC

Examples

expand all

Pass binary data through a CRC generator, introduce a bit error, and detect the error using a CRC detector.

Create a random binary vector.

msg = randi([0 1],12,1);

Encode the message words using a CRC generator with the ChecksumsPerFrame property set to 2. This subdivides the incoming message into two equal length subframes.

gen = comm.CRCGenerator([1 0 0 1],'ChecksumsPerFrame',2);
codeword = step(gen,msg);

Decode the message and verify that there are no errors in either subframe.

detect = comm.CRCDetector([1 0 0 1],'ChecksumsPerFrame',2);
[~, err] = step(detect,codeword)
err =

     0
     0

Introduce an error in the second subframe by inverting the last element of subframe 2. Pass the corrupted codeword through the CRC detector and verify that the error is detected in the second subframe.

codeword(end) = not(codeword(end));
[~,err] = step(detect,codeword)
err =

     0
     1

Use a CRC code to detect frame errors in a noisy BPSK signal.

Create a CRC generator and detector pair using a standard CRC-4 polynomial, $z^4 + z^3 + z^2 + z + 1$.

crcGen = comm.CRCGenerator('z4+z3+z2+z+1');
crcDet = comm.CRCDetector('z4+z3+z2+z+1');

Generate 12-bit frames of binary data and append CRC bits. Based on the degree of the polynomial, 4 bits are appended to each frame. Apply BPSK modulation and pass the signal through an AWGN channel. Demodulate and use the CRC detector to determine if the frame is in error.

numFrames = 20;
frmError = zeros(numFrames,1);

for k = 1:numFrames
    data = randi([0 1],12,1);                   % Generate binary data
    encData = step(crcGen,data);                % Append CRC bits
    modData = pskmod(encData,2);                % BPSK modulate
    rxSig = awgn(modData,5);                    % AWGN channel, SNR = 5 dB
    demodData = pskdemod(rxSig,2);              % BPSK demodulate
    [~,frmError(k)] = step(crcDet,demodData);  % Detect CRC errors
end

Identify the frames in which bit errors are detected.

find(frmError)
ans =

     6

Algorithms

This object implements the algorithm, inputs, and outputs described on the CRC-N Syndrome Detector block reference page. The object properties correspond to the block parameters.

Was this topic helpful?