Frequency (pmrf.Frequency)
- class pmrf.Frequency(start: float = 0, stop: float = 0, npoints: int = 0, unit: FrequencyUnitT | None = 'Hz')
Bases:
ModuleA frequency axis used to evaluate models over.
This class provides a container for a frequency band, defining the points at which network parameters are evaluated. The source code has been ported from the scikit-rf Frequency class but modified for JAX compatibility.
The primary purpose is to hold a vector of frequency points (f) and the corresponding frequency unit (unit). It provides numerous properties for accessing different representations of the frequency axis, such as angular frequency (w) and scaled frequency (f_scaled).
Examples
import pmrf as prf import skrf as rf # Create a frequency axis from 1 to 2 GHz with 101 points freq = prf.Frequency(start=1, stop=2, npoints=101, unit='ghz') # Access properties like the frequency vector in Hz or radians/sec print(f"Frequency points in Hz: {freq.f[:5]}...") print(f"Angular frequency in rad/s: {freq.w[:5]}...") # Convert to a scikit-rf Frequency object skrf_freq = freq.to_skrf() print(f"Type after conversion: {type(skrf_freq)}") # Create from a scikit-rf Frequency object freq_from_skrf = prf.Frequency.from_skrf(skrf_freq)
Frequency initializer.
Creates a Frequency object from start/stop/npoints and a unit. Alternatively, the class method
from_f()can be used to create a Frequency object from a frequency vector instead.- Parameters:
start (number, optional) – Start frequency in units of unit. Default is 0.
stop (number, optional) – Stop frequency in units of unit. Default is 0.
npoints (int, optional) – Number of points in the band. Default is 0.
unit (string, optional) – Frequency unit of the band: ‘Hz’, ‘kHz’, ‘MHz’, ‘GHz’, ‘THz’. This is used to create the attribute
f_scaled. It is also used by theNetworkclass for plots vs. frequency. Default is ‘Hz’.
Notes
The attribute unit sets the frequency multiplier, which is used to scale the frequency when f_scaled is referenced.
The attribute unit is not case sensitive. Hence, for example, ‘GHz’ or ‘ghz’ is the same.
See also
Examples
>>> wr1p5band = Frequency(start=500, stop=750, npoints=401, unit='ghz') >>> logband = Frequency(1, 1e9, 301, sweep_type='log')
- classmethod from_f(f_scaled: Array | ndarray | bool | number | bool | int | float | complex, unit: Literal['Hz', 'kHz', 'MHz', 'GHz', 'THz'] | None = None) Frequency
Construct Frequency object from a frequency vector.
The unit is set by kwarg ‘unit’.
- Parameters:
f_scaled (scalar or array-like) – Frequency vector in the units of unit.
unit (FrequencyUnitT, optional) – Frequency unit of the band. Default is None (defaults to ‘Hz’).
- Returns:
The instantiated Frequency object.
- Return type:
Examples
>>> f = np.linspace(75,100,101) >>> rf.Frequency.from_f(f, unit='GHz')
- static from_skrf(skrf_frequency, *, unit=None) Frequency
Create a from pmrf.frequency.Frequency from a skrf.Frequency object.
- Parameters:
skrf_frequency (skrf.Frequency) – The scikit-rf Frequency object.
- Returns:
The equivalent pmrf Frequency object.
- Return type:
- __add__(other: Frequency | Array | ndarray | bool | number | bool | int | float | complex) Frequency
Elementwise addition on frequency values.
- __div__(other: Frequency | Array | ndarray | bool | number | bool | int | float | complex) Frequency
Elementwise division on frequency values (Python 2 style alias).
- __floordiv__(other: Frequency | Array | ndarray | bool | number | bool | int | float | complex) Frequency
Elementwise floor division on frequency values.
- __getitem__(key: str | int | slice) Frequency
Slices a Frequency object based on an index, or human readable string.
- Parameters:
key (str, int, or slice) – if int, then it is interpreted as the index of the frequency if str, then should be like ‘50.1-75.5ghz’, or just ‘50’. If the frequency unit is omitted then
unitis used.
Examples
>>> b = rf.Frequency(50, 100, 101, 'ghz') >>> a = b['80-90ghz'] >>> a.plot_s_db()
- __len__() int
Return the number of frequency points.
- Returns:
Length of the frequency vector.
- Return type:
int
- __mod__(other: Frequency | Array | ndarray | bool | number | bool | int | float | complex) Frequency
Elementwise modulo on frequency values.
- __mul__(other: Frequency | Array | ndarray | bool | number | bool | int | float | complex) Frequency
Elementwise multiplication on frequency values.
- __rmul__(other: Frequency | Array | ndarray | bool | number | bool | int | float | complex) Frequency
Reflected elementwise multiplication on frequency values.
- __sub__(other: Frequency | Array | ndarray | bool | number | bool | int | float | complex) Frequency
Elementwise subtraction on frequency values.
- __truediv__(other: Frequency | Array | ndarray | bool | number | bool | int | float | complex) Frequency
Elementwise true division on frequency values.
- to_skrf()
Convert this from pmrf.frequency.Frequency object to a skrf.Frequency object.
- Returns:
The equivalent scikit-rf Frequency object.
- Return type:
skrf.Frequency
- property center: float
The center frequency in Hz.
- Returns:
The exact center frequency in Hz.
- Return type:
float
- property center_idx: int
The index of the frequency point closest to the center.
- Returns:
Index of the center frequency.
- Return type:
int
- property center_scaled: float
The center frequency in the specified unit.
- Returns:
The exact center frequency in the specified unit.
- Return type:
float
- property df: Array
The gradient of the frequency vector, in Hz.
- Returns:
Gradient of frequency.
- Return type:
jnp.ndarray
- property df_scaled: Array
The gradient of the scaled frequency vector.
- Returns:
Gradient of scaled frequency.
- Return type:
jnp.ndarray
- property dw: Array
The gradient of the angular frequency vector, in rad/s.
- Returns:
Gradient of angular frequency.
- Return type:
jnp.ndarray
- f: array
The frequency vector in Hz.
- property f_scaled: Array
The frequency vector in the specified unit.
- Returns:
A frequency vector in the specified unit.
- Return type:
jnp.ndarray
- property multiplier: float
The multiplier to convert from the specified unit back to Hz.
- Returns:
Multiplier for this frequency’s unit.
- Return type:
float
- property npoints: int
The number of points in the frequency axis.
- Returns:
Number of points.
- Return type:
int
- property span: float
The frequency span (stop - start) in Hz.
- Returns:
Span in Hz.
- Return type:
float
- property span_scaled: float
The frequency span (stop - start) in the specified unit.
- Returns:
Span in units.
- Return type:
float
- property start: float
The starting frequency in Hz.
- Returns:
Start frequency.
- Return type:
float
- property start_scaled: float
The starting frequency in the specified unit.
- Returns:
Scaled start frequency.
- Return type:
float
- property step: float
The frequency step size in Hz for evenly spaced sweeps.
- Returns:
Step size in Hz.
- Return type:
float
- property step_scaled: float
The frequency step size in the specified unit for evenly spaced sweeps.
- Returns:
Step size in units.
- Return type:
float
- property stop: float
The stop frequency in Hz.
- Returns:
Stop frequency.
- Return type:
float
- property stop_scaled: float
The stop frequency in the specified unit.
- Returns:
Scaled stop frequency.
- Return type:
float
- unit: str
The frequency unit. Possible options are “Hz”, “kHz”, “MHz”, “GHz” or “THz”.
- property w: Array
The angular frequency vector in radians/s.
Angular frequency is defined as \(\omega=2\pi f\).
- Returns:
Angular frequency in rad/s.
- Return type:
jnp.ndarray