General Utilities

General utilities (optic.utils)

parameters()

Basic class to be used as a struct of parameters

lin2dB(x)

Convert linear value to dB (decibels).

dB2lin(x)

Convert dB (decibels) to a linear value.

dBm2W(x)

Convert dBm to Watts.

dec2bitarray(x, bit_width)

Converts a positive integer or an array-like of positive integers to a NumPy array of the specified size containing bits (0 and 1).

decimal2bitarray(x, bit_width)

Converts a positive integer to a NumPy array of the specified size containing bits (0 and 1).

dotNumba(a, b)

Computes the dot product of two 1D arrays in a Numba-compatible way.

bitarray2dec(x_bitarray)

Converts an input NumPy array of bits (0 and 1) to a decimal integer.

ber2Qfactor(ber)

Converts a bit error rate (BER) to a Q factor in dB.

ber2Qfactor(ber)

Converts a bit error rate (BER) to a Q factor in dB.

Parameters:

ber (float) – The bit error rate to be converted.

Returns:

The Q factor corresponding to the input BER.

Return type:

float

bitarray2dec(x_bitarray)

Converts an input NumPy array of bits (0 and 1) to a decimal integer.

Parameters:

x_bitarray (1D array of int) – Input NumPy array of bits.

Returns:

number – Integer representation(s) of the input bit array(s).

Return type:

int or array of int

dB2lin(x)

Convert dB (decibels) to a linear value.

Parameters:

x (float) – The value in dB to be converted to a linear value.

Returns:

The linear value.

Return type:

float

dBm2W(x)

Convert dBm to Watts.

Parameters:

x (float) – The power value in dBm to be converted to Watts.

Returns:

The power value in Watts.

Return type:

float

dec2bitarray(x, bit_width)

Converts a positive integer or an array-like of positive integers to a NumPy array of the specified size containing bits (0 and 1).

Parameters:
  • x (int or array-like of int) – Positive integer(s) to be converted to a bit array.

  • bit_width (int) – Size of the output bit array.

Returns:

bitarray – Array containing the binary representation of all the input decimal(s).

Return type:

2D NumPy array of int

decimal2bitarray(x, bit_width)

Converts a positive integer to a NumPy array of the specified size containing bits (0 and 1). This version is slightly quicker but only works for one integer.

Parameters:
  • x (int) – Positive integer to be converted to a bit array.

  • bit_width (int) – Size of the output bit array.

Returns:

bitarray – Array containing the binary representation of the input decimal.

Return type:

1D NumPy array of int

dotNumba(a, b)

Computes the dot product of two 1D arrays in a Numba-compatible way.

This function is equivalent to np.dot for 1D arrays but can be JIT-compiled with Numba for accelerated execution.

Parameters:
  • a (ndarray of shape (N,)) – First input array (complex-valued).

  • b (ndarray of shape (N,)) – Second input array (complex-valued).

Returns:

result – The dot product of a and b, computed as the sum of element-wise products.

Return type:

complex

Notes

  • Both input arrays must have the same length.

  • This function initializes the result as a complex number to support complex-valued operations.

lin2dB(x)

Convert linear value to dB (decibels).

Parameters:

x (float) – The linear value to be converted to dB.

Returns:

The value converted to dB, i.e 10log10(x).

Return type:

float

class parameters

Basic class to be used as a struct of parameters

copy()

Returns a deep copy of the parameters object.

This method creates a new instance of the parameters class with the same attributes and values.

Returns:

A new instance of the parameters class with copied attributes.

Return type:

parameters

latex_table()

Generates a LaTeX table of the parameters and their values.

Returns:

A LaTeX table representation of the parameters and their values.

Return type:

str

table()

Generates a Markdown table of the parameters and their values.

Returns:

A Markdown table representation of the parameters and their values.

Return type:

str

to_engineering_notation(value)

Converts a numerical value to engineering notation with appropriate prefixes.

Parameters:

value (int or float) – The numerical value to be converted.

Returns:

The value formatted in engineering notation with a prefix, or the original value if it does not meet the criteria.

Return type:

str or value

view()

Prints the attributes and their values in either standard or scientific notation.