comnum.Scrambler#

class comnum.Scrambler(c_init)#

The Gold scrambler of 3GPP (TS 38.211, Sec. 5.2.1).

Parameters:

c_init (int) – the initial value of the second register.

Examples

>>> import comnum, numpy as np
>>> s = comnum.Scrambler(0x1234)
>>> b = np.array([1, 0, 1, 1], dtype=np.uint8)
>>> s.scramble(s.scramble(b)).tolist()
[1, 0, 1, 1]
descramble_llr(llr)#

Descramble LLRs (flip the signs where the sequence is 1).

Parameters:

llr (array_like) – the LLRs of scrambled bits.

Returns:

the LLRs of the bits (float64).

Return type:

numpy.ndarray

Raises:

ValueError – for an input that is not an array of numbers of the expected shape.

scramble(bits)#

Scramble (or descramble) bits.

Parameters:

bits (array_like) – the bits.

Returns:

the bits XOR the sequence (uint8).

Return type:

numpy.ndarray

Raises:

ValueError – for bits that are not 0 or 1, or not a 1-D array.

sequence(n)#

The first bits of the sequence.

Parameters:

n (int) – number of bits.

Returns:

n bits (uint8).

Return type:

numpy.ndarray

Raises:

ValueError – for a negative count.