%% Perform NB-IoT Uplink Multitone SC-FDMA Demodulation
% Perform NB-IoT uplink multitone SC-FDMA demodulation with 15-kHz subcarrier spacing for a chosen cyclic prefix fraction.
% Specify the number of slots for waveform generation.

NSlots = 10;

% Initialize the required cell-wide settings by specifying the NB-IoT subcarrier spacing as a field in the structure ue.

ue.NBULSubcarrierSpacing = '15kHz';

% Specify the zero-based NB-IoT subcarrier indices field as a vector, indicating multitone SC-FDMA demodulation, and the modulation type.

chs.NBULSubcarrierSet = 0:2;    % Indicate multitone demodulation
chs.Modulation = 'QPSK';         % Specify modulation type as QPSK

% Specify a random array of bits and map the values to QPSK-modulated symbols by using the lteSymbolModulate function. Perform uplink precoding on the modulated symbols by using the lteULPrecode function.

bits = randi([0,1],7*NSlots*2*length(chs.NBULSubcarrierSet),1);
symbols =  lteSymbolModulate(bits,chs.Modulation);
precodedSymbols = lteULPrecode(symbols,length(chs.NBULSubcarrierSet),'Subcarrier');

% Initialize the RE grid using the precoded symbols.

reGrid = zeros(12, 7*NSlots);
NSC = length(chs.NBULSubcarrierSet);
reGrid(chs.NBULSubcarrierSet+1,:) = reshape(precodedSymbols,NSC,[]);

% Generate the time-domain waveform for demodulation by using the lteSCFDMAModulate function.

[waveform,info] = lteSCFDMAModulate(ue,chs,reGrid);

% Specify the cyclic prefix fraction and get the resource array by performing SC-FDMA demodulation on the waveform.

cpfraction = 0.3;
grid = lteSCFDMADemodulate(ue,chs,waveform,cpfraction);

% Copyright 2018 The MathWorks, Inc.