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

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

pucch2.ResourceIdx = 0;
pucch2.ResourceSize = 0;
pucch2.CyclicShifts = 0;

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

reGrid = lteULResourceGrid(ue);
txAck = [1;1];
reGrid(ltePUCCH2DRSIndices(ue,pucch2)) = ltePUCCH2DRS(ue,pucch2,txAck);

tx = lteSCFDMAModulate(ue,reGrid);

%% Waveform Reception
% On the receive side, calculate timing offset using the PUCCH2 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.

[~,ack,corr] = lteULFrameOffsetPUCCH2(ue,pucch2,tx,length(txAck));

txDelayed = [zeros(5,1); tx];
[offset,ack,corrDelayed] = lteULFrameOffsetPUCCH2(ue,pucch2,txDelayed,length(txAck));

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