comnum.Interleaver#

class comnum.Interleaver#

A permutation of the positions of a block: Interleaver.random(n, seed=…), Interleaver.block(rows, cols) or Interleaver.qpp(k, f1, f2). It permutes any array and keeps its dtype (bits, LLRs, symbols).

Examples

>>> import comnum, numpy as np
>>> il = comnum.Interleaver.block(2, 3)
>>> il.interleave(np.arange(6)).tolist()
[0, 3, 1, 4, 2, 5]
>>> il.deinterleave(il.interleave(np.arange(6))).tolist()
[0, 1, 2, 3, 4, 5]
static block(rows, cols)#

Write row by row, read column by column.

Parameters:
  • rows (int) – rows of the array.

  • cols (int) – columns of the array.

Returns:

the interleaver of rows · cols positions.

Return type:

Interleaver

static qpp(k, f1, f2)#

The quadratic permutation polynomial (f1 i + f2 i²) mod k.

Parameters:
  • k (int) – the block length.

  • f1 (int) – the linear coefficient.

  • f2 (int) – the quadratic coefficient.

Returns:

the interleaver.

Return type:

Interleaver

Raises:

ValueError – if the polynomial is not a permutation.

static random(n, *, seed=0)#

A uniform random permutation.

Parameters:
  • n (int) – the block length.

  • seed (int) – the seed of the permutation.

Returns:

the interleaver.

Return type:

Interleaver

Raises:

ValueError – for a negative count.

Examples

>>> import comnum
>>> il = comnum.Interleaver.random(8, seed=1)
>>> sorted(il.perm.tolist()) == list(range(8))
True
deinterleave(y)#

The inverse permutation: x[perm[i]] = y[i].

Parameters:

y (array_like) – one interleaved block of any dtype.

Returns:

the block in its original order, of the dtype of y.

Return type:

numpy.ndarray

Raises:

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

interleave(x)#

Interleave a block: y[i] = x[perm[i]].

Parameters:

x (array_like) – one block of any dtype (bits, LLRs, symbols).

Returns:

the permuted block, of the dtype of x.

Return type:

numpy.ndarray

Raises:

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

n#

The block length.

Type:

int

perm#

output i is input perm[i].

Type:

numpy.ndarray

Type:

The permutation (int64)