Contenuto principale

Encode Data with LDPC Code in CCSDS Telemetry Standard

Since R2025a

This example shows how to use the CCSDS LDPC Encoder block to encode data bits with low-density parity-check (LDPC) code specified in the Consultative Committee for Space Data Systems (CCSDS) Telemetry standard. Use the ccsdsHDLLDPCEncoder model for the (8160,7136) LDPC configuration and the ccsdsHDLLDPCEncoderAR4JA model for the AR4JA LDPC configuration. To verify the behavior of the block, compare the output of the model with the input provided to the encoder function. The CCSDS LDPC Encoder block used in these models supports HDL code generation.

Set Up Input Variables

Set up workspace variables to generate inputs for the Simulink model and the MATLAB® function. These values are tunable and you can modify them according to your requirement.

configType = '(8160,7136) LDPC'; % Select the configuration type as
                                 % '(8160,7136) LDPC' or 'AR4JA LDPC'
numFrames = 2;
if strcmpi(configType,'AR4JA LDPC') %#ok<*IFBDUP>
    vectorSize = 1; %#ok<*UNRCH>
else
    vectorSize = 8; % Vector Size '1' or '8'
end

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.

if strcmpi(configType,'AR4JA LDPC')
    blkLenSet = [1024 4096 16384];
    codeRateSet = {'1/2' '2/3' '4/5'};
    blkLenIdx = [2 1];
    codeRateIdx = [0 1];
end

msg = {numFrames};
encData = {numFrames};

encSampleIn = [];
encValidIn = []; encStartIn = []; encEndIn =[];
blockLenIn = []; codeRateIn = [];

for ii = 1:numFrames

    % Generate input bits
    if strcmpi(configType,'AR4JA LDPC')
        blockLen = blkLenSet(blkLenIdx(ii)+1);
        codeRate = codeRateSet{codeRateIdx(ii)+1};
        R = str2num(codeRate); %#ok<*ST2NM>
    else
        blockLen = 7136;
        R = 7/8;
    end
    msg{ii} = (randi([0 1],blockLen,1)); % Data before encoding

    % Perform LDPC encoding
    G = generatorMatrix(configType,blockLen,R);
    encData{ii} = satcom.internal.ccsds.tmldpcEncode(msg{ii},G); % Encoded data

    encFrameGap = 49168 + (length(encData{ii}) - blockLen) + 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)]);
    if strcmpi(configType,'AR4JA LDPC')
        blockLenIn = fi([blockLenIn repmat(blkLenIdx(ii),1,ldpcLen) zeros(1,encFrameGap)],0,2,0);
        codeRateIn = fi([codeRateIn repmat(codeRateIdx(ii),1,ldpcLen) zeros(1,encFrameGap)],0,2,0);
    end
end

dataIn = encSampleIn.';
validIn = encValidIn;
startIn = encStartIn;
endIn = encEndIn;
if strcmpi(configType,'AR4JA LDPC')
    blkLenIdxIn = blockLenIn;
    codeRateIdxIn = codeRateIn;
end

simTime = length(encValidIn) + encFrameGap;

if strcmpi(configType,'AR4JA LDPC')
    modelName = 'ccsdsHDLLDPCEncoderAR4JA.slx';
else
    modelName = 'ccsdsHDLLDPCEncoder.slx';
end
open_system(modelName);

Run 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.

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

See Also

Blocks