This interactive tutorial visualizes the construction of the 5G NR LDPC parity-check matrix (H) from Base Graph 2 (BG2). The flow goes from a single number—the Transport Block Size (TBS)—to a sparse H-matrix with thousands of elements: TBS → Zc / iLS → Base Graph grid → expanded H-matrix.
Mathematical foundation
1. Input and set selection
You enter TBS. The simulator chooses the lifting size Zc and the set index iLS (0–7) so that the systematic capacity covers the target length:
The 3GPP spec defines eight lifting sets; each gives a list of allowed Zc values (e.g. Set 0: 2, 4, 8, …, 256). The smallest valid Zc in the appropriate set is selected.
2. Base Graph (BG2) visualization
BG2 is a 42×52 template. Each cell (r, c) is either empty (null) or holds a shift value sr,c that depends on iLS: the shift table stores eight values per cell (one per iLS). The left grid shows this base graph; occupied cells display the current shift. Hovering a cell highlights the corresponding block in the full H-matrix on the right.
3. Lifting (expansion)
Each non-empty cell (r, c) is replaced by a Zc×Zc circulant matrix: an identity matrix shifted right by sr,c mod Zc. Empty cells become Zc×Zc zero blocks. Clicking a cell in the base graph opens a Block Detail popup showing the circulant (1s and 0s) for that block.
4. Full H-matrix
The final H has size (42·Zc) × (52·Zc). It is drawn on the canvas as a bitmap: black = 1, white = 0. At large Zc the matrix is very sparse; the canvas scales to fit the simulation area (max width 800 px).
Simulation
The interactive simulator is below. Use the controls to explore the concepts described above.
- Ktarget = TBS + 24 (code block length including CRC).
- For BG2, Kb = 10 (constant for BG2). Require Kb · Zc ≥ Ktarget.
- Search all sets in the table below; choose the smallest Zc that satisfies the condition.
- The set index iLS of that set is used for the base graph shift table.
Set index (iLS) |
Set of lifting sizes (Z) |
|---|---|
0 |
2, 4, 8, 16, 32, 64, 128, 256 |
1 |
3, 6, 12, 24, 48, 96, 192, 384 |
2 |
5, 10, 20, 40, 80, 160, 320 |
3 |
7, 14, 28, 56, 112, 224 |
4 |
9, 18, 36, 72, 144, 288 |
5 |
11, 22, 44, 88, 176, 352 |
6 |
13, 26, 52, 104, 208 |
7 |
15, 30, 60, 120, 240 |
Property |
Value / Formula |
Description |
|---|---|---|
Base Graph Dim |
42 × 52 |
The macro template. |
Lifting Size (Zc) |
— |
User input (scaling factor). |
Full H-Matrix Dim |
— |
The actual sparse matrix size. |
Total Elements |
— |
Total number of bits in the H-matrix. |
Action |
Logic |
Result |
|---|---|---|
Encoding |
Solve H·c = 0 |
Generates valid parity bits. |
Transmission |
Send vector c |
The complete codeword. |
Verification |
Check H·cT |
Must be 0 for no errors. |
Error |
H·cT ≠ 0 |
Syndrome non-zero; failed rows highlighted. |
Usage
Use this simulation to explore 5G NR LDPC BG2 H-matrix construction and codeword verification:
- TBS (Transport Block Size): Enter an integer (e.g. 40 or 1000). Changing TBS triggers Generate H to compute Zc and iLS and to auto-fill the Transport Block Bits textarea with exactly 10×Zc bits (systematic capacity). Click Generate H manually to refresh after editing TBS.
- iLS and Zc: You can override the auto choice. iLS (0–7) selects the shift column in the 3GPP table; Zc is populated from the selected set. Changing either updates the Base Graph, H-matrix, and the TB bits field (10×Zc length).
- Base Graph grid (left): Each cell shows the shift value for the current iLS, or is empty. Hover a cell to highlight the corresponding Zc×Zc block in the H-matrix. Click a cell to open a popup with the circulant matrix for that block.
- H-Matrix canvas (right): Renders the full sparse matrix: black = 1, white = 0. Size is (42·Zc)×(52·Zc). For large Zc, pixels are scaled to fit.
- Codeword Generator: Transport Block Bits holds 10×Zc systematic bits (label shows current/max). It is auto-filled when TBS or Zc changes. If you type more than 10×Zc bits, the value is truncated when you click Generate Codeword. Generate Codeword (s, p) builds the full codeword c and displays it in the Bit Viewer (Block 0–51, Zc bits per row; Blocks 0–9 = systematic, 10–51 = parity). Click a bit to flip it; validity updates in real time.
- Validity Check: The panel below the button shows H·cT = z: syndrome weight, failed row indices (if any), and a pass/fail summary. Status bar shows VALID (Syndrome = 0) or INVALID.
- Impairment Injection: Inject 1-Bit Error or Inject Burst Error flips random bits; Apply LDPC Correction re-encodes from the current TB bits to restore a valid codeword.
Tips: Start with a small TBS (e.g. 40) for a small Zc and readable H-matrix and bit viewer. The pipeline is: Input → Zc/iLS → Base Graph → H-Matrix → Codeword → Verification (H·cT).
Parameters
- TBS: Transport Block Size in bits. With Generate H, computes Zc and iLS and draws the H-matrix. Changing TBS also triggers TB bits auto-fill to 10×Zc.
- iLS (Set index): 0–7. Selects the 3GPP shift column. Changing it updates the Base Graph, H-matrix, and TB bits length.
- Zc (Lifting size): From the current iLS set. Sets circulant size and H dimensions; changing Zc auto-fills TB bits to 10×Zc and regenerates the codeword.
- Generate H: From TBS, computes Ktarget = TBS + 24, picks smallest Zc with Kb·Zc ≥ Ktarget, updates iLS/Zc, draws Base Graph and H-matrix, then syncs TB bits and generates the codeword.
- Transport Block Bits: Binary 0/1 string of length 10×Zc (systematic). Label shows (current / max) bits; input exceeding max is truncated on Generate Codeword.
Limitations
- Construction & verification, not decoding. The tool builds H, encodes a codeword, and checks the syndrome H·cT. It does not run an actual LDPC decoder (belief propagation / min-sum) — "Apply LDPC Correction" simply re-encodes from the known systematic bits.
- Base Graph 2 only. Only 5G NR BG2 (42×52, Kb = 10) is shown; Base Graph 1 (used for larger blocks / higher rates) and its different lifting structure are out of scope.
- No rate matching or channel. There is no puncturing of the first 2Zc systematic columns, bit selection, interleaving, or modulation/AWGN — this is the bare parity-check structure, not the full 5G transmit chain (see [[ldpcratematch]] for rate matching).
- Hard-bit, noiseless flips. Impairment injection flips bits deterministically; there is no soft information (LLRs) or realistic noise model, so it cannot illustrate iterative error correction.
- Display-limited size. Large Zc produces an (42·Zc)×(52·Zc) matrix scaled to fit an 800 px canvas, so individual bits become sub-pixel and the bit viewer is best used with small TBS.
- Approximate set selection. Ktarget ≈ TBS + 24 assumes a single 24-bit CRC and ignores code-block segmentation that the real 5G spec applies for large transport blocks.