Main Content

crcDetect

Detect errors in input data using CRC parity bits

Since R2024a

Description

[msg,err] = crcDetect(codeword,crcCfg) computes checksums to detect errors in an input codeword based on the specified CRC configuration object and returns the checksum error signal when checking CRC code bits for each codeword subframe. For more information, see Algorithms.

example

Examples

collapse all

Generate 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 3-bit CRC generator.

cfgObj = crcConfig(Polynomial='z^3 + 1',ChecksumsPerFrame=2);
codeword = crcGenerate(x,cfgObj);

Add one bit error to each codeword.

errorPattern = randerr(2,9,1).';
codewordWithError = xor(codeword,errorPattern(:));

Decode messages with and without errors. The crcDetect function reports no errors in the transmitted message words for codeword and reports errors in both transmitted message words for codewordWithError.

[tx,err] = crcDetect(codeword,cfgObj);
[tx1,err1] = crcDetect(codewordWithError,cfgObj);
disp(err)
   0
   0
disp(err1)
   1
   1

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

Create a CRC configuration object assigning a standard CRC-4 polynomial, z4+z3+z2+z+1.

poly = '0x1F';
crcCfg = crcConfig(Polynomial=poly);

Generate 12-bit frames of binary data and append the 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);
    encData = crcGenerate(data,crcCfg);
    modData = pskmod(encData,2);
    rxSig = awgn(modData,5);
    demodData = pskdemod(rxSig,2);
    [~,frmError(k)] = crcDetect(demodData,crcCfg);
end

Identify the frames in which CRC code bit errors are detected.

find(frmError)
ans =

  0×1 empty double column vector

Input Arguments

collapse all

Received codeword, specified as binary values in a column vector or matrix. When the received codeword is a matrix, the function processes each column independently.

Data Types: double | int8 | logical

CRC configuration, specified as a crcConfig object.

Data Types: crcConfig object

Output Arguments

collapse all

Output message, returned as binary values in a column vector or matrix with the same data type and number of columns as input codeword. The message word output contains the received codeword with the checksums removed.

The length of the output frame is NC × P bits, where N is the column length of the received codeword, C is the number of checksums per frame (crcCfg.ChecksumsPerFrame), and P is the degree of the generator polynomial (crcCfg.Polynomial).

Checksum error signal, returned as binary values in a column vector or matrix with the same data type and number of columns as input codeword. The number of rows of err equals the value of crcCfg.ChecksumsPerFrame. For each checksum computation, an element value of 0 in err indicates no checksum error, and an element value of 1 in err indicates a checksum error.

Algorithms

collapse all

References

[1] Sklar, Bernard. Digital Communications: Fundamentals and Applications. Englewood Cliffs, NJ: Prentice-Hall, 1988.

[2] Wicker, Stephen B. Error Control Systems for Digital Communication and Storage. Upper Saddle River, NJ: Prentice Hall, 1995.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2024a