%% Retrieve Transport Block from UL-SCH Encoder with Multiple HARQ Processes
% Generate a random sequence of binary values corresponding to one transport block of length 5120.

trBlkLen1 = 5120;
trBlk1 = randi([0 1],trBlkLen1,1,'int8');

% Create and configure an UL-SCH encoder System object with multiple HARQ processes and the specified target code rate.

targetCodeRate = 567/1024;
encUL = nrULSCH('MultipleHARQProcesses',true);
encUL.TargetCodeRate = targetCodeRate;

% Load the transport block into the UL-SCH encoder for HARQ process number 1.

setTransportBlock(encUL,trBlk1,1);

% Call the encoder with QPSK modulation scheme, 1 transmission layer, an output length of 10,240 bits, redundancy version 0, and HARQ process number 1. The encoder applies the UL-SCH processing chain to the transport block loaded into the object using HARQ process number 1.

encUL('QPSK',1,10240,0,1); 

% Retrieve the transport block from the encoder for HARQ process number 1. Verify that the retrieved block is identical to the block originally loaded into the encoder for this HARQ process.

tmp = getTransportBlock(encUL,1);
isequal(tmp,trBlk1) 

% Repeat the encoding operation for a new transport block of length 4400 and HARQ process number 2.

trBlkLen2 = 4400;
trBlk2 = randi([0 1],trBlkLen2,1,'int8');
setTransportBlock(encUL,trBlk2,2); 
encUL('QPSK',1,8800,0,2);

% Retrieve the first transport block again. Verify that the first transport block is still unchanged.

tmp = getTransportBlock(encUL,1);
isequal(tmp,trBlk1)

% Copyright 2018-2019 The MathWorks, Inc.