Main Content

DVB-S2 Symbol Modulation of Data Bits

This example shows how to modulate data bits to complex data symbols using the DVB-S2 Symbol Modulator block. Generate a set of random inputs and provide them as an input to the block and the MATLAB® function refDVBS2SymMod. Compare the output of the block with the output of the refDVBS2SymMod function. This reference function uses a comm.PSKModulator object and the dvbsapskmod function from Communications Toolbox™.

Set Up Input Variables

Set up input variables. You can change the variable values in this section based on your requirements. The modIdx values 0, 1, 2, 3, and 4 correspond to the modulation schemes QPSK, 8-PSK, 16-APSK, 32-APSK and pi/2-BPSK, respectively. The codeRateIdx values 5, 6, 7, 8, 9, and 10 correspond to the code rates 2/3, 3/4, 4/5, 5/6, 8/9, and 9/10, respectively.

rng(0);
numBits = 60;
modIdx = [1; 3; 0; 2; 4];
codeRateIdx = [5; 10; 6; 7; 9; 8];
unitAvgPower = 'on';               % 'on' to enable and 'off' to disable
outputDataType = 'Custom';         % Output data type can be 'double', 'single', or 'Custom'
wordLength = 16;                   % Output word length can be in the range [3, 32]

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

Generate Frames of Random Samples

Generate bits using the randi function.

for ii = 1:numframes
    dataSymbols{ii} = randi([0 1],numBits,1);
    modSelTmp{ii} = fi(modIdx(ii)*ones(numBits,1),0,3,0);
    codeRateIndTmp{ii} = fi(codeRateIdx(ii)*ones(numBits,1),0,4,0);
    loadTmp{ii} = boolean([1;zeros(numBits-1,1)]);
end

Convert Frames to Stream of Random Samples

Convert frames of complex random samples to a stream of complex random samples that the block can accept as input.

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

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

Run Simulink Model

The HDL DVB-S2 Symbol Modulator subsystem contains the DVB-S2 Symbol Modulator block. Running the model imports the input signal variables dataIn, validIn, modIdx, codeRateIdx, and loadIn to the block from the script. The model exports a stream of modulated output samples dataOut and validOut signals from the block to the MATLAB workspace.

modelname = 'HDLDVBS2SymbolModulator';
open_system(modelname);
set_param([modelname '/DVBS2SymbolMod/DVB-S2 Symbol Modulator'],'UnitAveragePower',unitAvgPower)
set_param([modelname '/DVBS2SymbolMod/DVB-S2 Symbol Modulator'],'OutputDataType',outputDataType)
symModOut = sim(modelname);
modOut =  symModOut.dataOut.Data(symModOut.validOut.Data);

Modulate Stream Samples Using MATLAB Function

To symbol modulate the stream of random bits, provide them as input to the refDVBS2SymMod function. You can use the output of this function as a reference against which to compare the output of the block.

for ii = 1:numframes
 inpParamFr.UnitAvgPowerRef = unitAvgPower;
 inpParamFr.modIdx = modIdx(ii);
 inpParamFr.codeRateIdx = codeRateIdx(ii);
 referenceOutput{ii} = refDVBS2SymMod(dataSymbols{ii},inpParamFr);
end

Compare Simulink Block Output with MATLAB Function Output

Compare the output of the DVB-S2 Symbol Modulator block with the output of the refDVBS2SymMod function.

referenceOutput = double(cell2mat(referenceOutput.'));
actualData = double(squeeze(modOut(:)));

figure('units','normalized','outerposition',[0 0 1 1])
subplot(2,1,1)
plot(real(referenceOutput(:)));
hold on;
plot(real(actualData(:)));
grid on
legend('MATLAB Reference Output','Simulink Block Output')
xlabel('Sample Index')
ylabel('Magnitude')
title('Comparison of Simulink Block and MATLAB Function (Real Part)')

subplot(2,1,2)
plot(imag(referenceOutput(:)));
hold on;
plot(imag(actualData(:)));
grid on
legend('MATLAB Reference Output','Simulink Block Output')
xlabel('Sample Index')
ylabel('Magnitude')
title('Comparison of Simulink Block and MATLAB Function (Imaginary Part)')

sqnrRealdB = 10*log10(double(var(real(actualData(:)))/abs(var(real(actualData(:)))-var(real(referenceOutput(:))))));
sqnrImagdB = 10*log10(double(var(imag(actualData(:)))/abs(var(imag(actualData(:)))-var(imag(referenceOutput(:))))));

fprintf('\n DVB-S2 Symbol Modulator \n SQNR of real part: %.2f dB',sqnrRealdB);
fprintf('\n SQNR of imaginary part: %.2f dB\n',sqnrImagdB);
 DVB-S2 Symbol Modulator 
 SQNR of real part: 44.25 dB
 SQNR of imaginary part: 44.20 dB

See Also

Blocks

Functions

Objects