%% Estimate Timing Offset for TDL-C Channel Transmission
% Generate primary synchronization signal (PSS) symbols for physical layer cell identity number 42.

ncellid = 42;
pssSym = nrPSS(ncellid);

% Obtain resource element indices for the PSS.

pssInd = nrPSSIndices();

% Create a resource grid containing the generated PSS symbols.

txGrid = zeros([240 4]);
txGrid(pssInd) = pssSym;

% OFDM modulate the resource grid.

txWaveform = ofdmmod(txGrid,512,[40 36 36 36],[1:136 377:512].');

% Transmit the waveform through a TDL-C channel model by using a sample rate of 7.68 MHz.

SR = 7.68e6;
channel = nrTDLChannel;
channel.SampleRate = SR;
channel.DelayProfile = 'TDL-C';
rxWaveform = channel(txWaveform);

% Estimate timing offset for the transmission by using the PSS symbols as reference symbols. The OFDM modulation of the reference symbols spans 20 resource blocks at 15-kHz subcarrier spacing and uses initial slot number 0.

nrb = 20;
scs = 15;
initialSlot = 0;
offset = nrTimingEstimate(rxWaveform,nrb,scs,initialSlot,pssInd,pssSym);

% Copyright 2019 The MathWorks, Inc.