Utilities
Signal processing and unit conversion utilities.
Miscellaneous helpers: dB/linear conversions, phase wrapping to (−π, π], replacing zeros with the smallest float, and other small signal utilities used across the library.
db2power(db)
Converts power from decibels (dB) to watts.
The conversion is calculated as 10**(db / 10).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
float
|
Power in decibels (dB). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Power in watts (W). |
Source code in src/rad_lab/utilities.py
26 27 28 29 30 31 32 33 34 35 36 37 | |
db2volt(db)
Converts a decibel (dB) value to a voltage or amplitude ratio.
The conversion is calculated as 10**(db / 20).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
float
|
A value in decibels (dB). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The corresponding voltage or amplitude ratio (unitless). |
Source code in src/rad_lab/utilities.py
55 56 57 58 59 60 61 62 63 64 65 66 | |
phase_negpi_pospi(phase)
Wraps phase angles to the interval [-pi, pi).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase
|
float or array - like
|
Phase angle(s) in radians. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Phase angle(s) wrapped to the [-pi, pi) interval. |
Source code in src/rad_lab/utilities.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
phase_zero_twopi(phase)
Wraps phase angles to the interval [0, 2*pi).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase
|
float or array - like
|
Phase angle(s) in radians. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Phase angle(s) wrapped to the [0, 2*pi) interval. |
Source code in src/rad_lab/utilities.py
85 86 87 88 89 90 91 92 93 94 95 96 | |
power2db(power)
Converts power from watts to decibels (dB).
The conversion is calculated as 10 * log10(power).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
power
|
float
|
Power in watts (W). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Power in decibels (dB). |
Source code in src/rad_lab/utilities.py
12 13 14 15 16 17 18 19 20 21 22 23 | |
volt2db(voltage)
Converts a voltage or amplitude ratio to decibels (dB).
The conversion is calculated as 20 * log10(voltage). This is typically used for field quantities like voltage or pressure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voltage
|
float
|
Voltage or amplitude ratio (unitless). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The corresponding value in decibels (dB). |
Source code in src/rad_lab/utilities.py
40 41 42 43 44 45 46 47 48 49 50 51 52 | |
zero_to_smallest_float(array, value=1e-16)
Replaces all zero elements in a NumPy array with a small float value.
This operation is performed in-place. It is often used to avoid division-by-zero errors or issues with taking logarithms of zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
The input array to modify. |
required |
value
|
float
|
The small value to substitute for zeros. Defaults to 1e-16. |
1e-16
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
The array is modified in-place. |
Source code in src/rad_lab/utilities.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |