%% Map PSSCH Resource Elements
% Write the complex PSSCH values into the PSSCH resource elements in a PSSCH subframe both for D2D normal cyclic prefix and V2X. Display an image of their locations to compare both sidelink modes. This mapping writes PSSCH 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, an empty sidelink resource grid and D2D normal cyclic prefix. Define a PRB allocation, ue.PRBSet, with RB values from 30 to 39.

ue = struct('NSLRB',50,'CyclicPrefixSL','Normal');
ue.NSAID = 1;
ue.NSubframePSSCH = 1;
ue.PRBSet = [30:39]';
ue.Modulation = 'QPSK';
subframe_D2D = lteSLResourceGrid(ue);

% Generate PSSCH indices. Populate the PSSCH resource elements in the subframe using a vector filled with zeros. For D2D normal cyclic prefix a PSSCH subframe contains (144 * nprb ) REs. The number of resource blocks is set to 10. Because the PSSCH uses QPSK modulation, there are 2 bits per symbol.

pssch_indices = ltePSSCHIndices(ue);
subframe_D2D(pssch_indices) = ltePSSCH(ue,zeros(2*10*144,1));

% Change user equipment settings to V2X sidelink mode. Set the V2X scrambling identity to 4567.

ue.SidelinkMode = 'V2X';
ue.NXID = 4567;
subframe_V2X = lteSLResourceGrid(ue);
pssch_indices = ltePSSCHIndices(ue);
subframe_V2X(pssch_indices) = ltePSSCH(ue,zeros(2*10*120,1));

% View the resource grid 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.