Main Content

DVB-S2 Symbol Demodulation of Complex Data Symbols

This example shows how to use the DVB-S2 Symbol Demodulator block to demodulate complex data symbols to log-likelihood ratio (LLR) values or data bits. Generate a set of complex random inputs and provide them as an input to the block and the MATLAB® function refDVBS2SymDemod. Compare the output of the block with the output of the refDVBS2SymDemod function. This reference function uses the comm.PSKDemodulator object and the dvbsapskdemod function from Communications Toolbox™. To work with scalar and vector output types separately, this example uses two Simulink models. You can generate HDL code from the subsystems in these Simulink models.

Set Up Input Variables

Set up the input variables. You can change the variable values in this section based on your requirements. The example runs the HDLDVBS2SymbolDemodulatorScalar.slx model when you set outputType to 'Scalar' and runs the HDLDVBS2SymbolDemodulatorVector.slx model when you set outputType to 'Vector'.

rng(0);
framesize = 8;                 % framesize must be a multiple of 8 when you
                               % set the 'Output type' variable to 'Vector'
                               % framesize can be any integer greater than
                               % 0 when you set the 'Output type' variable
                               % to 'Scalar'
modIdx = [1;3;0;2;4];          % modIdx must contain 0, 1, 2, 3, and 4,
                               % which correspond to the modulation schemes
                               % QPSK, 8-PSK, 16-APSK, 32-APSK, and
                               % pi/2-BPSK, respectively.
codeRateIdx = [5;10;6;7;9;8];  % codeRateIdx values can be 5, 6, 7, 8, 9, or 10, which
                               % correspond to the code rates 2/3, 3/4,
                               % 4/5, 5/6, 8/9, and 9/10, respectively.
UnitAvgCheckBox = 'on';        % on to enable and off to disable unit average power option
outputType = 'Scalar';         % outputType can be 'Scalar' or 'Vector'
decisionType = 'Approximate log-likelihood ratio';  % decisionType can be 'Approximate log-likelihood ratio' or 'Hard'

% Initialize variables
numframes = length(modIdx);
dataSymbols  = cell(1,numframes);
modSelTmp = cell(1,numframes);
modOrder = cell(1,numframes);
codeRateStr = cell(1,numframes);
referenceOutput = cell(1,numframes);
codeRateIndTmp = cell(1,numframes);

Generate Frames of Random Samples

Generate frames of complex random samples using the MATLAB function randn.

for ii = 1:numframes
    dataSymbols{ii} = complex(randn(framesize,1),randn(framesize,1));
    modSelTmp{ii} = fi(modIdx(ii)*ones(framesize,1),0,3,0);
    codeRateIndTmp{ii} = fi(codeRateIdx(ii)*ones(framesize,1),0,4,0);
end

if strcmp(UnitAvgCheckBox,'on')
 UnitAvgPower = true;
else
 UnitAvgPower = false;
end

Convert Frames to Stream of Random Samples

Convert frames of complex random samples to a stream of complex random samples to provide them as an input to the block.

idlecyclesbetweensamples = 0;
idlecyclesbetweenframes = 0;
[dataIn, ctrl] = whdlFramesToSamples(dataSymbols,idlecyclesbetweensamples, ...
    idlecyclesbetweenframes);
[modInd, ~] = whdlFramesToSamples(modSelTmp,idlecyclesbetweensamples, ...
    idlecyclesbetweenframes);
[codeRateInd, ~] = whdlFramesToSamples(codeRateIndTmp,idlecyclesbetweensamples, ...
    idlecyclesbetweenframes);
startIn = logical(ctrl(:,1)');
endIn = logical(ctrl(:,2)');
validIn = logical(ctrl(:,3)');

sampletime = 1;
samplesizeIn = 1;
simTime = size(ctrl,1)*8;

Run Simulink® Model

The HDL DVBS2 Symbol Demodulator subsystem contains the DVB-S2 Symbol Demodulator block. Running the model imports the input signal variables and control signals into the block from the script and exports a stream of demodulated output samples and control signals from the block to the MATLAB workspace.

if strcmp(outputType,'Vector')
    modelname = 'HDLDVBS2SymbolDemodulatorVector';
    open_system(modelname);
    set_param([modelname '/DVBS2SymbolDemod/DVBS2 Symbol Demodulator'],'UnitAveragePower',UnitAvgCheckBox)
    set_param([modelname '/DVBS2SymbolDemod/DVBS2 Symbol Demodulator'],'DecisionType',decisionType)
    symDemodOut = sim(modelname);

    startIdx = find(symDemodOut.startOut.Data);
    endIdx = find(symDemodOut.endOut.Data);
    actualData = cell(1,numframes);

    for ii = 1:numframes
        idx = startIdx(ii):endIdx(ii);
        tmpDataOut = symDemodOut.dataOut.Data(:,idx);
        dataOutSqueezed = squeeze(tmpDataOut);
        tmpValidOut = symDemodOut.validOut.Data(:,idx);
        demodOut = tmpDataOut(:,tmpValidOut);
        actualData{ii} = double(demodOut(:));
    end

else
    modelname = 'HDLDVBS2SymbolDemodulatorScalar';
    open_system(modelname);
    set_param([modelname '/DVBS2SymbolDemod/DVB-S2 Symbol Demodulator'],'UnitAveragePower',UnitAvgCheckBox)
    set_param([modelname '/DVBS2SymbolDemod/DVB-S2 Symbol Demodulator'],'DecisionType',decisionType)
    symDemodOut = sim(modelname);
    demodOut = symDemodOut.dataOut.Data(symDemodOut.validOut.Data);
end

Demodulate Stream Samples Using MATLAB Function

To demodulate the stream of random samples, provide them as an input to the refDVBS2SymDemod function. You can use the output of this function as a reference to compare the output of the block.

for ii = 1:numframes
 inpParamFr.decisionType = decisionType;
 inpParamFr.UnitAvgCheckBox = UnitAvgCheckBox;
 inpParamFr.modIdx = modIdx(ii);
 inpParamFr.codeRateIdx = codeRateIdx(ii);
 referenceOutput{ii} = refDVBS2SymDemod(dataSymbols{ii},inpParamFr);
end

Compare Simulink Block Output with MATLAB Function Output

Compare the output of the DVB-S2 Symbol Demodulator block with the output of the refDVBS2SymDemod function.

referenceOutput = double(cell2mat(referenceOutput.'));
if strcmp(outputType,'Vector')
    actualData = double(cell2mat(actualData.'));
else
    actualData = double(squeeze(demodOut(:)));
end

figure(1)
stem(actualData,'-bo')
hold on
stem(referenceOutput,'-r*')
grid on
legend('Reference Output','Block Output')
xlabel('Sample Index')
ylabel('Magnitude')
title('Comparison of Simulink Block and MATLAB Function')
fprintf('\nPlotting the comparison results of Simulink block and MATLAB function outputs\n');
Plotting the comparison results of Simulink block and MATLAB function outputs

See Also

| |