Main Content

Decode and Recover Message from RS Codeword Using CCSDS Standard

This example shows how to use the CCSDS RS Decoder block to decode and recover a message from a Reed-Solomon (RS) codeword according to the Consultative Committee for Space Data Systems (CCSDS) standard. Generate and encode a set of random inputs and then provide them as input to the ccsdsRSDecode (Satellite Communications Toolbox) function and the CCSDS RS Decoder block by adding errors. Compare the output of the CCSDS RS Decoder block with the output of the ccsdsRSDecode function. The example model supports HDL code generation for the HDL CCSDS RS Decoder subsystem.

Set Up Input Data Parameters

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

k = 239;        % Message length 223 or 239
s = k;          % Shortened message length ranges from 1 to k
i = 4;          % Interleaving depth 1, 2, 3, 4, 5, or 8
numFrames = 3;  % Number of input frames
numErrors = 16; % Maximum number of correctable errors allowed in the input frame is (255-k)*i/2

Generate Random Input Samples

Generate random samples using the specified message length, shortened message length, and interleaving depth. Encode the random samples using the ccsdsRSEncode function, and then insert numErrors number of errors at random locations in the encoded samples.

% Generate random message samples
msg = randi([0 255],s*i,1);

% Encode message samples
encoderOut = ccsdsRSEncode(msg,k,i,s);

% Insert errors in encoded output
errorLoc = randi([1 (255-k+s)*i],numErrors,1);
errorVal = randi([1 255],numErrors,1);
chOut = encoderOut;
chOut(errorLoc) = errorVal;

Decode Encoded Data Using MATLAB® Function

Decode the encoded data containing errors using the ccsdsRSDecode function.

[refOutput,refNErr] = ccsdsRSDecode(chOut,k,i,s);
refOutput = repmat(refOutput,numFrames,1);
refNErr = repmat(refNErr,numFrames,1);

Decode Encoded Data Using Simulink® Block

Decode the encoded data containing errors using the CCSDS RS Decoder block. Running the model imports the input signal variables from the MATLAB workspace to the CCSDS RS Decoder block in the model.

% Set frame gap between input frames
if(k == 223 && (i == 1 || i == 2))
    frameGap = 602-(255*i);
else
    frameGap = 0;
end

% Assign inputs to model
dataIn = repmat([chOut; zeros((k-s)*i,1); zeros(frameGap,1)],numFrames,1);
startIn = repmat([true; false(255*i -1,1); false(frameGap,1)],numFrames,1);
endIn = repmat([false((255-k+s)*i -1,1); true; false((k-s)*i,1); ...
    false(frameGap,1)],numFrames,1);
validIn = repmat([true((255-k+s)*i,1); false((k-s)*i,1); ...
    false(frameGap,1)],numFrames,1);

numOutputSamples = k*i;
stopTime = (3065 + numOutputSamples)*numFrames; % Maximum latency of the
                                                % block is 3065 clock cycles

% Run the Simulink model
model_name = 'HDLCCSDSRSDecoder';
open_system(model_name);
set_param([model_name '/HDL CCSDS RS Decoder/CCSDS RS Decoder'], ...
    'MessageLength',num2str(k),'InterleavingDepth',num2str(i));
sim(model_name);

Compare Simulink Block Output with MATLAB Function Output

Compare the CCSDS RS Decoder block output with the ccsdsRSDecode function output.

dataOut = squeeze(decOut);
validOut = squeeze(validOut);
endOut = squeeze(endOut);
numCorrErrOut = squeeze(numCorrErr);
simOutput = dataOut(validOut);
fprintf('\nHDL CCSDS RS Decoder\n');
difference = double(simOutput) - double(refOutput);
fprintf(['\nTotal number of samples that differ between Simulink block output ' ...
    'and MATLAB function output is: %d \n'],sum(difference));
HDL CCSDS RS Decoder

Total number of samples that differ between Simulink block output and MATLAB function output is: 0 

See Also

Blocks

Functions