%% View Correlation Peak in PSCCH DM-RS Transmission
% View the correlation peak for a transmission waveform that has been delayed by five samples. The transmission contains PSCCH demodulation reference signal (DM-RS) symbols available for estimating the waveform timing.
% Create a UE configuration specifying 15 resource blocks, a normal cyclic prefix, and a PRBSet of 1.

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

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

txgrid = lteSLResourceGrid(ue);
txgrid(ltePSCCHDRSIndices(ue)) = ltePSCCHDRS;
txwaveform = lteSLSCFDMAModulate(ue,txgrid);

%
% Calculate the timing offset in samples.

[offset corr] = lteSLFrameOffsetPSCCH(ue,txwaveform);

%
% Add a time delay of five samples.

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

%
% Calculate the timing offset in samples.

[offset corrDelayed] = lteSLFrameOffsetPSCCH(ue,rxwaveform);

%
% Plot the correlation data before and after delay is added. Zoom in on the x-axis to view correlation peaks.

plot(corr)
hold on
plot(corrDelayed)
hold off
xlim([0 100])

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

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

% Copyright 2012 The MathWorks, Inc.