%% UL-SCH Encoding with Multiple HARQ Processes
% Generate a random sequence of binary values corresponding to one transport block of length 5120.

trBlkLen = 5120;
trBlk = randi([0 1],trBlkLen,1,'int8');

% Create and configure an UL-SCH encoder System object for use with multiple HARQ processes.

encUL = nrULSCH;
encUL.MultipleHARQProcesses = true;

% Load the transport block into the UL-SCH encoder, specifying HARQ process number 2.

harqID = 2;
setTransportBlock(encUL,trBlk,harqID);

% Call the encoder with QPSK modulation scheme, 3 transmission layers, an output length of 10,002 bits, and redundancy version 3. The encoder applies the UL-SCH processing chain to the transport block loaded into the object for HARQ process number 2.

mod = 'QPSK';
nLayers = 3;
outlen = 10002;
rv = 3;
codedTrBlock = encUL(mod,nLayers,outlen,rv,harqID);

% Verify that the encoded transport block has the required number of bits.

isequal(length(codedTrBlock),outlen)

% Copyright 2018-2019 The MathWorks, Inc.