%% Create PSSCH DM-RS Values
% Write the complex PSSCH DM-RS values into the PSSCH DM-RS 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.
% Create a user equipment settings structure and an empty resource grid subframe for 10 MHz bandwidth and 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]';
subframe_D2D = lteSLResourceGrid(ue);

% Generate PSSCH DM-RS indices and load PSSCH DM-RS values into the subframe.

psschdrs_indices = ltePSSCHDRSIndices(ue);
subframe_D2D(psschdrs_indices) = ltePSSCHDRS(ue);

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

ue.SidelinkMode = 'V2X';
ue.NXID = 5334;
subframe_V2X = lteSLResourceGrid(ue);
psschdrs_indices = ltePSSCHDRSIndices(ue);
subframe_V2X(psschdrs_indices) = ltePSSCHDRS(ue);

% Display the PSCCH DM-RS locations for both sidelink modes.

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

% Copyright 2012 The MathWorks, Inc.