%% Generate PSBCH Indices
% Generate PSBCH values and indices. Write the values into the PSBCH resource elements in a synchronization subframe for both D2D and V2X sidelink modes, and display an image of their locations. This mapping also writes the PSBCH values into the last SC-FDMA guard symbol within a subframe. The sidelink SC-FDMA modulator removes PSBCH values from the last SC-FDMA guard symbol in a separate processing step.
% Create a user equipment settings structure and a resource grid that has 10 MHz bandwidth and normal cyclic prefix for D2D sidelink mode.

ue.NSLRB = 50;
ue.CyclicPrefixSL = 'Normal';
ue.NSLID = 1;

% Generate an empty resource grid and PSBCH indices. Load the PSBCH indices into the resource grid.

grid_D2D = lteSLResourceGrid(ue);
psbch_indices = ltePSBCHIndices(ue);
grid_D2D(psbch_indices) = ltePSBCH(ue,zeros(2*576,1));

% Change user equipment settings to V2X sidelink mode.

ue.SidelinkMode = 'V2X';

% Generate an empty resource grid and PSBCH indices. Load the PSBCH indices into the resource grid.

grid_V2X = lteSLResourceGrid(ue);
psbch_indices = ltePSBCHIndices(ue);
grid_V2X(psbch_indices) = ltePSBCH(ue,zeros(2*504,1));

% Display the locations of the PSBCH indices for both sidelink modes.

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

% Copyright 2012 The MathWorks, Inc.