%% View PUCCH Format 1 DM-RS Transmission Correlation Peaks
% View the correlation peak for a transmission waveform that has been delayed. The transmission contains PUCCH format 1 demodulation reference signal (DM-RS) symbols available for estimating the waveform timing.
%% UE Configuration
% Create configuration structures for ue and pucch1.

ue = struct('NULRB',6,'NCellID',0,'NSubframe',0,'Hopping','Off');
ue.CyclicPrefixUL = 'Normal';
ue.NTxAnts = 1;

pucch1 = struct('ResourceIdx',0);
pucch1.CyclicShifts = 0;
pucch1.DeltaShift = 1;
pucch1.ResourceSize = 0;

%
%% Generate Transmission Waveform
% On the transmit side, populate a resource grid and generate a waveform containing PUCCH1 DM-RS.

reGrid = lteULResourceGrid(ue);
reGrid(ltePUCCH1DRSIndices(ue,pucch1)) = ltePUCCH1DRS(ue,pucch1);

tx = lteSCFDMAModulate(ue,reGrid);

%% Waveform Reception
% On the receive side, calculate timing offset using the PUCCH format 1 DM-RS symbols for the time-domain waveform and return the correlations for the transmit waveform and for a delayed version of the transmit waveform.

[~,corr] = lteULFrameOffsetPUCCH1(ue,pucch1,tx);

txDelayed = [zeros(7,1); tx];
[offset,corrDelayed] = lteULFrameOffsetPUCCH1(ue,pucch1,txDelayed);

% 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.

rrxGrid = lteSCFDMADemodulate(ue,txDelayed(1+offset:end));

% Copyright 2012 The MathWorks, Inc.