%% Estimate Offset of Narrowband Waveform
% Create a subframe resource grid for the cell-wide settings structure, enb. Map the subframe grid into a frame resource grid.

subframeGrid = zeros(12,14);
frameGrid = zeros(12,14*10);
enb.OperationMode = 'Standalone';
enb.NSubframe = 5;
enb.NFrame = 2;
enb.NNCellID = 1;
subframeGrid(lteNPSSIndices(enb)) = lteNPSS(enb);
frameGrid(:,14*enb.NSubframe + (1:14)) = subframeGrid;

% Generate an OFDM-modulated waveform for the resource grid and user-equipment-specific settings ue, specifying a timing offset of 25 samples.

ue.NBULSubcarrierSpacing = '15kHz'; % NB DL OFDM is the same as NB UL SC-FDMA 
                                    % with 15-kHz subcarrier spacing
waveform = [zeros(25,1); lteSCFDMAModulate(ue,frameGrid)];

% Estimate the timing offset and display the result.

offset = lteNBDLFrameOffset(enb,waveform);
disp(offset)

% Copyright 2019 The MathWorks, Inc.