%% Encode BCH Transport Block
% Generate a random sequence of binary values corresponding to a BCH transport block of 24 bits.

trblk = randi([0 1],24,1,'int8');  

% Specify the physical layer cell identity number as 321, the system frame number as 10, and the second half frame.

nid = 321;  
sfn = 10;   
hrf = 1;     

% Specify the number of candidate SS/PBCH blocks as 8. When you specify the number of candidate SS/PBCH blocks as 4 or 8, you can specify the subcarrier offset kssb as an input argument to the BCH encoder.

lssb = 8;                     
kssb = 18;               

% Encode the BCH transport block using the specified arguments.

cdblk = nrBCH(trblk,sfn,hrf,lssb,kssb,nid);

% When you specify the number of candidate SS/PBCH blocks as 64, you can specify the SS block index ssbIdx as an input argument instead of the subcarrier offset kssb.

lssb = 64;                     
ssbIdx = 13;               

% Encode the BCH transport block with the updated input arguments.

cdblk2 = nrBCH(trblk,sfn,hrf,lssb,ssbIdx,nid);

% Copyright 2019 The MathWorks, Inc.