Main Content

crc.detector

(Removed) Construct CRC detector object

crc.detector has been removed. To detect errors in input data using cyclic redundancy check (CRC), use the comm.CRCDetector System object instead. For more details on the recommended workflow, see Version History.

Syntax

h= crc.detector(polynomial)

h= crc.detector(generatorObj)

h= crc.detector(‘Polynomial’, polynomial, ‘param1’, val1, etc.)

h= crc.detector

Description

h= crc.detector(polynomial) constructs a CRC detector object H defined by the generator polynomial POLYNOMIAL

h= crc.detector(generatorObj) constructs a CRC detector object H defined by the parameters found in the CRC generator object GENERATOROBJ

h= crc.detector('property1', val1, ...) constructs a CRC detector object H with properties as specified by PROPERTY/VALUE pairs.

h= crc.detector constructs a CRC detector object H with default properties. It constructs a CRC-CCITT detector, and is equivalent to:

h= crc.detector('Polynomial','0x1021','InitialState','0xFFFF','ReflectInput',false,'ReflectRemainder',false,'FinalXOR','0x0000')

Properties

The following table describes the properties of a CRC detector object. All properties are writable, except Type.

PropertyDescription
TypeSpecifies the object as a 'CRC Detector'.
PolynomialThe generator polynomial that defines connections for a linear feedback shift register. This property can be specified as a binary vector representing descending powers of the polynomial. In this case, the leading '1' of the polynomial must be included. It can also be specified as a string, prefaced by '0x', that is a hexadecimal representation of the descending powers of the polynomial. In this case, the leading '1' of the polynomial is omitted.
InitialStateThe initial contents of the shift register. This property can be specified as a binary scalar, a binary vector, or as a string, prefaced by '0x', that is a hexadecimal representation of the binary vector. As a binary vector, its length must be one less than the length of the binary vector representation of the Polynomial.
ReflectInputA Boolean quantity that specifies whether the input data should be flipped on a bytewise basis prior to entering the shift register.
ReflectRemainderA Boolean quantity that specifies whether the binary output CRC checksum should be flipped around its center after the input data is completely through the shift register.
FinalXORThe value with which the CRC checksum is to be XORed just prior to detecting the input data. This property can be specified as a binary scalar, a binary vector or as a string, prefaced by '0x', that is a hexadecimal representation of the binary vector. As a binary vector, its length must be one less than the length of the binary vector representation of the Polynomial.

A detect method is used with the object to detect errors in digital transmission.

CRC Generation Algorithm

For information pertaining to the CRC generation algorithm, see Cyclic Redundancy Check Codes.

Detector Method

[OUTDATA ERROR] = DETECT(H, INDATA) detects transmission errors in the encoded input message INDATA by regenerating a CRC checksum using the CRC detector object H. The detector then compares the regenerated checksum with the checksum appended to INDATA. The binary-valued INDATA can be either a column vector or a matrix. If it is a matrix, each column is considered to be a separate channel. OUTDATA is identical to the input message INDATA, except that it has the CRC checksum stripped off. ERROR is a 1xC logical vector indicating if the encoded message INDATA has errors, where C is the number of channels in INDATA. An ERROR value of 0 indicates no errors, and a value of 1 indicates errors.

Examples

Create a CRC-16 CRC generator, then use it to generate a checksum for the binary vector represented by the ASCII sequence '123456789'. Introduce an error, then detect it using a CRC-16 CRC detector.

gen = crc.generator('Polynomial', '0x8005', 'ReflectInput', ...
true, 'ReflectRemainder', true);
det = crc.detector('Polynomial', '0x8005', 'ReflectInput', ...
true, 'ReflectRemainder', true);
% The message below is an ASCII representation
% of the digits 1-9
msg = int2bit((49:57)',8);
encoded = generate(gen, msg);
encoded(1) = ~encoded(1);                % Introduce an error
[outdata error] = detect(det, encoded);  % Detect the error
noErrors = isequal(msg, outdata)         % Should be 0
error                                    % Should be 1

This example generates the following output:

noErrors = 0 error = 1 

Version History

Introduced in R2008a

expand all

R2023b: Removed

crc.detector has been removed. To detect errors in input data using cyclic redundancy check (CRC), use the comm.CRCDetector System object instead.

Replace instances of crc.detector with a comm.CRCDetector System object. Note the mapping between crc.detector properties and comm.CRCDetector properties:

crc.detectorcomm.CRCDetector
PolynomialPolynomial
InitialStateInitialConditions
ReflectInputReflectInputBytes
ReflectRemainderReflectChecksums
FinalXORFinalXOR

See the following table for examples of migrating the old workflow to the recommended workflow.

Previous WorkflowRecommended Workflow
oldO = crc.generator;
oldOdet = crc.detector

data = randi([0 1],100,1);

enc_old = generate(oldO,data);

[dec_old, err_old] = detect(oldOdet,enc_old);
oldOdet = 

                Type: CRC Detector
          Polynomial: 0x1021
        InitialState: 0xFFFF
        ReflectInput: false
    ReflectRemainder: false
            FinalXOR: 0x0000
sysO = comm.CRCGenerator('InitialConditions',1);
sysOdet = comm.CRCDetector('InitialConditions',1)

data = randi([0 1],100,1);

enc_new = sysO(data);

[dec_new, err] = sysOdet(enc_new);
sysOdet = 

  comm.CRCDetector with properties:

           Polynomial: 'z^16 + z^12 + z^5 + 1'
    InitialConditions: 1
         DirectMethod: false
    ReflectInputBytes: false
     ReflectChecksums: false
             FinalXOR: 0
    ChecksumsPerFrame: 1
oldO = crc.generator([1 1 1 1 1]);
oldOdet = crc.detector([1 1 1 1 1])


data = randi([0 1],100,1);
enc_old = generate(oldO,data);
[dec_old, err_old] = detect(oldOdet,enc_old);
oldOdet = 

                Type: CRC Detector
          Polynomial: 0xF
        InitialState: 0x0
        ReflectInput: false
    ReflectRemainder: false
            FinalXOR: 0x0
sysO = comm.CRCGenerator('Polynomial',[1 1 1 1 1]);
sysOdet = comm.CRCDetector('Polynomial',[1 1 1 1 1])

data = randi([0 1],100,1);
enc_new = sysO(data);
[dec_new, err] = sysOdet(enc_new);
sysOdet = 

  comm.CRCDetector with properties:

           Polynomial: [1 1 1 1 1]
    InitialConditions: 0
         DirectMethod: false
    ReflectInputBytes: false
     ReflectChecksums: false
             FinalXOR: 0
    ChecksumsPerFrame: 1