%% Synchronize and Demodulate Transmission Containing PSBCH DM-RS
% Synchronize and demodulate a transmission that has been delayed by five samples. The transmission contains PSBCH demodulation reference signal (DM-RS) symbols that are used when estimating the waveform timing offset.
% Create a UE configuration specifying 15 resource blocks, a sidelink identity of 1, and a normal cyclic prefix.

ue = struct('NSLRB',15,'NSLID',1,'CyclicPrefixSL','Normal');

%
% Create a resource grid and modulate the waveform containing PSBCH DM-RS symbols.

txgrid = lteSLResourceGrid(ue);
txgrid(ltePSBCHDRSIndices(ue)) = ltePSBCHDRS(ue);
txwaveform = lteSLSCFDMAModulate(ue,txgrid);

%
% Add a time delay of five samples.

rxwaveform = [zeros(5,1); txwaveform];

%
% Calculate the timing offset in samples.

offset = lteSLFrameOffsetPSBCH(ue,rxwaveform)

%
% Correct the timing offset and demodulate the received waveform.

rxGrid = lteSLSCFDMADemodulate(ue,rxwaveform(1+offset:end));

% Copyright 2012 The MathWorks, Inc.