Main Content

crc.generator

(Removed) Construct CRC generator object

crc.generator has been removed. To generate cyclic redundancy check (CRC) code bits, use the comm.CRCGenerator System object instead. For more details on the recommended workflow, see Version History.

Syntax

h = crc.generator(polynomial)

h = crc.generator(detectorObj)

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

h = crc.generator

Description

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

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

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

h = crc.generator constructs a CRC generator object H with default properties. It constructs a CRC-CCITT generator, and is equivalent to: h = crc.generator('Polynomial', '0x1021', 'InitialState', '0xFFFF', ...

'ReflectInput', false, 'ReflectRemainder', false, 'FinalXOR', '0x0000').

Properties

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

PropertyDescription
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 being appended to 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.

CRC Generation Algorithm

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

Generator Method

encoded = generate(h, msg) generates a CRC checksum for an input message using the CRC generator object H. It appends the checksum to the end of MSG. The binary-valued MSG can be either a column vector or a matrix. If it is a matrix, then each column is considered to be a separate channel.

Examples

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

gen = crc.generator('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);
h = 

                Type: CRC Generator
          Polynomial: 0xF
        InitialState: 0xF
        ReflectInput: true
    ReflectRemainder: false
            FinalXOR: 0x0

Version History

Introduced in R2008a

expand all

R2023b: Removed

crc.generator has been removed. To generate cyclic redundancy check (CRC) code, use the comm.CRCGenerator System object instead.

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

crc.generatorcomm.CRCGenerator
PolynomialPolynomial
InitialStateInitialConditions
ReflectInputReflectInputBytes
ReflectRemainderReflectchecksums
FinalXORFinalXOR

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

Previous WorkflowRecommended Workflow
data = randi([0 1],100,1);
oldO = crc.generator
encOld = generate(oldO,data);
oldO = 

                Type: CRC Generator
          Polynomial: 0x1021
        InitialState: 0xFFFF
        ReflectInput: false
    ReflectRemainder: false
            FinalXOR: 0x0000
data = randi([0 1],100,1);

sysO = comm.CRCGenerator('InitialConditions',1)
encNew = sysO(data);
sysO = 

  comm.CRCGenerator with properties:

           Polynomial: 'z^16 + z^12 + z^5 + 1'
    InitialConditions: 1
         DirectMethod: false
    ReflectInputBytes: false
     ReflectChecksums: false
             FinalXOR: 0
    ChecksumsPerFrame: 1
data = randi([0 1],96,1);

oldO = crc.generator('Polynomial', '0xF', 'InitialState', '0xF',...
'ReflectInput', true, 'FinalXOR', '0x0')

encOld = generate(oldO,data);
 Type: CRC Generator
          Polynomial: 0xF
        InitialState: 0xF
        ReflectInput: true
    ReflectRemainder: false
            FinalXOR: 0x0
data = randi([0 1],96,1);

sysO = comm.CRCGenerator('Polynomial',...
'0x1F','InitialConditions', [1 1 1 1],...
'ReflectInputBytes', true, 'FinalXOR', 0)

encNew = sysO(data);
sysO = 

  comm.CRCGenerator with properties:

           Polynomial: '0x1F'
    InitialConditions: [1 1 1 1]
         DirectMethod: false
    ReflectInputBytes: true
     ReflectChecksums: false
             FinalXOR: 0
    ChecksumsPerFrame: 1
data = randi([0 1],100,5); 

oldO = crc.generator([1 1 1 1 1])
 
encOld = generate(oldO,data);
oldO = 

                Type: CRC Generator
          Polynomial: 0xF
        InitialState: 0x0
        ReflectInput: false
    ReflectRemainder: false
            FinalXOR: 0x0
data = randi([0 1],100,5); 

sysO = comm.CRCGenerator('Polynomial',[1 1 1 1 1],...
 'ChecksumsPerFrame',5)

encNew = sysO(data(:));
sysO = 

  comm.CRCGenerator with properties:

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