Frequency (pmrf.Frequency)

class pmrf.frequency.Frequency(start=0, stop=0, npoints=0, unit='Hz')[source]

Bases: Module

Represents a frequency axis for paramrf models.

This class provides a container for a frequency band, defining the points at which network parameters are evaluated. The source code has been derived from the scikit-rf Frequency class, but with added 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).

Parameters:
  • start (float)

  • stop (float)

  • npoints (int)

  • unit (FrequencyUnitT | None)

_f

The frequency vector in Hz.

Type:

jnp.ndarray

_unit

The frequency unit (e.g., ‘hz’, ‘ghz’). Marked as static for JAX/Equinox.

Type:

str

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)
__init__(start=0, stop=0, npoints=0, unit='Hz')[source]

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 the Network class for plots vs. frequency. Default is ‘Hz’.

Return type:

None

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

from_f

constructs a Frequency object from a frequency vector instead of start/stop/npoints.

unit

frequency unit of the band

Examples

>>> wr1p5band = Frequency(start=500, stop=750, npoints=401, unit='ghz')
>>> logband = Frequency(1, 1e9, 301, sweep_type='log')
classmethod from_f(f, unit=None)[source]

Construct Frequency object from a frequency vector.

The unit is set by kwarg ‘unit’.

Parameters:
  • f (scalar or array-like) – Frequency vector.

  • unit (FrequencyUnitT, optional) – Frequency unit of the band. Default is None (defaults to ‘Hz’).

Returns:

The instantiated Frequency object.

Return type:

Frequency

Examples

>>> f = np.linspace(75,100,101)
>>> rf.Frequency.from_f(f, unit='GHz')
static from_skrf(skrf_frequency)[source]

Create a pmrf.Frequency from a skrf.Frequency object.

Parameters:

skrf_frequency (skrf.Frequency) – The scikit-rf Frequency object.

Returns:

The equivalent pmrf Frequency object.

Return type:

Frequency

to_skrf()[source]

Convert this pmrf.Frequency object to a skrf.Frequency object.

Returns:

The equivalent scikit-rf Frequency object.

Return type:

skrf.Frequency

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 stop_scaled: float

The stop frequency in the specified unit.

Returns:

Scaled stop frequency.

Return type:

float

property stop: float

The stop frequency in Hz.

Returns:

Stop frequency.

Return type:

float

property npoints: int

The number of points in the frequency axis.

Returns:

Number of points.

Return type:

int

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 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 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 f: Array

The frequency vector in Hz.

Returns:

The frequency vector in Hz.

Return type:

jnp.ndarray

property f_scaled: Array

The frequency vector in the specified unit.

Returns:

A frequency vector in the specified unit.

Return type:

jnp.ndarray

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

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

property unit: Literal['Hz', 'kHz', 'MHz', 'GHz', 'THz']

The frequency unit.

Possible values are ‘Hz’, ‘kHz’, ‘MHz’, ‘GHz’, ‘THz’. Setting this attribute is not case-sensitive.

Returns:

String representing the frequency unit.

Return type:

str

property multiplier: float

The multiplier to convert from the specified unit back to Hz.

Returns:

Multiplier for this frequency’s unit.

Return type:

float