LTE Symbol Modulation of Data Bits
This example shows how to use the LTE Symbol Modulator block to modulate data bits to complex data symbols. You can generate HDL code from this block.
Set up Input Parameters
Choose a data length for each modulation type. The data length must be an integer multiple of number of bits per symbol.
rng(0); framesize = 240; % Map modulation names to values % 0 - BPSK % 1 - QPSK % 2 - 16-QAM % 3 - 64-QAM % 4 - 256-QAM % others - QPSK % For LTE Symbol Modulator Simulink(R) block modSelVal = [0;1;2;3;4]; % For |lteSymbolModulate| function modSelStr = {'BPSK','QPSK','16QAM','64QAM','256QAM'}; outWordLength = 16; numframes = length(modSelVal); dataBits = cell(1,numframes); modSelTmp = cell(1,numframes); lteFcnOutput = cell(1,numframes);
Generate Input Data
Generate frames of random input samples. Convert the framed input data to a stream of samples and provide these samples as input to the Simulink block.
for ii = 1:numframes dataBits{ii} = logical(randi([0 1],framesize,1)); modSelTmp{ii} = fi(modSelVal(ii)*ones(framesize,1),0,3,0); end
idlecyclesbetweensamples = 0; idlecyclesbetweenframes = 0; [sampleIn, ctrl] = whdlFramesToSamples(dataBits,idlecyclesbetweensamples,... idlecyclesbetweenframes); [modSel, ~] = whdlFramesToSamples(modSelTmp,idlecyclesbetweensamples,... idlecyclesbetweenframes); load = logical(ctrl(:,1)'); validIn = logical(ctrl(:,3)'); sampletime = 1; samplesizeIn = 1; simTime = size(ctrl,1);
Run Model
Running the Simulink model exports the stream of modulated samples from Simulink to the MATLAB® workspace.
modelname = 'ltehdlSymbolModulatorModel';
open_system(modelname);
sim(modelname);
sampleOut = squeeze(sampleOut).';
lteHDLOutput = sampleOut(squeeze(validOut));
Generate Reference Data
Modulate data bits with the <docid:lte_ref#bt16g53 lteSymbolModulate
function and use the output of this function as a reference data.
for ii = 1:numframes lteFcnOutput{ii} = lteSymbolModulate(dataBits{ii},modSelStr{ii}).'; end
Compare Model Output with Function Output
Compare the output of the Simulink model against the output of the lteSymbolModulate
function.
fprintf('\nLTE Symbol Modulator\n'); lteFcnOutput = fi(cell2mat(lteFcnOutput),1,outWordLength,outWordLength-2); difference = sum(abs(lteHDLOutput-lteFcnOutput(1:length(lteHDLOutput)))); fprintf('\nTotal number of samples differed between Simulink block output and Reference data output: %d \n',difference);
LTE Symbol Modulator Total number of samples differed between Simulink block output and Reference data output: 0