Main Content

Encode and Decode Message with RS Code Using CCSDS Standard

This example shows how to encode and decode a message with Reed-Solomon (RS) code according to the Consultative Committee for Space Data Systems (CCSDS) standard 131.0-B-3 Section 4 [ 1 ].

The Simulink® model in this example contains CCSDS RS Encoder and CCSDS RS Decoder blocks connected back-to-back and are combined under CCSDS RS Encode Decode subsystem. You can generate HDL code only for this subsystem.

Set Up Input Data Parameters

Set up workspace variables for the model to use. You can modify the variable values according to your requirement. The block supports a fixed codeword length of 255.

numFrames = 2;  % Number of input frames
k = 239;        % Message length 223 or 239
s = k;          % Shortened message length in the range 1 to k
i = 5;          % Interleaving depth 1, 2, 3, 4, 5, or 8

Generate Input Samples for Simulink® Model

Generate input samples for the CCSDS RS Encoder block. Generate error samples to be introduced along with the encoder output, to provide as an input to the CCSDS RS Decoder block. Define the input frame gaps required for the blocks.

The CCSDS RS Decoder block does not support back-to-back input frames for shortened lengths (s < k) and when k = 223 and i = 1 or 2.

decFrGap = 0;
if((s<k) || (k==223 && i<3))
    decFrGap = 602-(k*i);    % Minimum gap required between input frames for CCSDS RS Decoder block
end
encFrGap = (255-k)*i;        % Minimum gap required between input frames for CCSDS RS Encoder block
frameGap = encFrGap+decFrGap;

% Generate random input samples
data = uint8(randi([0,255],s*i*numFrames,1));
valid = repmat([true(s*i,1); false((k-s)*i,1); false(frameGap,1)],numFrames,1);
start = repmat([true; false(s*i-1,1); false((k-s)*i,1); false(frameGap,1)],numFrames,1);
endIn = repmat([false(s*i-1,1); true; false((k-s)*i,1); false(frameGap,1)],numFrames,1);

% Generate errors based on the error correction capability of the CCSDS RS
% code
errSymPerFrame = (255-k)/2; % Maximum number of correctable errors per interleaving depth
noise1 = uint8(zeros((255-k+s),i*numFrames));
loc = zeros(errSymPerFrame,i*numFrames);
values = zeros(errSymPerFrame,i*numFrames);
index = 0;
for ii = 1:numFrames
    for jj = 1:i
        index = index+1;
        % Select the error locations such that there are |errSymPerFrame|
        % number of errors per interleaving depth in the decoder input
        loc(:,index) = 255*i*(ii-1)+255*(jj-1)+randperm(255-k+s,errSymPerFrame);
        % Generate random error values
        values(:,index) = randi([1 255],1,errSymPerFrame);
    end
end
noise1(loc) = values;
noise1 = reshape(noise1,[],i,numFrames);
noise = [];
for ii = 1:numFrames
    noise = [noise; reshape(noise1(:,:,ii)',[],1)]; %#ok<AGROW>
end

Run Simulink Model

Running the model imports the input samples to the CCSDS RS Encoder block and encodes the random input samples. It also introduces errors to the encoded output, provides them as input to the CCSDS RS Decoder block, and decodes the erroneous samples.

model = 'ccsdsRSEncoderDecoder';
open_system(model);
set_param([model '/CCSDS RS Encode Decode/CCSDS RS Encoder'],'MessageLength',num2str(k),'InterleavingDepth',num2str(i));
set_param([model '/CCSDS RS Encode Decode/CCSDS RS Decoder'],'MessageLength',num2str(k),'InterleavingDepth',num2str(i));
encLat = 3;
decLat = 3065; % Maximum latency of the CCSDS RS Decoder block
latency = encLat+decLat;
stopTime = (latency + (s*i) + frameGap)*numFrames -1;
sim(model);

Compare CCSDS RS Decoder Block Output with CCSDS RS Encoder Input

Compare the CCSDS RS Decoder block output with the CCSDS RS Encoder input.

decOutput = squeeze(dataOut);
encInput  = data;
fprintf('\n Compare CCSDS RS Decoder Output with CCSDS RS Encoder Input\n');
difference = double(decOutput) - double(encInput);
fprintf(['\nTotal number of samples that differ between CCSDS RS Decoder output ' ...
    'and CCSDS RS Encoder input is: %d \n'],sum(difference));
 Compare CCSDS RS Decoder Output with CCSDS RS Encoder Input

Total number of samples that differ between CCSDS RS Decoder output and CCSDS RS Encoder input is: 0 

References

[1] TM Synchronization and Channel Coding. Recommendation for Space Data System Standards, CCSDS 131.0-B-3. Blue Book. Issue 3. Washington, D.C.: CCSDS, September 2017.

See Also

Blocks

Functions