Detect errors in input data using CRC
The CRCDetector object computes checksums for its entire input frame.
To detect errors in the input data using cyclic redundancy code:
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.
Specify the generator polynomial as a binary or integer row vector, with coefficients in descending order of powers. The default is [1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1], which is equivalent to vector [16 12 5 0]. 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, . The following table lists commonly used generator polynomials.
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.
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.
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.
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.
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.
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 NCheckSumsPerFrameP must be divisible by ChecksumsPerFrame. The object sets the size of the message word as NCheckSumsPerFrameP, 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 the 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 the this property to 2 When you do so, the system object:
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.
|clone||Create CRC detector object with same property values|
|getNumInputs||Number of expected inputs to step method|
|getNumOutputs||Number of outputs from step method|
|isLocked||Locked status for input attributes and nontunable properties|
|release||Allow property value and input characteristics changes|
|reset||Reset states of CRC detector object|
|step||Detect errors in input data using CRC|
Encode a signal and then detect the errors.
% Transmit two message words of length 6 x = logical([1 0 1 1 0 1 0 1 1 1 0 1]'); % Encode the message words using a CRC generator hGen = comm.CRCGenerator([1 0 0 1], 'ChecksumsPerFrame',2); codeword = step(hGen, x); % Add one bit error to each codeword errorPattern = randerr(2,9,1).'; codewordWithError = xor(codeword, errorPattern(:)); % Decode messages with and without errors using a CRC decoder hDetect = comm.CRCDetector([1 0 0 1], 'ChecksumsPerFrame',2); [tx, err] = step(hDetect, codeword); [tx1, err1] = step(hDetect, codewordWithError); disp(err) % err is [0;0], no errors in transmitted message words disp(err1) % err1 is [1;1], errors in both transmitted message words
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.