%% Create PSBCH DM-RS Values
% Write the complex PSBCH DM-RS values into the PSBCH DM-RS resource elements in a synchronization subframe for both D2D and V2X sidelink modes and display an image of their locations.
% Create a user equipment settings structure and an empty resource grid subframe for 10 MHz bandwidth and D2D sidelink mode.

ue = struct();
ue.NSLRB = 50;
ue.CyclicPrefixSL = 'Normal';
ue.NSLID = 1;
subframe_D2D = lteSLResourceGrid(ue);

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

psbchdrs_indices = ltePSBCHDRSIndices(ue);
subframe_D2D(psbchdrs_indices) = ltePSBCHDRS(ue);

% Change user equipment settings to V2X sidelink mode.

ue.SidelinkMode = 'V2X';

% Generate the grid subframe, the PSBCH DM-RS indices and load PSBCH DM-RS values into subframe_V2X.

subframe_V2X = lteSLResourceGrid(ue);
psbchdrs_indices = ltePSBCHDRSIndices(ue);
subframe_V2X(psbchdrs_indices) = ltePSBCHDRS(ue);

% Display the PSBCH 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.