%% Map PSCCH Resource Elements
% Write the complex PSCCH values into the PSCCH resource elements in a PSCCH subframe for D2D sidelink and with normal cyclic prefix. Do the same for V2X. Display an image of their locations and compare both sidelink modes. This mapping writes PSCCH values into the last SC-FDMA guard symbol within a subframe. The sidelink SC-FDMA modulator removes these values before transmission of the waveform.
% Create a UE settings structure for D2D sidelink and an empty sidelink resource grid. Assign a PRB set index of 5.

ue = struct('NSLRB',15,'CyclicPrefixSL','Normal');
subframe_D2D = lteSLResourceGrid(ue);
ue.PRBSet = 5;

% Generate PSCCH indices. Populate the PSCCH resource elements in the subframe. For D2D normal cyclic prefix, a PSCCH subframe contains 144 REs.

[pscch_indices, pscch_info] = ltePSCCHIndices(ue);
subframe_D2D(pscch_indices) = ltePSCCH(zeros(pscch_info.G,1));

% Change user equipment settings to V2X sidelink mode. Assign a PRB set indices of 5 and 6.

ue.SidelinkMode = 'V2X';
subframe_V2X = lteSLResourceGrid(ue);
ue.PRBSet = [5;6];

% Generate PSCCH indices. Populate the PSCCH resource elements in the subframe using a codeword filled with zeros. For V2X, a PSCCH subframe contains 240 REs.

[pscch_indices, pscch_info] = ltePSCCHIndices(ue);
subframe_V2X(pscch_indices) = ltePSCCH(zeros(pscch_info.G,1));

% View the resource grid and compare the indices for both sidelink modes.

subplot(2,1,1);
image(400*abs(subframe_D2D)); 
axis xy; title('D2D');
subplot(2,1,2);
image(400*abs(subframe_V2X)); 
axis xy; title(ue.SidelinkMode);

% Copyright 2012 The MathWorks, Inc.