Web Simulation 

 

 

 

 

5G NR LDPC Rate Matching (3GPP TS 38.212 §5.4.2) 

This interactive tutorial visualizes the three stages of LDPC Rate Matching: Bit Selection, Bit Interleaving, and Bit Concatenation (output). The simulation uses a single code block with Base Graph 2 (BG2) and a circular buffer of length Ncb.

 

Mathematical foundation

1. Circular buffer (w)

The interleaved LDPC coded bits are mapped to the circular buffer w of length Ncb. For BG2 without limited buffer rate matching, Ncb = N = 52·Zc. The first 2·Zc bits are punctured (never transmitted). Systematic bits occupy the next 8·Zc positions (some may be filler <NULL>); the rest are parity bits.

2. Starting index k0

For BG2, k0 = ⌊(offset[rvid] · Ncb) / (50·Zc)⌋ · Zc, with offsets [0, 13, 25, 43] for RV 0, 1, 2, 3.

3. Bit Selection (5.4.2.1)

Select E bits from w starting at index k0, wrapping around if needed. Filler bits (value −1) are skipped and do not count toward E.

4. Bit Interleaving (5.4.2.2)

The E selected bits are written row-by-row into a matrix with C′ columns (e.g. from modulation order), then read column-by-column to form the final output.

2
100
= 0 50
Systematic Parity Punctured (2·Zc) Filler Window of Selection

Step detail

Waiting to start selection…
Waiting to start interleaving…

Key parameters (3GPP TS 38.212 §5.4.2)

Ncb
Circular buffer length — Total number of bits in the circular buffer w after encoding. Depends on limited: If limited = 0, Ncb = N (= N_COLS·Zc, e.g. 52·Zc for BG2). If limited = 1 (LBRM on), Ncb = min(N, Nref·Zc) with Nref from Table 5.4.2.1-1 (Max PRBs). Defines the size of the buffer from which bits are selected.
limited
LBRM indicator (0 or 1) — Binary flag: 0 = use full buffer (Ncb = N); 1 = use limited buffer (Ncb = min(N, Nref·Zc)). In the spec this is set by higher-layer signaling; in this sim you set it via the "limited (LBRM)" checkbox.
k0
Starting index — Offset where bit selection begins in the circular buffer. k0 = ⌊(offset[rvid]·Ncb)/(denom)⌋·Zc, with denom = 66·Zc (BG1) or 50·Zc (BG2) per Table 5.4.2.1-2. Used for HARQ: different RV shifts the start so the receiver can combine retransmissions.
E
Number of bits to select — Desired length of the rate-matched output. Exactly E bits are collected from w starting at k0 (wrapping if needed), skipping punctured and filler bits. These bits are then interleaved to form the final transmitted sequence.
ParameterValueHow obtained
limited (LBRM)From Parameter Setting
NcbFrom Calculation. If limited=0: Ncb=N (= N_COLS·Zc). If limited=1: Ncb=min(N, Nref·Zc) (Table 5.4.2.1-1).
k0From Calculation. k0=⌊(offset[rvid]·Ncb)/(denom)⌋·Zc; denom=66·Zc (BG1) or 50·Zc (BG2) (Table 5.4.2.1-2).
EFrom Parameter Setting
Systematic bits transmittedFrom Calculation (bit selection output: count of selected systematic bits).
Parity bits transmittedFrom Calculation (bit selection output: count of selected parity bits; = E − systematic).

Input bits (code block)

d0, d1, d2, …, dN−1 (N = Ksb·Zc − fcnt; Ksb=22 for BG1, Ksb=10 for BG2; fcnt = length of filler bits). Current: N =

d0 … dN−1:

Circular buffer w

Length Ncb — Window of Selection from k0 for E bits

Where each colored section in the circular buffer comes from (3GPP TS 38.212)

  • Red (Punctured): First 2·Zc bits of the systematic part of the LDPC coded block. In 5G NR these bits are always punctured and are not included in the selected bit sequence.
  • Green (Systematic): Bits from the input sequence d. For BG2 the systematic part is Kb·Zc − 2·Zc minus filler bits; they represent the actual data before parity.
  • Grey (Filler): fcnt filler bits inserted to match the code block size; skipped during bit selection.
  • Cyan/Blue (Parity): Redundancy bits from the LDPC encoder; they fill the remainder of the circular buffer after the systematic section, up to length Ncb.

Buffer construction: Punctured (Red, 2·Zc) → Systematic (Green) → Filler (Grey, fcnt) → Parity (Cyan/Blue) up to Ncb.

Click "Animate Bit Selection" or "Step Fwd" to see step-by-step status.

Bit Selection

Parameters for bit selection: LBRM (Table 5.4.2.1-1) and k0 (Table 5.4.2.1-2).

Bit selection output e (e1, e2, …, eE−1):

Table 5.4.2.1-1: Limited buffer rate matching (LBRM)

max PRBNref (nPRB)
3332
6666
107107
135135
162162
217217
273

Table 5.4.2.1-2: k0 (Ncb = , Zc = )

rvidk0 for LDPC base graph 1k0 for LDPC base graph 2
00 = 0 =
1⌊(17·Ncb)/(66·Zc)⌋·Zc = ⌊(13·Ncb)/(50·Zc)⌋·Zc =
2⌊(33·Ncb)/(66·Zc)⌋·Zc = ⌊(25·Ncb)/(50·Zc)⌋·Zc =
3⌊(56·Ncb)/(66·Zc)⌋·Zc = ⌊(43·Ncb)/(50·Zc)⌋·Zc =

Bit Interleaving

Matrix based on Qm (C′ columns). Write row-by-row, read column-by-column (5.4.2.2).

Click "Animate Interleaving", "Step Bwd", or "Step Fwd" to see step-by-step status.

Final Output: Serialized bitstream fk (length E) = f0, f1, …, fE−1

Bit Interleaving output f: the final sequence sent to the modulator (3GPP TS 38.212 §5.4.2.2).

 

Usage

Use this simulation to explore 3GPP TS 38.212 Section 5.4.2 LDPC Rate Matching:

  1. Run Rate Matching: Builds the circular buffer, computes k0, selects E bits (Bit Selection output e), interleaves (Final output fk), and updates all views.
  2. Zc: Lifting size (2, 4, 8, 16). Ncb = 52·Zc for BG2.
  3. E: Output length (number of bits to select). Bit Selection output e and Final output fk both have length E.
  4. RV (Redundancy Version): 0–3. Determines k0 for bit selection (Incremental Redundancy).
  5. Qm (Modulation Order): 2 (QPSK), 4 (16QAM), 6 (64QAM), 8 (256QAM). Sets interleaver columns C′ = Qm and rows R′ = ⌈E/Qm⌉ per 5.4.2.2. Matrix is written row-by-row from e, read column-by-column to form fk. Filler cells (−) are skipped when reading.
  6. Filler bits: <NULL> bits at the end of the systematic part; skipped during bit selection and do not count toward E.
  7. Bit Selection: Animate Bit Selection or Step Fwd (below the circular buffer) shows step-by-step selection; Step detail and inline status show Collecting/Skipping.
  8. Bit Interleaving: Animate Interleaving runs write-then-read; Step Bwd / Step Fwd step through (wrap around at end/start). Status shows f[k] = e[i] or NULL/Filler skip. Bit Selection output e and Final output fk highlight in sync.

Tips: Start with Zc=2 and E=100. Change Qm to see matrix rows change (e.g. Qm=6 → R′ = ⌈100/6⌉ = 17 rows). Change RV to see k0 shift the selection window.

Parameters

  • Zc: Lifting size; Ncb = 52·Zc for BG2.
  • E: Rate-matched output length in bits (Bit Selection e and Final fk length).
  • RV: Redundancy version (0–3); defines k0 for bit selection.
  • Qm (C′): Modulation order = interleaver columns (3GPP 5.4.2.2). Rows R′ = ⌈E/Qm⌉.
  • Filler bits: NULL bits in systematic part; skipped in selection.
  • limited (LBRM): When checked, Ncb = min(N, Nref·Zc); Max PRBs selects Nref from Table 5.4.2.1-1.