NR uses LDPC for data and Polar code for control. This is what most of us remember about 5G channel coding. But there is one more code which does not get much attention. When UE sends only a few bits of UCI, for example 4 bits of HARQ-ACK or a small CSI report, neither LDPC nor Polar code is used. If the payload is 3 to 11 bits, UE encodes it with a (32, K) block code. This code is usually called Reed Muller code, or RM code in short.
One interesting thing is that 38.212 never uses the name Reed Muller. The specification just calls it
- Why we need another channel code ?
- Where is it used in NR ?
- What is Reed Muller code ?
- How the encoding works ?
- Example
- Rate Matching
- How strong is the code ?
- How gNB decodes it ?
- Comparison with LTE
- Reference
Why we need another channel code ?
Then you may ask why we need one more code when we already have Polar code for the control channel. The reason is the size of the payload. HARQ-ACK for a few PDSCHs, SR or a wideband CQI is only a few bits. The codes designed for long blocks do not work well at this size.
Let's think of what happens if we use Polar code for 4 bits. Polar code in NR depends on CRC. The decoder keeps a list of candidates and uses CRC to pick the right one out of the list. If we attach even the shortest 6 bit CRC to a 4 bit payload, more than half of what UE transmits is CRC. That is a big overhead. In addition, the polarization effect itself needs a certain block length before it starts paying off.
Now look at the problem from the other side. If the payload is K bits, there are only 2K possible messages. With K = 11 this is 2048. This is small enough for gNB to compare the received signal with every possible codeword and pick the closest one. This is Maximum Likelihood decoding, and no decoder can do better than this. So for a very small payload the best strategy is simple. Choose a short block code whose codewords are as far apart from each other as possible, and let the receiver do the brute force comparison. Reed Muller code is a code of this kind.
There are a couple of points that I want you to keep in mind before going further.
There is no CRC. UCI of 11 bits or less is transmitted without any CRC. So gNB has no CRC result to tell whether the decoding was right or wrong.The output is always 32 bits. Whatever K is, the encoder produces 32 bits. Fitting these 32 bits to the real resource is the job of rate matching.The whole code is one table. There is no shift register, no interleaver and no reliability sequence. If you have the table, you have the encoder.
Where is it used in NR ?
The small block length codes apply only to UCI, and the code is selected purely by the number of UCI bits. Figure 1 shows how the payload size is mapped to the channel code. For now, just pay attention to the box in the middle. This is the range that this note is about.
Figure 1. Channel code selection for UCI. Only the number of UCI bits decides the code, and Reed Muller code takes the range of 3 to 11 bits where no CRC is attached.
Following table is the same thing with the clause numbers of 38.212, so that you can find the original text easily.
UCI payload |
Channel code |
CRC |
38.212 clause |
1 bit |
Repetition code |
None |
5.3.3.1 |
2 bits |
Simplex code |
None |
5.3.3.2 |
None |
5.3.3.3 |
||
12 to 19 bits |
Polar code |
6 bits |
5.3.1 |
20 bits or more |
Polar code |
11 bits |
5.3.1 |
Then which physical channel carries the Reed Muller coded bits ? There are two cases. One is UCI on PUCCH format 2, 3 and 4, which is described in 38.212 6.3.1. The other is UCI multiplexed on PUSCH, which is described in 38.212 6.3.2. Both of them point to the same clause 5.3.3 when the payload is 11 bits or less. PUCCH format 0 and 1 are not in this list. They carry at most 2 bits, and they do it by selecting or modulating a sequence, so there is no channel coding step in them.
HARQ-ACK, SR and CSI are all treated the same. The encoder does not care what the bits mean. It only looks at the total number of bits in the UCI bit sequence.A very short CSI part 2 is padded. If CSI part 2 on PUCCH is shorter than 3 bits, zeros are appended until it becomes 3 bits (38.212 6.3.1.1.3). So it goes through the (32, K) code with K = 3.DCI never uses it. A DCI format shorter than 12 bits is zero padded to 12 bits, and then it goes to Polar code with 24 bit CRC. Downlink has no small block length coding.
What is Reed Muller code ?
Before we look at the table in 38.212, it would be helpful to know what Reed Muller code is in general. I will not go through the whole theory. For now, just pay attention to the first order code, because this is what the NR table is built on.
A Reed Muller code is written as RM(r, m). The codeword length is 2m. The basic idea is as follows. Take a Boolean polynomial of m variables x1 to xm whose degree is r or less. The coefficients of the polynomial are the information bits. Evaluate the polynomial at all 2m combinations of the variables, and the 2m results are the codeword. The minimum distance of RM(r, m) is 2m-r.
In the first order code, r is 1. So the polynomial is just a0 + a1x1 + ... + amxm, and there are m + 1 information bits. In other words, the codeword is a linear combination of m + 1 basis sequences. One is the all ones sequence, which belongs to a0. The others are x1 to xm, where xj is just the j-th bit of the position index written in binary. Following is the case of m = 3.
position : 0 1 2 3 4 5 6 7 --------------------------------- 1 all ones : 1 1 1 1 1 1 1 1 x1 : 0 1 0 1 0 1 0 1 x2 : 0 0 1 1 0 0 1 1 x3 : 0 0 0 0 1 1 1 1
If you XOR any combination of these four rows, the result is all 0, all 1, or a sequence with exactly four 1s and four 0s. This is the important property of the first order Reed Muller code. Any two different codewords differ in exactly half of the positions, or in all of the positions. The codewords are spread as far apart as the length allows.
Now apply this to m = 5. RM(1, 5) takes 6 information bits and gives 32 coded bits with minimum distance 16. But NR needs to carry up to 11 bits. Then how do we get 5 more bits ? The answer is to add 5 more basis sequences on top of the 6 sequences of RM(1, 5). These additional sequences are usually called
Strictly speaking, it is an extended Reed Muller code. Only the first 6 basis sequences form a real Reed Muller code. The whole (32, 11) code is RM(1, 5) plus 5 masks. People just call the whole thing Reed Muller code.The price of more bits is distance. This is the trade off that decides everything in the later sections of this note.
How the encoding works ?
Now let's get into the specification. 38.212 5.3.3.3 defines the whole encoder in one line. The input is K bits c0, c1, ... , cK-1 with 3 ≤ K ≤ 11. The output is always N = 32 bits d0, d1, ... , d31.
di = ( c0 Mi,0 + c1 Mi,1 + ... + cK-1 Mi,K-1 ) mod 2 , i = 0, 1, ... , 31
Mi,k is the basis sequence given by 38.212 Table 5.3.3.3-1. The equation may look a little formal, but the meaning is simple. Each information bit ck owns one column of the table. If ck is 1, the column is XORed into the output. If ck is 0, the column is ignored. So the codeword is just the XOR of the columns selected by the 1s in the payload. Figure 2 shows the whole flow, including the rate matching that comes after the encoder.
Figure 2. Encoding and rate matching of the (32, K) code. The payload only selects which columns of the table are XORed, so K decides how many columns are in use and whether the mask sequences get involved.
One thing you would notice is that K is not signaled or configured separately. K is just the number of UCI bits. UE uses the first K columns of the table and never touches the rest. For example, a 4 bit payload uses Mi,0 to Mi,3 only.
Basis sequence table
Following is 38.212 Table 5.3.3.3-1, based on
i |
Mi,0 |
Mi,1 |
Mi,2 |
Mi,3 |
Mi,4 |
Mi,5 |
Mi,6 |
Mi,7 |
Mi,8 |
Mi,9 |
Mi,10 |
0 |
1 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 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|
0 |
1 |
0 |
0 |
1 |
1 |
0 |
1 |
23 |
1 |
1 |
1 |
0 |
1 |
0 |
0 |
0 |
1 |
1 |
1 |
24 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
0 |
25 |
1 |
1 |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
0 |
1 |
26 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
0 |
1 |
1 |
0 |
27 |
1 |
1 |
1 |
1 |
0 |
1 |
0 |
1 |
1 |
1 |
0 |
28 |
1 |
0 |
1 |
0 |
1 |
1 |
1 |
0 |
1 |
0 |
0 |
29 |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
0 |
30 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
31 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
What is inside the table ?
At first, the table just looks like a random pattern of 0 and 1. But if you look at it column by column, you would find a clear structure in it. I checked the following points with a small script rather than by eye.
Mi,0 is all ones. This is the constant term of the first order Reed Muller code. So c0 = 1 flips every bit of the codeword.Mi,1 to Mi,5 count from 0 to 31. Read these five bits in each row as one 5 bit number. The 32 rows give all the values from 0 to 31 exactly once. For example, i = 31 is 00000 and i = 30 is 11111. This means that these five columns are x1 to x5 of RM(1, 5), but with the rows shuffled.So K of 6 or less is a pure RM(1, 5). Shuffling the rows changes the order of the coded bits, but it does not change the distance between codewords. Every codeword other than all 0 and all 1 has exactly sixteen 1s.Mi,6 to Mi,10 are the mask sequences. They cannot be made by XORing the first six columns. They come into play only when K is 7 or more.The first 16 rows of Mi,10 are all ones. In other words, Mi,10 looks exactly like Mi,0 in the range of i = 0 to 15. Please remember this. It becomes a problem in rate matching.
I couldn't find a clear description about why the rows are placed in this particular order rather than in the natural binary order. My guess is that it is related to how the code behaves when a part of the 32 bits is not transmitted, but I don't want to say this is the exact reason.
Example
Now let's check this with real numbers. Assume that UE has 4 bits of HARQ-ACK to send, and the bits are c0 c1 c2 c3 = 1 1 0 1. K is 4, so only Mi,0 to Mi,3 are used. In addition, c2 is 0, so Mi,2 drops out. What remains is the XOR of three columns. In the following, each column of the table is written as one line, from i = 0 on the left to i = 31 on the right.
i = 0 i = 31
| |
M(i,0), c0 = 1 : 1111 1111 1111 1111 1111 1111 1111 1111
M(i,1), c1 = 1 : 1100 1100 1001 0101 1010 0101 1101 0010
M(i,2), c2 = 0 : not used
M(i,3), c3 = 1 : 0011 1001 1100 1100 0110 0100 1011 0110
---------------------------------------------------------
d = XOR : 0000 1010 1010 0110 0011 1110 1001 1011
If you count the 1s in d, you get 16. This is not a coincidence. As I mentioned above, when K is 6 or less every codeword other than all 0 and all 1 has exactly sixteen 1s. You can try any other 4 bit payload and you will get the same count.
You can do the same thing with a few lines of code. Following is a Python example. The table is typed in row by row, and the two functions are direct translations of 38.212 5.3.3.3 and 5.4.3. I will explain the second function in the next section.
# 38.212 Table 5.3.3.3-1. One string per row i, M(i,0) on the left
M = [
"11000000001", "11100000011", "10010010111", "10110000101",
"11110001001", "11001011101", "10101010111", "10011001101",
"11011001011", "10111010011", "10100111011", "11100110101",
"10010101111", "11010101011", "10001101001", "11001111011",
"11101110010", "10011100100", "11011111000", "10000110000",
"10100010001", "11010000011", "10001001101", "11101000111",
"11111011110", "11000111001", "10110100110", "11110101110",
"10101110100", "10111111100", "11111111111", "10000000000"]
def rm_encode(c): # 38.212 5.3.3.3, len(c) = K = 3 .. 11
return [sum(int(M[i][k]) * c[k] for k in range(len(c))) % 2 for i in range(32)]
def rate_match(d, E): # 38.212 5.4.3
return [d[k % 32] for k in range(E)]
d = rm_encode([1, 1, 0, 1])
print("".join(map(str, d))) # 00001010101001100011111010011011
print("".join(map(str, rate_match(d, 16)))) # 0000101010100110
The encoder is a table lookup and XOR. The whole thing fits in one line of code, and this is why UE side complexity is never an issue for this code.A payload of all zeros gives a codeword of all zeros. The code is linear, so this is always the case. Scrambling is applied after the encoding, so what goes on the air is not all zeros.
Rate Matching
The encoder always produces 32 bits. But the number of bits that PUCCH or PUSCH can carry is almost never exactly 32. Then how UE fits the 32 bits into the given resource ? 38.212 5.4.3 handles this, and again the rule is only one line. E is the rate matching output sequence length.
ek = dk mod N , k = 0, 1, ... , E-1 , N = 32
UE reads d from the beginning and goes back to d0 when it reaches the end. If E is smaller than 32, the tail of the codeword is simply not transmitted. If E is larger than 32, the codeword is repeated. There is no interleaver, no redundancy version and no starting offset. Following is the result for the codeword of the example above.
d, 32 bits : 0000 1010 1010 0110 0011 1110 1001 1011 E = 16 : 0000 1010 1010 0110 E = 32 : 0000 1010 1010 0110 0011 1110 1001 1011 E = 48 : 0000 1010 1010 0110 0011 1110 1001 1011 0000 1010 1010 0110
Then where does E come from ? For PUCCH, it comes from the size of the PUCCH resource. 38.212 Table 6.3.1.4-1 gives the total number of coded bits as follows.
PUCCH format 2 : 16 x number of UCI symbols x number of PRBs. Format 2 has 8 data REs per PRB per symbol and uses QPSK.PUCCH format 3 : 24 x number of UCI symbols x number of PRBs with QPSK, and 12 instead of 24 with pi/2-BPSK.PUCCH format 4 : 24 x number of UCI symbols / spreading factor with QPSK, and 12 instead of 24 with pi/2-BPSK.
So PUCCH format 2 with 1 PRB and 1 symbol gives E = 16, and only d0 to d15 are transmitted. With 1 PRB and 2 symbols E is 32, and exactly one codeword is transmitted. PUCCH format 3 with 1 PRB and 4 UCI symbols in QPSK gives E = 96, so the codeword is transmitted three times. When different types of UCI are multiplexed in one PUCCH, the total is split according to 38.212 Table 6.3.1.4.1-1. For UCI on PUSCH, E comes from the beta offset calculation in 38.212 6.3.2.4. I will not go through those cases here, because the rule of this section does not change. Only the value of E changes.
Now we know how the 32 bits are stretched or cut. But we still have one more question. Is it really OK to cut a codeword down to 16 bits ?
How strong is the code ?
Under Maximum Likelihood decoding, the strength of a block code is mostly decided by the minimum distance. This is the smallest number of bit positions in which two different codewords differ. The larger it is, the more bit errors the receiver can survive. I computed it from the table for every K, first for the full 32 bit codeword.
K |
Number of codewords |
Basis sequences in use |
Minimum distance |
3 to 6 |
8 to 64 |
Mi,0 to Mi,5 only |
16 |
7 to 10 |
128 to 1024 |
1 to 4 mask sequences added |
12 |
11 |
2048 |
all 5 mask sequences added |
10 |
As you see, there are three steps. Up to K = 6 the code is a pure RM(1, 5), and the distance is 16, which is half of the codeword length. The first mask sequence brings it down to 12, and it stays at 12 until K = 10. The last mask sequence brings it down to 10. So a 3 bit payload and a 6 bit payload are protected equally, and a 7 bit payload is clearly weaker than a 6 bit one.
But this is only for E = 32. With rate matching, a part of the codeword is cut or repeated, and the distance changes with it. Following table shows the minimum distance after rate matching for several values of E. This table is my own calculation from 38.212 Table 5.3.3.3-1 and the rule in 5.4.3. It is not a table from the specification.
K |
E = 16 |
E = 24 |
E = 32 |
E = 48 |
E = 64 |
3 |
7 |
10 |
16 |
23 |
32 |
4 |
6 |
9 |
16 |
22 |
32 |
5 |
6 |
9 |
16 |
22 |
32 |
6 |
4 |
9 |
16 |
20 |
32 |
7 |
3 |
7 |
12 |
16 |
24 |
8 |
3 |
7 |
12 |
16 |
24 |
9 |
3 |
6 |
12 |
15 |
24 |
10 |
3 |
6 |
12 |
15 |
24 |
11 |
4 |
10 |
10 |
20 |
There are a couple of points that I want you to notice here.
Repetition gives energy, not coding gain. E = 64 is exactly two times E = 32 in every row. Sending the codeword twice doubles the distance, which is the same thing as 3 dB more energy. It does not make the code itself any better.Partial repetition helps unevenly. At E = 48 the first 16 bits are sent twice. Most rows gain something from it, but K = 11 stays at 10.Truncation hurts a lot. At E = 16 a 4 bit payload still has distance 6, but K = 7 to 10 are down to 3.K = 11 with E = 16 gives distance 0. This means that two different payloads produce exactly the same 16 bits.
The last one surprised me, so let me explain where it comes from. As I mentioned in the table section, Mi,10 is all ones for i = 0 to 15. This is the same as Mi,0 in that range. So if a payload has both c0 and c10 set to 1, the two columns cancel each other in the first 16 bits. For example, the payload 1 0 0 0 0 0 0 0 0 0 1 gives sixteen 0s, and so does the payload of all zeros. In general, flipping c0 and c10 together does not change e0 to e15 at all. gNB cannot distinguish such two payloads however high the SNR is. According to my calculation, E has to be at least 17 for all 2048 codewords of K = 11 to be different.
Then can this combination happen in a real network ? PUCCH format 2 with 1 PRB and 1 symbol gives E = 16. According to 38.213 9.2.5.2, UE uses the minimum number of PRBs that keeps the code rate within maxCodeRate. 11 bits in 16 coded bits is a code rate of about 0.69, and this is lower than the largest maxCodeRate value 0.80 in 38.213 Table 9.2.5.2-1. So my understanding is that the specification does not exclude this case when the network configures maxCodeRate of 0.80 for a one symbol PUCCH format 2. I haven't confirmed this with a real log, so please take it as my reading of the specification. In any case, it is the network that decides the PUCCH resource and maxCodeRate. A lower maxCodeRate or a two symbol resource removes the problem.
How gNB decodes it ?
38.212 specifies only the encoder. How gNB decodes the bits is up to the implementation, as always. But the structure of the code gives a pretty clear hint about how it can be done. So I will describe the common approach here, not a method written in any specification.
The simplest way is the brute force comparison that I mentioned at the beginning. gNB generates all 2K codewords, applies the same rate matching and scrambling to them, and correlates each of them with the received soft bits. The codeword with the largest correlation wins. With K = 11 this is 2048 correlations of length E. This is not a big number for a base station.
There is a faster way, and this is where the Reed Muller structure helps. The codewords of the first order Reed Muller code are the rows of a Hadamard matrix and their inverted copies. So the correlation with all of them can be computed at once by
Step 1. Combine the soft bits that belong to the same di. This undoes the repetition of rate matching. The positions that were cut are set to 0.Step 2. Put the 32 soft bits back into the natural binary order, using the 5 bit number made of Mi,1 to Mi,5 as the index.Step 3. Run a 32 point Fast Hadamard Transform. The position of the largest absolute value gives c1 to c5, and its sign gives c0. For K of 6 or less, the decoding is done here.Step 4. For K of 7 or more, repeat Step 3 for every combination of the mask bits. For each combination, flip the sign of the soft bits where the combined mask is 1, and then run the transform. The combination with the largest peak wins. There are at most 32 combinations, so this is 32 transforms instead of 2048 correlations.
There is one more thing which is easy to miss. Because there is no CRC, the decoder always gives some answer. It gives an answer even when UE did not transmit anything, for example when UE missed the DCI. So gNB cannot rely on the decoder output alone. My understanding is that gNB normally compares the largest correlation value with a threshold and treats the result as DTX when the value is below it. Where to put the threshold is a trade off between missing a real transmission and accepting noise as UCI, and this part is completely up to the implementation.
Comparison with LTE
If you have worked on LTE, the table in this note would look familiar. NR did not design a new code for this range. It took the (32, O) code of LTE as it is. I compared 38.212 Table 5.3.3.3-1 with 36.212 Table 5.2.2.6.4-1 entry by entry, and all 352 entries are same. What changed is how the code is used around it.
Item |
LTE |
NR |
Basis sequences for the 32 bit code |
36.212 Table 5.2.2.6.4-1, (32, O) code, 11 sequences |
38.212 Table 5.3.3.3-1, (32, K) code, 11 sequences. Every entry is same as LTE |
Other block code table |
36.212 Table 5.2.3.3-1, (20, A) code with 13 basis sequences |
None. Only one table |
HARQ-ACK of more than 11 bits |
Split into two bit sequences. Each one is encoded by the (32, O) code and the two outputs are concatenated. See 36.212 5.2.2.6.5 |
Polar code with CRC |
CQI of more than 11 bits on PUSCH |
CRC attachment and then the convolutional code of 36.212 5.1.3.1 |
Polar code with CRC |
CRC for 11 bits or less |
None |
None |
In LTE the Reed Muller code was stretched in several ways. There was a separate (20, A) code for PUCCH format 2. And when HARQ-ACK got longer than 11 bits, LTE split the bits into two halves and ran the (32, O) encoder twice. NR removed all of these. There is only one table, it covers only 3 to 11 bits, and Polar code takes over from 12 bits. I think this is one of the places where NR is simpler than LTE.
Same table, same rate matching. The circular repetition of the 32 bits is also the same as in LTE. So an LTE implementation of this encoder can be reused for NR without any change.The range above 11 bits is where the two differ. LTE kept using Reed Muller code or convolutional code there, and NR switches to Polar code with CRC.
Reference
- 3GPP TS 38.212 v19.4.0 : NR; Multiplexing and channel coding - clause 5.3.3, 5.4.3, 6.3.1, 6.3.2
- 3GPP TS 38.213 v19.5.0 : NR; Physical layer procedures for control - clause 9.2.5.2
- 3GPP TS 36.212 v19.3.0 : E-UTRA; Multiplexing and channel coding - clause 5.2.2.6.4, 5.2.2.6.5, 5.2.3.3