pmrf.functions.math

Functions

comb(N, k[, exact, repetition])

The number of combinations of N things taken k at a time.

complex2Scalar(z)

Serialize a list/array of complex numbers

complex_2_db(z)

Return the magnitude in dB of a complex number (as \(20\log_{10}(|z|)\))..

complex_2_db10(z)

Return the magnitude in dB of a complex number (as \(10\log_{10}(|z|)\)).

complex_2_degree(z)

Returns the angle complex argument in degree.

complex_2_magnitude(z)

Return the magnitude of the complex argument.

complex_2_quadrature(z)

Take a complex number and returns quadrature, which is (length, arc-length from real axis)

complex_2_radian(z)

Return the angle complex argument in radian.

complex_2_reim(z)

Return real and imaginary parts of a complex number.

complex_components(z)

Break up a complex array into all possible scalar components.

complexify(f[, name])

Make a function f(scalar) into f(complex).

conv_cost(x)

conv_inter(x[, axis])

convolve_interleaved(x[, axis])

cross_ratio(a, b, c, d)

Calculate the cross ratio of a quadruple of distinct points on the real line.

dB20(x)

db10_2_mag(z)

Convert dB to linear magnitude.

db_2_mag(x)

db_2_magnitude(z)

Convert dB to linear magnitude.

db_2_np(db)

Converts a value in decibel (dB) to neper (Np).

db_per_100feet_2_db_per_100meter([...])

Convert attenuation values given in dB/100ft to dB/100m.

dbdeg_2_reim(db, deg)

Converts dB magnitude and phase (in deg) arrays into a complex array.

degree_2_radian(deg)

Convert angles from degrees to radians.

dirac_delta(x)

Calculate Dirac function.

evaluate_bernstein_basis(x, coeffs, ...)

evaluate_power_basis(x, coeffs, lower_bound, ...)

feet_2_meter([feet])

Convert length in feet to meter.

find_closest(z1, z2, z_approx)

Return z1 or z2 depending on which is closer to z_approx.

find_correct_sign(z1, z2, z_approx)

Create new vector from z1, z2 choosing elements with sign matching z_approx.

inf_to_num(x)

Convert inf and -inf's to large numbers.

mag_2_db(x)

mag_2_db10(z[, zero_nan])

Convert linear magnitude to dB.

magdeg_2_reim(mag, deg)

Convert linear magnitude and phase (in deg) arrays into a complex array.

magnitude_2_db(z[, zero_nan])

Convert linear magnitude to dB.

meter_2_feet([meter])

Convert length in meter to feet.

multiply_by(x, by[, axis])

multiply_every(x, n[, axis])

neuman(x)

Calculate Neumans number.

np_2_db(x)

Converts a value in Nepers (Np) to decibel (dB).

null(A[, eps])

Calculate the null space of matrix A.

polar_2_rect(radii, angles[, deg])

radian_2_degree(rad)

Convert angles from radians to degrees.

rect_2_polar(x[, deg])

rms(x)

round_sig(x[, sig])

scalar2Complex(s)

Unserialize a list/array of real and imag numbers into a complex array.

sqrt_known_sign(z_squared, z_approx)

Return the square root of a complex number, with sign chosen to match z_approx.

sqrt_phase_unwrap(z)

Take the square root of a complex number with unwrapped phase.

sum_every(x, n[, axis])

unwrap_rad(phi)

Unwraps a phase given in radians.

pmrf.functions.math.complex_2_magnitude(z)[source]

Return the magnitude of the complex argument.

Parameters:

z (number or array_like) – A complex number or sequence of complex numbers

Returns:

mag

Return type:

ndarray or scalar

pmrf.functions.math.complex_2_db(z)[source]

Return the magnitude in dB of a complex number (as \(20\log_{10}(|z|)\))..

The magnitude in dB is defined as \(20\log_{10}(|z|)\) where \(z\) is a complex number.

Parameters:

z (number or array_like) – A complex number or sequence of complex numbers

Returns:

mag20dB

Return type:

ndarray or scalar

pmrf.functions.math.complex_2_db10(z)[source]

Return the magnitude in dB of a complex number (as \(10\log_{10}(|z|)\)).

The magnitude in dB is defined as \(10\log_{10}(|z|)\) where \(z\) is a complex number.

Parameters:

z (number or array_like) – A complex number or sequence of complex numbers

Returns:

mag10dB

Return type:

ndarray or scalar

pmrf.functions.math.complex_2_radian(z)[source]

Return the angle complex argument in radian.

Parameters:

z (number or array_like) – A complex number or sequence of complex numbers

Returns:

ang_rad – The counterclockwise angle from the positive real axis on the complex plane in the range (-pi, pi], with dtype as numpy.float64.

Return type:

ndarray or scalar

pmrf.functions.math.complex_2_degree(z)[source]

Returns the angle complex argument in degree.

Parameters:

z (number or array_like) – A complex number or sequence of complex numbers

Returns:

ang_deg

Return type:

ndarray or scalar

pmrf.functions.math.complex_2_quadrature(z)[source]

Take a complex number and returns quadrature, which is (length, arc-length from real axis)

Arc-length is calculated as \(|z| \arg(z)\).

Parameters:

z (number or array_like) – A complex number or sequence of complex numbers

Returns:

  • mag (array like or scalar) – magnitude (length)

  • arc_length (array like or scalar) – arc-length from real axis: angle*magnitude

pmrf.functions.math.complex_2_reim(z)[source]

Return real and imaginary parts of a complex number.

Parameters:

z (number or array_like) – A complex number or sequence of complex numbers

Returns:

  • real (array like or scalar) – real part of input

  • imag (array like or scalar) – imaginary part of input

pmrf.functions.math.complex_components(z)[source]

Break up a complex array into all possible scalar components.

Parameters:

z (number or array_like) – A complex number or sequence of complex numbers

Returns:

  • c_real (array like or scalar) – real part

  • c_imag (array like or scalar) – imaginary part

  • c_angle (array like or scalar) – angle in degrees

  • c_mag (array like or scalar) – magnitude

  • c_arc (array like or scalar) – arclength from real axis, angle*magnitude

pmrf.functions.math.magnitude_2_db(z, zero_nan=True)[source]

Convert linear magnitude to dB.

Parameters:
  • z (number or array_like) – A complex number or sequence of complex numbers

  • zero_nan (bool, optional) – Replace NaN with zero. The default is True.

Returns:

z – Magnitude in dB given by 20*log10(|z|)

Return type:

number or array_like

pmrf.functions.math.mag_2_db10(z, zero_nan=True)[source]

Convert linear magnitude to dB.

Parameters:
  • z (array_like) – A complex number or sequence of complex numbers

  • zero_nan (bool, optional) – Replace NaN with zero. The default is True.

Returns:

z – Magnitude in dB given by 10*log10(|z|)

Return type:

array_like

pmrf.functions.math.db_2_magnitude(z)[source]

Convert dB to linear magnitude.

Parameters:

z (number or array_like) – A complex number or sequence of complex numbers

Returns:

z – 10**((z)/20) where z is a complex number

Return type:

number or array_like

pmrf.functions.math.db10_2_mag(z)[source]

Convert dB to linear magnitude.

Parameters:

z (array_like) – A complex number or sequence of complex numbers

Returns:

z – 10**((z)/10) where z is a complex number

Return type:

array_like

pmrf.functions.math.magdeg_2_reim(mag, deg)[source]

Convert linear magnitude and phase (in deg) arrays into a complex array.

Parameters:
  • mag (number or array_like) – A complex number or sequence of real numbers

  • deg (number or array_like) – A complex number or sequence of real numbers

Returns:

z – A complex number or sequence of complex numbers

Return type:

array_like

pmrf.functions.math.dbdeg_2_reim(db, deg)[source]

Converts dB magnitude and phase (in deg) arrays into a complex array.

Parameters:
  • db (number or array_like) – A realnumber or sequence of real numbers

  • deg (number or array_like) – A real number or sequence of real numbers

Returns:

z – A complex number or sequence of complex numbers

Return type:

array_like

pmrf.functions.math.db_2_np(db)[source]

Converts a value in decibel (dB) to neper (Np).

Parameters:

db (number or array_like) – A real number or sequence of real numbers

Returns:

np – A real number of sequence of real numbers

Return type:

number or array_like

pmrf.functions.math.np_2_db(x)[source]

Converts a value in Nepers (Np) to decibel (dB).

Parameters:
  • np (number or array_like) – A real number or sequence of real numbers

  • x (Number | Sequence[Number] | Array)

Returns:

db – A real number of sequence of real numbers

Return type:

number or array_like

pmrf.functions.math.radian_2_degree(rad)[source]

Convert angles from radians to degrees.

Parameters:

rad (number or array_like) – Angle in radian

Returns:

deg – Angle in degree

Return type:

number or array_like

pmrf.functions.math.degree_2_radian(deg)[source]

Convert angles from degrees to radians.

Parameters:

deg (number or array_like) – Angle in radian

Returns:

rad – Angle in degree

Return type:

number or array_like

pmrf.functions.math.feet_2_meter(feet=1)[source]

Convert length in feet to meter.

1 foot is equal to 0.3048 meters.

Parameters:

feet (number or array-like, optional) – length in feet. Default is 1.

Returns:

meter – length in meter

Return type:

number or array-like

See also

meter_2_feet

pmrf.functions.math.meter_2_feet(meter=1)[source]

Convert length in meter to feet.

1 meter is equal to 0.3.28084 feet.

Parameters:

meter (number or array-like, optional) – length in meter. Default is 1.

Returns:

feet – length in feet

Return type:

number or array-like

See also

feet_2_meter

pmrf.functions.math.db_per_100feet_2_db_per_100meter(db_per_100feet=1)[source]

Convert attenuation values given in dB/100ft to dB/100m.

db_per_100meter = db_per_100feet * rf.meter_2_feet()

Parameters:

db_per_100feet (number or array-like, optional) – Attenuation in dB/ 100 ft. Default is 1.

Returns:

db_per_100meter – Attenuation in dB/ 100 m

Return type:

number or array-like

pmrf.functions.math.unwrap_rad(phi)[source]

Unwraps a phase given in radians.

Parameters:

phi (number or array_like) – phase in radians

Returns:

phi – unwrapped phase in radians

Return type:

number of array_like

pmrf.functions.math.sqrt_known_sign(z_squared, z_approx)[source]

Return the square root of a complex number, with sign chosen to match z_approx.

Parameters:
  • z_squared (number or array-like) – the complex to be square-rooted

  • z_approx (number or array-like) – the approximate value of z. sign of z is chosen to match that of z_approx

Returns:

z – square root of z_squared.

Return type:

number, array-like (same type as z_squared)

pmrf.functions.math.find_correct_sign(z1, z2, z_approx)[source]

Create new vector from z1, z2 choosing elements with sign matching z_approx.

This is used when you have to make a root choice on a complex number. and you know the approximate value of the root.

\[z1,z2 = \pm \sqrt(z^2)\]
Parameters:
  • z1 (array-like) – root 1

  • z2 (array-like) – root 2

  • z_approx (array-like) – approximate answer of z

Returns:

z3 – array built from z1 and z2 by z1 where sign(z1) == sign(z_approx), z2 else

Return type:

np.array

pmrf.functions.math.find_closest(z1, z2, z_approx)[source]

Return z1 or z2 depending on which is closer to z_approx.

Parameters:
  • z1 (array-like) – root 1

  • z2 (array-like) – root 2

  • z_approx (array-like) – approximate answer of z

Returns:

z3 – array built from z1 and z2

Return type:

np.array

pmrf.functions.math.sqrt_phase_unwrap(z)[source]

Take the square root of a complex number with unwrapped phase.

This idea came from Lihan Chen.

\[\sqrt{|z|} \exp( \arg_{unwrap}(z) / 2 )\]
Parameters:

z (number or array_like) – A complex number or sequence of complex numbers

Returns:

z – A complex number or sequence of complex numbers

Return type:

number of array_like

pmrf.functions.math.dirac_delta(x)[source]

Calculate Dirac function.

Dirac function \(\delta(x)\) defined as \(\delta(x)=1\) if x=0, 0 otherwise.

Parameters:

x (number of array_like) – A real number or sequence of real numbers

Returns:

delta – 1 or 0

Return type:

number of array_like

References

https://en.wikipedia.org/wiki/Dirac_delta_function

pmrf.functions.math.neuman(x)[source]

Calculate Neumans number.

It is defined as:

\[2 - \delta(x)\]

where \(\delta\) is the Dirac function.

Parameters:

x (number or array_like) – A real number or sequence of real numbers

Returns:

y – A real number or sequence of real numbers

Return type:

number or array_like

See also

dirac_delta

pmrf.functions.math.null(A, eps=1e-15)[source]

Calculate the null space of matrix A.

Parameters:
  • A (array_like)

  • eps (float)

Returns:

null_space

Return type:

array_like

References

https://scipy-cookbook.readthedocs.io/items/RankNullspace.html https://stackoverflow.com/questions/5889142/python-numpy-scipy-finding-the-null-space-of-a-matrix

pmrf.functions.math.inf_to_num(x)[source]

Convert inf and -inf’s to large numbers.

Parameters:

x (array-like or number) – the input array or number

Returns:

x – Input without with +/- inf replaced by large numbers

Return type:

Number of array_like

pmrf.functions.math.cross_ratio(a, b, c, d)[source]

Calculate the cross ratio of a quadruple of distinct points on the real line.

The cross ratio is defined as:

\[r = \frac{ (a-b)(c-d) }{ (a-d)(c-b) }\]
Parameters:
  • a (array-like or number)

  • b (array-like or number)

  • c (array-like or number)

  • d (array-like or number)

Returns:

r

Return type:

array-like or number

References

https://en.wikipedia.org/wiki/Cross-ratio

pmrf.functions.math.complexify(f, name=None)[source]

Make a function f(scalar) into f(complex).

If f(x) then it returns f_c(z) = f(real(z)) + 1j*f(imag(z))

If the real/imag arguments are not first, then you may specify the name given to them as kwargs.

Parameters:
  • f (Callable) – function of real variable

  • name (string, optional) – name of the real/imag argument names if they are not first

Returns:

f_c – function of a complex variable

Return type:

Callable

Examples

>>> def f(x): return x
>>> f_c = rf.complexify(f)
>>> z = 0.2 -1j*0.3
>>> f_c(z)
pmrf.functions.math.complex2Scalar(z)[source]

Serialize a list/array of complex numbers

Parameters:

z (number or array_like) – A complex number or sequence of complex numbers

Returns:

re_im – produce the following array for an input z: z[0].real, z[0].imag, z[1].real, z[1].imag, etc.

Return type:

array_like

See also

scalar2Complex

pmrf.functions.math.scalar2Complex(s)[source]

Unserialize a list/array of real and imag numbers into a complex array.

Inverse of complex2Scalar().

Parameters:

s (array_like) – an array with real and imaginary parts ordered as: z[0].real, z[0].imag, z[1].real, z[1].imag, etc.

Returns:

z – A complex number or sequence of complex number

Return type:

Number or array_like

See also

complex2Scalar

pmrf.functions.math.multiply_by(x, by, axis=None)[source]
Parameters:
  • x (Array)

  • by (Array)

Return type:

Array

pmrf.functions.math.sum_every(x, n, axis=None)[source]
Parameters:
  • x (Array)

  • n (int)

Return type:

Array

pmrf.functions.math.multiply_every(x, n, axis=None)[source]
Parameters:
  • x (Array)

  • n (int)

Return type:

Array

pmrf.functions.math.convolve_interleaved(x, axis=1)[source]
Return type:

Array

pmrf.functions.math.rms(x)[source]
pmrf.functions.math.mag_2_db(x)[source]
pmrf.functions.math.db_2_mag(x)[source]
pmrf.functions.math.polar_2_rect(radii, angles, deg=False)[source]
pmrf.functions.math.rect_2_polar(x, deg=False)[source]
pmrf.functions.math.round_sig(x, sig=3)[source]
pmrf.functions.math.comb(N, k, exact=False, repetition=False)[source]

The number of combinations of N things taken k at a time.

This is often expressed as “N choose k”.

Args: N: The number of things. k: The number of elements taken. exact: If True, the result is computed exactly and returned as an integer type.

Currently, vectorization is not supported for exact=True.

repetition: If repetition is True, then the number of combinations with

repetition is computed.

Returns: The number of combinations of N things taken k at a time.

Notes: When exact=False, the result is approximately and efficiently computed using the following formula:

\[\]

begin{equation} expleft{ln{Gamma(N+1)} - [ln{Gamma(k+1)} + ln{Gamma(N+1-k)}]right} end{equation}

Where we use the Gamma function.

Parameters:
  • N (Array)

  • k (Array)

  • exact (bool)

  • repetition (bool)

pmrf.functions.math.evaluate_power_basis(x, coeffs, lower_bound, upper_bound)[source]
pmrf.functions.math.evaluate_bernstein_basis(x, coeffs, lower_bound, upper_bound)[source]
pmrf.functions.math.conv_inter(x, axis=1)
Return type:

Array

pmrf.functions.math.dB20(x)
pmrf.functions.math.conv_cost(x)