utils#

Various convenient utility functions.

qampy.core.utils.bin2gray(value)#

Convert a binary value to an gray coded value see _[1]. This also works for arrays. ..[1] https://en.wikipedia.org/wiki/Gray_code#Constructing_an_n-bit_Gray_code

qampy.core.utils.bool2bin(x)#

Convert an array of boolean values into a binary number. If the input array is not a array of booleans it will be converted.

qampy.core.utils.convert_iqtosinglebitstream(idat, qdat, nbits)#

Interleave a two bitstreams into a single bitstream with nbits per symbol. This can be used to create a combined PRBS signal from 2 PRBS sequences for I and Q channel. If nbits is odd we will use nbits//2 + 1 bits from the first stream and nbits//2 from the second.

Parameters:
  • idat (array_like) – input data stream (1D array of booleans)

  • qdat (array_like) – input data stream (1D array of booleans)

  • nbits (int) – number of bits per symbol that we want after interleaving

Returns:

output – interleaved bit stream

Return type:

array_like

qampy.core.utils.factorial(n)#

The factorial of n, i.e. n!

qampy.core.utils.find_offset(sequence, data)#

Find index where binary sequence occurs fist in the binary data array

Parameters:
  • sequence (It is required that len(data) >) – sequence to search for inside the data

  • data (array_like) – data array in which to find the sequence

  • sequence

Returns:

idx – index where sequence first occurs in data

Return type:

int

qampy.core.utils.lfsr_ext(seed, taps, nbits)#

A Fibonacci or external XOR linear feedback shift register.

Parameters:
  • seed (int) – binary number denoting the input state registers

  • taps (list) – list of registers that are input to the XOR (length 2)

  • nbits (int) – number of registers

Yields:
  • xor (int) – output bit of the registers

  • state (int) – state of the register

qampy.core.utils.lfsr_int(seed, mask)#

A linear feedback shift register, using Galois or internal XOR implementation.

Parameters:
  • seed (int) – an integer representing the list of bits as the starting point of the register. Length N

  • mask (int) – Determines the polynomial of the shift register (length N+1). The first and last bit of the mask must be 1.

Yields:
  • xor (int) – output bit of the register

  • state (int) – state of the register

qampy.core.utils.linspacestep(start, step, N)#

Create an array of given length for a given start and step value.

Parameters:
  • start (float) – first value to start with

  • step (float) – size of the step

  • N (int) – number of steps

Returns:

out – array of length N from start to start+N*step (not included)

Return type:

array_like

qampy.core.utils.rolling_window(data, size, wrap=False)#

Reshapes a 1D array into a 2D array with overlapping frames. Stops when the last value of data is reached.

Parameters:
  • data (array_like) – Data array to segment

  • size (int) – The frame size

Returns:

out – output segmented 2D array

Return type:

array_like

Examples >>> utils.rolling_window(np.arange(10), 3) array([[0, 1, 2],

[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9]])