Main Content

Decode Convolutionally-Coded LLR Values Using APP Decoder

This example shows how to decode convolutionally-coded log-likelihood ratio (LLR) values using the APP Decoder block. To verify the results, compare the output of the block with the output of the Communication Toolbox™ System object™ comm.APPDecoder that is provided with same inputs as the block. This example supports HDL code generation for the HDL APP Decoder subsystem.

Set Up Input Variables

Specify the input variables. You can change the variable values in this section based on your requirements. In this example, you must specify the same value for the frame length (frameLength) and the window length (winLen). The block supports a maximum window length of 128.

numFrames = 3;
frameLength = 64;
codeGenerator = '[171 133]';                       % Code generator, specified as a row vector of octal values
feedback = '171';
codeRate = length(str2num(codeGenerator));         % Decoding rate
winLen = 64;                                       % Window length must be less than or equal to 128
CodeGenDecimal = oct2dec(str2num(codeGenerator));
K = length(dec2bin(CodeGenDecimal(2)));            % Constraint length derived from code generator value
TermMode = 'Truncated';                            % Terminated or Truncated
Algorithm = 'Max Log MAP (max)';                   % Max Log MAP (max) or Log MAP (max*)

Generate Frames of Input Data

Generate frames of LLR-coded and LLR-uncoded input data with the specified variables. To generate input data, create random binary bits, convolutionally-encode and symbol-demodulate the random binary bits, add noise to the symbol-demodulated data, and demodulate the noise-added symbol-demodulated data.

TrellisStructure = poly2trellis(K,str2num(codeGenerator),str2num(feedback));

if frameLength == winLen
    FrameGap = 0;
else
    FrameGap = winLen - rem(frameLength,winLen);
end

if strcmpi(TermMode,'Terminated')
    tailLen = K - 1;
else  % 'Truncated'
    tailLen = 0;
end

LLRCodedIn = [];
LLRUncodedIn = [];
startIn = [];
endIn = [];
validIn = [];

for fr=1:numFrames
    % Create binary random inputs to convolution encoder
    inpToConvEnc(:,fr) = [randn(frameLength-tailLen,1)>0; zeros(tailLen,1)];

    % Convolutionaly-encode binary random inputs
    encodedData = convenc(inpToConvEnc(:,fr), TrellisStructure);

    % Modulate convolutionally-encoded data
    modData = qammod(double(encodedData), 4, 'InputType', 'bit', 'UnitAveragePower', true);

    % Add AWGN noise to modulated data
    snrdB = 8;
    noiseVar = 10^-(snrdB/10);
    rxSig = awgn(modData,snrdB,'measured');

    % Demodulate noise-added modulated data
    demod(:,fr) = -qamdemod(rxSig, 4, 'OutputType', 'approxllr', 'UnitAveragePower', true);

    % Prepare LLR-coded (LLRc) and LLR-uncoded (LLRu) input values to model
    LLRc = reshape(demod(:,fr),codeRate,[]).';
    LLRu(:,fr) = LLRc(:,1);

    LLRCodedIn = [LLRCodedIn; LLRc];
    LLRUncodedIn = [LLRUncodedIn; LLRu(:,fr)];

    startSig = [true; false(frameLength-1,1); false(FrameGap,1)];
    endSig = [false(frameLength-1,1); true; false(FrameGap,1)];
    validSig = [true(frameLength,1); false(FrameGap,1)];

    startIn = [startIn; startSig];
    endIn = [endIn; endSig];
    validIn = [validIn; validSig];
end
stopTime = (numFrames+4)*frameLength;

Run Simulink Model

Run the model to import the input signal variables from the MATLAB® workspace to the APP Decoder block in the model.

modelName = 'HDLAPPDecoder';
open_system(modelName);
set_param([modelName '/HDL APP Decoder/APP Decoder'],'Algorithm',Algorithm);
set_param([modelName '/HDL APP Decoder/APP Decoder'],'CodeGenerator',codeGenerator);
set_param([modelName '/HDL APP Decoder/APP Decoder'],'FeedbackConnection',feedback);
set_param([modelName '/HDL APP Decoder/APP Decoder'],'TermMode',TermMode);
sim(modelName);

Decode Generated Data Using System Object

Create comm.APPDecoder System object and provide the same inputs as the block inputs.

hAPPDec = comm.APPDecoder;
if strcmpi(Algorithm,'Max Log MAP (max)')
    hAPPDec.Algorithm = 'Max';
else
    hAPPDec.Algorithm = 'Max*';
end
hAPPDec.TrellisStructure = TrellisStructure;
hAPPDec.TerminationMethod = TermMode;

% Generate reference output
LLRu_ref = [];
LLRc_ref = [];
for fr=1:numFrames
    [LLRu_MATLAB,LLRc_MATLAB] = hAPPDec(LLRu(:,fr),demod(:,fr));
    LLRu_ref = [LLRu_ref; LLRu_MATLAB];
    LLRc_ref = [LLRc_ref; LLRc_MATLAB];
end

Compare Simulink Block Output with System Object Output

Compare the APP Decoder block output with the comm.APPDecoder System object output.

LLRu_out_sim = LLRUncodedOut(validOut);
LLRc_out_sim = reshape(LLRCodedOut(:,validOut),[],1);

figure(1);
plot(LLRu_ref,'-bd');
hold on;
plot(LLRu_out_sim,'--r*')
grid on;
legend('Reference output','Block output');
xlabel('Sample Index');
ylabel('Uncoded LLR Output');
title('Comparison of Block Output with System Object Output');
figure(2);
plot(LLRc_ref,'-bd');
hold on;
plot(LLRc_out_sim,'--r*')
grid on;
legend('Reference output','Block output');
xlabel('Sample Index');
ylabel('Coded LLR Output');
title('Comparison of Block Output with System Object Output');

See Also

|