Web Simulation 

 

 

 

 

5G NR Gold Sequence Scrambling Tutorial 

This interactive tutorial visualizes the 5G NR Gold Sequence Scrambling Generator defined in 3GPP TS 38.211. The generator produces a pseudo-random binary sequence c(n) used for scrambling (e.g. PDSCH, PDCCH). It is built from two 31-bit Linear Feedback Shift Registers (LFSRs) whose outputs are combined with XOR. Despite looking like "random" bit-shifting, it is a deterministic process: the same c_init (initialization value) always yields the same sequence, so the receiver can recreate it exactly.

 

Mathematical foundation

1. M-Sequence x1

First LFSR: x1(n+31) = (x1(n+3) + x1(n)) mod 2. In hardware: the register shifts left; the new bit (feedback) is the XOR of tap positions 0 and 3. Initial state: x1(0)=1, all others 0. This is a fixed maximal-length (m-) sequence.

2. M-Sequence x2

Second LFSR: x2(n+31) = (x2(n+3) + x2(n+2) + x2(n+1) + x2(n)) mod 2. Taps at positions 0, 1, 2, 3. Initial state is set from the 31-bit value c_init (e.g. derived from RNTI, Cell ID, etc.).

3. Output c(n)

c(n) = (x1(n) + x2(n)) mod 2, i.e. XOR of the two output bits. The composite sequence is a Gold sequence: deterministic, long period, and good correlation properties for scrambling.

4. Nc offset (warm-up)

Per 3GPP, the generator performs Nc = 1600 shifts before the first output bit c(0) is used. This discards the initial "simple" bits so the scrambling sequence appears highly random from the first bit used in the radio frame. Use Start from n=Nc (default) so Initialize runs the warm-up; Start from n=0 skips it for teaching.

5. c_init for PDSCH (example)

For PDSCH scrambling, 38.211 defines c_init = n_RNTI · 215 + q · 214 + n_ID, where n_RNTI is the RNTI, q is the codeword index, and n_ID is the data scrambling identity. Changing c_init (e.g. by Cell ID or RNTI) completely changes the resulting sequence, so each user/cell gets a unique scrambling pattern.

Start
1
Status: —

Gold Sequence Formulas (3GPP TS 38.211)

FormulaPlugged in (Current State)
c(n) = (x₁(n+Nc) + x₂(n+Nc)) mod 2 --
x₁(n+31) = (x₁(n+3) + x₁(n)) mod 2 --
x₂(n+31) = (x₂(n+3) + x₂(n+2) + x₂(n+1) + x₂(n)) mod 2 --
M-Sequence x1 (fixed taps: 0, 3) — bit 0 = output
0
0
M-Sequence x2 (taps: 0, 1, 2, 3 — from C_init)
Generated scrambling sequence c(n) — newest left

Mathematical Trace

cinit = nRNTI·215 + q·214 + nID
ParameterDescriptionCurrent value
nRNTIRadio Network Temporary Identifier1
qCodeword index (0 or 1)0
nIDScrambling identity (data-scrambling or Cell ID)0
Plugged in: (1 × 32768) + (0 × 16384) + 0
Result: 32768 (decimal)
Binary: bit 15 is HIGH → x2[15] = 1 in the register.

 

Usage

Use this simulation to explore the 5G NR Gold Sequence generator (TS 38.211):

  1. Scenario: Choose PDSCH to compute c_init from n_RNTI, q, and n_ID (formula above). Use Apply → C_init to update the C_init field and re-initialize. PDCCH and Custom use the C_init value you enter directly.
  2. C_init: 31-bit initialization for x2. Enter a decimal value (0–231−1). Changing it completely changes the output sequence.
  3. Start: Start from n=0 skips warm-up; Start from n=Nc (default) performs 1600 shifts before the first output c(0) per 3GPP.
  4. Initialize: Sets x1(0)=1, loads x2 from C_init, and (if Start from n=Nc) runs 1600 warm-up shifts so the first Step produces c(0).
  5. Speed: Animation speed slider (0.1–2, default 1). Higher = faster steps when Run is active.
  6. Step: Performs one shift of both LFSRs and appends one output bit c(n) to the stream. Stops Run if it is active.
  7. Run / Stop: Run generates bits continuously at the current Speed. Click again (or Step) to stop.
  8. Registers: Two rows of 31 cells. Index 0 (left) is the output bit; tap positions (x1: 0,3; x2: 0,1,2,3) have a magenta border. Feedback XOR result boxes sit to the right of each feedback gate. Pink lines: taps → feedback gates; gate → result box.
  9. Bit stream: Generated c(n) bits; newest on the left.

Tips: Start with C_init=1024 and click Initialize, then Step a few times to see the registers shift and c(n) appear. Try PDSCH with different n_RNTI or n_ID to see how the sequence changes. Enable Skip warm-up to observe the effect of the Nc offset.

Parameters

  • n_RNTI: Radio Network Temporary Identifier (e.g. C-RNTI). Used in PDSCH c_init formula.
  • q: Codeword index (0 or 1 for dual codeword). Used in PDSCH c_init.
  • n_ID: Data scrambling identity (e.g. cell ID or configurable). Used in PDSCH c_init.
  • C_init: 31-bit initial value for the x2 register. Determines the entire Gold sequence.
  • Nc: Number of initial shifts (1600) before first output; per 3GPP 38.211.