NR Symbol Demodulation of Complex Data Symbols
This example shows how to use the NR Symbol Demodulator block to demodulate complex NR data symbols to data bits or LLR values.
Set Input Data Parameters
Map modulation names to values. Set the NR Symbol Demodulator block with numerical values and configure the nrSymbolDemodulate
(5G Toolbox) function with strings.
rng(0); framesize = 10; % 0 - BPSK % 1 - QPSK % 2 - 16-QAM % 3 - 64-QAM % 4 - 256-QAM % 5 - pi/2-BPSK % others - QPSK modSelVal = [0;1;2;3;4;5]; modSelStr = {'BPSK','QPSK','16QAM','64QAM','256QAM','pi/2-BPSK'}; decType = 'Soft'; numframes = length(modSelVal); dataSymbols = cell(1,numframes); modSelTmp = cell(1,numframes); nrFcnOutput = cell(1,numframes);
Generate Input Data
Generate frames of random input samples. Convert the framed input data to a stream of samples and input the stream to the NR Symbol Demodulator Simulink® block.
for ii = 1:numframes dataSymbols{ii} = complex(randn(framesize,1),randn(framesize,1)); modSelTmp{ii} = fi(modSelVal(ii)*ones(framesize,1),0,3,0); end idlecyclesbetweensamples = 0; idlecyclesbetweenframes = 0; [sampleIn, ctrl] = whdlFramesToSamples(dataSymbols,idlecyclesbetweensamples,... idlecyclesbetweenframes); [modSel, ~] = whdlFramesToSamples(modSelTmp,idlecyclesbetweensamples,... idlecyclesbetweenframes); validIn = logical(ctrl(:,3)'); sampletime = 1; samplesizeIn = 1; simTime = size(ctrl,1)*8;
Run Model
Running the Simulink model exports the stream of demodulated samples from Simulink to the MATLAB® workspace.
modelname = 'nrhdlSymbolDemodulatorModel'; open_system(modelname); set_param([modelname '/NRDemod/NR Symbol Demodulator'],'DecisionType',decType) sim(modelname); nrHDLOutput = sampleOut(validOut).';
Generate Reference Data
Demodulate data symbols with nrSymbolDemodulate
function and use its output as a reference data.
for ii = 1:numframes nrFcnOutput{ii} = nrSymbolDemodulate(dataSymbols{ii},modSelStr{ii},'DecisionType',decType,1).'; end
Compare Model Output with Function Output
Compare the output of the Simulink model against the output of nrSymbolDemodulate
function.
nrFcnOutput = double(cell2mat(nrFcnOutput)); figure(1) stem(nrHDLOutput,'b') hold on stem(nrFcnOutput,'--r') grid on legend('Reference','Simulink') xlabel('Sample Index') ylabel('Magnitude') title('Comparison of Simulink block and MATLAB function')