Encode Data with LDPC Code in CCSDS Telemetry Standard
This example shows how to use the CCSDS LDPC Encoder block to encode data bits with (8160,7136) low-density parity-check (LDPC) code specified in the Consultative Committee for Space Data Systems (CCSDS) Telemetry standard. The Simulink® model in this example supports HDL code generation for the HDL CCSDS LDPC Encoder subsystem.
Set Up Input Variables
Set up workspace variables for the Simulink model and the MATLAB® function. You can modify these variable values according to your requirement.
numFrames = 5; vectorSize = 8;
Generate Input Data
Generate the input data for the Simulink® model and the MATLAB function that you use in this example. Generate random input bits and then LDPC-encode using a function.
msg = {numFrames};
encData = {numFrames};
blockLen = 7136;
parityLen = 1022; % 8160 - 7136
encSampleIn = [];
encValidIn = []; encStartIn = []; encEndIn =[];
for ii = 1:numFrames
% Generate input bits
msg{ii} = (randi([0 1],blockLen,1)); % Data before encoding
% Peform LDPC encoding
G = coder.load('+satcom/+internal/+ccsds/tmLDPCGeneratorMatrices.mat','LDPCG7136Rate7By8');
g = G.LDPCG7136Rate7By8;
encData{ii} = satcom.internal.ccsds.tmldpcEncode(msg{ii},g); % Encoded data
encFrameGap = round(parityLen/vectorSize) + 100; % Maximum frame gap
inBits = reshape(msg{ii},vectorSize,[]);
ldpcLen = size(inBits,2);
encSampleIn = [encSampleIn inBits zeros(vectorSize,encFrameGap)]>0; %#ok<*AGROW>
encStartIn = logical([encStartIn 1 zeros(1,ldpcLen-1) zeros(1,encFrameGap)]);
encEndIn = logical([encEndIn zeros(1,ldpcLen-1) 1 zeros(1,encFrameGap)]);
encValidIn = logical([encValidIn ones(1,ldpcLen) zeros(1,encFrameGap)]);
end
dataIn = encSampleIn.';
validIn = encValidIn;
startIn = encStartIn;
endIn = encEndIn;
simTime = length(encValidIn) + encFrameGap;
modelName = 'ccsdsHDLLDPCEncoder.slx';
Run Simulink Model
Encode data using the CCSDS LDPC Encoder block. Running the model imports the input signal variables from the MATLAB workspace to the LDPC Encoder block in the model.
open_system(modelName); out = sim(modelName);

Compare Model Output with Function Input
Compare the output of the Simulink model with the MATLAB function output.
startIdx = find(squeeze(out.startOut)); endIdx = find(squeeze(out.endOut)); validOut = (squeeze(out.validOut)); actEncData = squeeze(out.encOut); for ii = 1:numFrames idx = startIdx(ii):endIdx(ii); if vectorSize == 8 encHDL = actEncData(:,idx); else encHDL = actEncData(idx); end HDLOutput = logical(encHDL(:)); error = sum(abs(logical(encData{ii})-HDLOutput(:))); fprintf('Frame: %d, The Simulink model output and the MATLAB function input differ by %d bits\n', ii, error); end
Frame: 1, The Simulink model output and the MATLAB function input differ by 0 bits Frame: 2, The Simulink model output and the MATLAB function input differ by 0 bits Frame: 3, The Simulink model output and the MATLAB function input differ by 0 bits Frame: 4, The Simulink model output and the MATLAB function input differ by 0 bits Frame: 5, The Simulink model output and the MATLAB function input differ by 0 bits