Main Content

Encode Message into RS Codeword Using CCSDS Standard

This example shows how to use the CCSDS RS Encoder block to encode a message into a Reed-Solomon (RS) codeword according to the Consultative Committee for Space Data Systems (CCSDS) standard. Generate a set of random input message symbols and provide them as input to the ccsdsRSEncode (Satellite Communications Toolbox) function and the CCSDS RS Encoder block. Compare the output of the CCSDS RS Encoder block with the output of the ccsdsRSEncode function. The Simulink® model in this example supports HDL code generation for the HDL CCSDS RS Encoder 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
frameGap = (255-k)*i; % Minimum gap required between input frames
                      % If a new input frame is given without this frame
                      % gap, the block discards the previous frame and
                      % processes the new frame.

Generate Random Input Samples and Encode Using MATLAB® Function

Generate random samples using the specified message length and interleaving depth. Encode the random samples using the ccsdsRSEncode function.

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

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

Encode Input Samples Using Simulink Block

Encode the random samples using the CCSDS RS Encoder block. Running the model imports the input signal variables from the MATLAB workspace to the CCSDS RS Encoder block in the model.

% Assign inputs to model
data = repmat(msg,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);
valid = repmat([true(s*i,1); false((k-s)*i,1); false(frameGap,1)],numFrames,1);

% Run Simulink model
model = 'HDLCCSDSRSEncoder';
set_param([model '/HDL CCSDS RS Encoder/CCSDS RS Encoder'],'MessageLength',num2str(k),'InterleavingDepth',num2str(i));
latency = 3; % fixed block latency
stopTime = latency + ((s*i) + frameGap)*numFrames;

Compare Simulink Block Output with MATLAB Function Output

Compare the CCSDS RS Encoder block output with the ccsdsRSEncode function output.

simOutput = dataOut;
refOutput = repmat(encOut,numFrames,1);
fprintf('\nHDL CCSDS RS Encoder\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));

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

See Also