This tutorial focuses only on the interleaving stage of 5G NR polar coding in 3GPP TS 38.212 section 5.3.1.1. The input is the bit sequence c0, c1, c2, ..., cK-1. The output is the interleaved sequence c'0, c'1, c'2, ..., c'K-1.
The purpose of this stage is not to change bit values. It changes only their order. The output bit c'k is copied from one input position cPI(k). The interleaver spreads the polar-code input bits according to a standardized 164-entry pattern.
3GPP Definition
The interleaved sequence reorders (but does not change) the bits — each output bit is copied from one input position, or kept in place if interleaving is disabled:
c′k = cPI(k), k = 0 ... K−1 (IIL=0 ⇒ PI(k) = k)
If the interleaver flag is enabled, 3GPP uses the fixed table PI_IL_MAX(m) of length K_IL_MAX = 164. The algorithm scans the table and keeps the entries belonging to the last K positions:
k = 0
for m = 0 to K_IL_MAX - 1
if PI_IL_MAX(m) >= K_IL_MAX - K
PI(k) = PI_IL_MAX(m) - (K_IL_MAX - K)
k = k + 1
end if
end for
Why The Threshold Exists
The master table is always 164 entries long, but the actual polar input length K can be smaller. The threshold 164 - K selects only the master-table entries that belong to the last K positions of the 164-position reference interleaver. After selection, subtracting 164 - K renumbers those selected positions into the local range 0 ... K-1.
Worked Example
Assume K = 32, I_IL = 1, and the input sequence is:
c = [1 1 0 1 0 0 1 1 1 0 0 1 0 1 1 0 0 0 1 0 1 1 0 1 0 1 1 1 0 0 1 0]
The threshold is:
K_IL_MAX - K = 164 - 32 = 132
When scanning the 164-entry table, entries smaller than 132 are skipped. Because the condition is >= 132, the table value 132 is kept.
how the first kept values are derived:
K = 32, K_IL_MAX = 164, threshold = K_IL_MAX - K = 164 - 32 = 132
scan PI_IL_MAX(m) from m = 0 upward and keep only values >= 132
m = 61: PI_IL_MAX(61) = 132 -> keep
m = 62: PI_IL_MAX(62) = 134 -> keep
m = 63: PI_IL_MAX(63) = 138 -> keep
m = 64: PI_IL_MAX(64) = 139 -> keep
m = 65: PI_IL_MAX(65) = 140 -> keep
m = 66 through 103: values are below 132 -> skip
m = 104: PI_IL_MAX(104) = 133 -> keep
The first kept table values are therefore 132, 134, 138, 139, 140, 133. Therefore the first six output bits are:
m derivation: scan PI_IL_MAX; PI_IL_MAX(61) = 132 is the 1st kept value because 132 >= 132, so m = 61 and k = 0
symbolic formula: PI(k) = PI_IL_MAX(m) - (K_IL_MAX - K)
plugged formula: PI(0) = 132 - 132 = 0, where k = 0 and m = 61
result: c'_0 = c_0 = 1
m derivation: continue scanning; PI_IL_MAX(62) = 134 is the 2nd kept value, so m = 62 and k = 1
symbolic formula: PI(k) = PI_IL_MAX(m) - (K_IL_MAX - K)
plugged formula: PI(1) = 134 - 132 = 2, where k = 1 and m = 62
result: c'_1 = c_2 = 0
m derivation: continue scanning; PI_IL_MAX(63) = 138 is the 3rd kept value, so m = 63 and k = 2
symbolic formula: PI(k) = PI_IL_MAX(m) - (K_IL_MAX - K)
plugged formula: PI(2) = 138 - 132 = 6, where k = 2 and m = 63
result: c'_2 = c_6 = 1
m derivation: continue scanning; PI_IL_MAX(64) = 139 is the 4th kept value, so m = 64 and k = 3
symbolic formula: PI(k) = PI_IL_MAX(m) - (K_IL_MAX - K)
plugged formula: PI(3) = 139 - 132 = 7, where k = 3 and m = 64
result: c'_3 = c_7 = 1
m derivation: continue scanning; PI_IL_MAX(65) = 140 is the 5th kept value, so m = 65 and k = 4
symbolic formula: PI(k) = PI_IL_MAX(m) - (K_IL_MAX - K)
plugged formula: PI(4) = 140 - 132 = 8, where k = 4 and m = 65
result: c'_4 = c_8 = 1
m derivation: rows 66 through 103 are below 132 and skipped; PI_IL_MAX(104) = 133 is the 6th kept value, so m = 104 and k = 5
symbolic formula: PI(k) = PI_IL_MAX(m) - (K_IL_MAX - K)
plugged formula: PI(5) = 133 - 132 = 1, where k = 5 and m = 104
result: c'_5 = c_1 = 1
Every output position is built the same way. The simulator below highlights the active table row, the selected input bit, the output bit position, and the exact formula used for that step.
Simulation
The interactive simulator is below. Use the controls to explore the concepts described above.
Usage Instructions
- Choose a preset: Start with NR control example K=32. It is large enough to show the table-filtering behavior while still being readable.
- Change K: The threshold
164 - K changes immediately. Smaller K skips more master-table entries.
- Toggle I_IL: Set
I_IL = 0 to see identity mapping PI(k)=k. Set I_IL = 1 to apply the 3GPP table-based interleaver.
- Edit input c: Type any sequence of 0 and 1. If the text is shorter than
K, the simulator repeats the pattern so there are always exactly K input bits.
- Step through the mapping: Use Step Fwd and Step Bwd. The formula panel shows
symbolic formula = plugged formula = result for the current output bit.
- Read the table: The table panel lists all
m rows of PI_IL_MAX(m). Skipped rows are dim; kept rows are highlighted as usable mapping rows.
- Read the curves: The left side is input
c. The right side is output c'. A curve from input index PI(k) to output index k means c'_k = c_PI(k).
What To Notice
Interleaving does not create new bits and does not perform XOR. It only reorders the existing K bits.
The standardized table is length 164 because K_IL_MAX = 164. For a smaller K, the thresholding step extracts a smaller interleaver from the same master pattern.
The same algorithm is used for every enabled case: scan the table, keep entries greater than or equal to 164 - K, subtract 164 - K, and copy c_PI(k) into c'_k.
Limitations
- Interleaving stage only. This page isolates the 5.3.1.1 input interleaver; it does not perform set construction, parity-check placement, the polar transform, or rate matching (see [[polarcodingencoding]] and [[polarcoding]] for those stages).
- Permutation, not coding. The interleaver only reorders bits — it adds no redundancy and provides no error protection by itself; its benefit appears only in combination with the downstream polar code.
- Single fixed table. Uses the one standardized 164-entry master pattern PIIL_MAX (Table 5.3.1.1-1); the demo just sub-selects from it and does not explore alternative or adaptive interleavers.
- K capped at 164. The reference interleaver length KIL_MAX = 164 bounds the payload shown; larger transport blocks are handled by segmentation upstream, which is out of scope.
- Noiseless, bit-exact. There is no channel or error model; the visualization shows the deterministic position mapping, not any performance metric.
- Uplink control context. The 164-entry interleaver corresponds to the uplink control (PUCCH/PUSCH) polar construction; other channels use different processing.