MATLAB: How to use rate matching to alter turbo code rate

turbo codes rate matching lte

Hello,
My objective is to alter the code rate of turbo codes given a certain code-word size. Right now i'm just experimenting with just coding and rate matching. I was trying to produce a code word with rate 1/2 using the following code:
msgLen = 4032; %From 3gpp lte
cdLen = 2*msgLen; %try: code rate 1/2
mbits = randi([0,1],msgLen, 1);
cd = lteTurboEncode(mbits);
cdrm = lteRateMatchTurbo(cd, cdLen, 0);
cdrx = lteRateRecoverTurbo(cdrm, msgLen, 0);
mhat = lteTurboDecode(cdrx);
Problem: the rate recover function returns a cell with vector of length 12300×1 while my original coded vector was of size 12108×1 (3 x 4032 + 12).
Why does the rate recover function assume a transport block size of 4096 thats one step bigger than the 4032 I have used? Any help would be appreciated. Thanks!

Best Answer

HI Muhammad,
The difference in size you see is due to the way lteRateRecoverTurbo works. The lteRateRecoverTurbo takes in the input block length and then internally calculates what would be the lenght of coded bits. This includes the complete chain of CRC attachment and Code block segmentation and then coding, though you didn't perform those stages.
Inorder to make your code work, in the message length that is passed to the lteRateRecoverTurbo, subtract the amount of CRC that is used, which is 24.
The following code will work
msgLen = 4032; %From 3gpp lte
cdLen = 2*msgLen; %try: code rate 1/2
mbits = randi([0,1],msgLen, 1);
cd = lteTurboEncode(mbits);
cdrm = lteRateMatchTurbo(cd, cdLen, 0);
cdrx = lteRateRecoverTurbo(cdrm, msgLen-24, 0); % Subtract the number of CRC bits
mhat = lteTurboDecode(cdrx);
size(mhat{1}) % This provides the length as input passed
Indeed, if you try having both CRC encoding and Code block segmentation processing, you can easily figure out why the difference as come.
msgLen = 4032;
cdLen = 2*msgLen;
mbits = randi([0,1],msgLen, 1);
crc = lteCRCEncode(mbits,'24A');
cbs = lteCodeBlockSegment(crc); % This will provide a length 4096 bits that is input to the Turbo encoder
cd = lteTurboEncode(cbs);
cdrm = lteRateMatchTurbo(cd, cdLen, 0);
cdrm(cdrm == 0) = -1; % Make them as LLRs
cdrx = lteRateRecoverTurbo(cdrm, msgLen, 0);
mhat = lteTurboDecode(cdrx); % So after the Turbo decoding, it will have 4096 bits rather than 4032 bits, due to addition of filler bits and CRC
cbshat = lteCodeBlockDesegment(mhat, msgLen+24);
crchat = lteCRCDecode(cbshat,'24A'); % This will return the same as message length
% Check the decoded bits with message bits
isequal(double(crchat),mbits)
To get the information about what the lengths are at each processing stage of transport channel, you can use lteDLSCHInfo and lteULSCHInfo functions.
Hope this provides some insights of what went wrong and the ways to proceed further.
Regards,
Sriram