Main Content

Check for CRC Errors in Streaming Samples

R2026b

This example shows how to use the LTE CRC Decoder block to check encoded data, and how to compare the hardware-friendly design with the results from LTE Toolbox™. The workflow follows these steps:

  1. Generate frames of random input samples in MATLAB.

  2. Generate and append the CRC checksum using the LTE Toolbox function lteCRCEncode.

  3. Convert framed input data and checksum to a stream of samples and import it to Simulink®.

  4. To check the samples against the checksum using a hardware-friendly architecture, run the Simulink model. The model contains the Wireless HDL Toolbox™ block LTE CRC Decoder.

  5. Export the stream of samples back to the MATLAB® workspace.

  6. Convert the sample stream back to framed data, and compare the frames with the reference data.

Generate input data frames, then generate the CRC checksum using lteCRCEncode.

frameLength = 256;
numframes   = 2;
rng(0);

txframes     = cell(1,numframes);
txcodeword   = cell(1,numframes);
rxSoftframes = cell(1,numframes);

for ii = 1:numframes

    txframes{ii}  = randi([0 1],frameLength,1)>0.5;

    CRCType = '24B';
    CRCMask = 50;
    txcodeword{ii} = boolean(lteCRCEncode(txframes{ii},CRCType,CRCMask));

end

Serialize input data for the Simulink model. The LTE CRC Decoder block does not require any space between frames, but the hardware-friendly algorithm adds latency of (3 * _CRCLength_ / SampleSize) + 5 cycles. This example uses scalar input samples, so the latency is (3 * _CRCLength_) + 5.

idleCyclesBetweenSamples = 0;
idleCyclesBetweenFrames  = 77;
samplesizeIn             = 1;

[sampleIn,ctrlIn] = whdlFramesToSamples(...
    txcodeword,idleCyclesBetweenSamples,idleCyclesBetweenFrames,samplesizeIn);

Run the Simulink model.

sampletime = 1;
simTime = length(ctrlIn);
modelName = 'ltehdlCRCDecoderModel';
open_system(modelName);
sim(modelName);

The Simulink model exports sampleOut and ctrlOut back to the MATLAB workspace. Deserialize the output samples, and compare the framed data to the input frames.

txhdlframes = whdlSamplesToFrames(sampleOut,ctrlOut);

fprintf('\nLTE CRC Decoder\n');
for ii = 1:numframes
    numBitsDiff = sum(double(txframes{ii})-double(txhdlframes{ii}));
    fprintf(['  Frame %d: Behavioral and ' ...
        'HDL simulation differ by %d bits\n'], ii, numBitsDiff);
end
Maximum frame size computed to be 256 samples.

LTE CRC Decoder
  Frame 1: Behavioral and HDL simulation differ by 0 bits
  Frame 2: Behavioral and HDL simulation differ by 0 bits

See Also

Blocks

Functions

Topics