PwrDetectorController

class rfblocks.PwrDetectorController(controller_id: str, device: LogDetector)[source]

Higher level control for power detector boards

PwrDetectorController maintains the state configuration for a power detector board. This includes the current signal input power and frequency. The controller also holds application specific calibration data associated with the detector and optionally applies corrections to the measured signal power using the calibration data.

The following signals are defined:

  • freq_changed(float)

  • pwr_changed(float)

  • caldata_changed()

  • detector_initialized()

  • correction_state_changed(bool)

  • enable_state_changed(bool)

Documentation for the LTC5582 and LT5537 power detector rfblocks modules can be found here: LTC5582 and LT5537 Power Detectors

Parameters:
property apply_correction: bool

Control applying corrections to the measured signal power.

By default, corrections are not applied. Set to True in order to apply corrections. Note that calibration data must be available via the cal_data property.

property avg: int

The number of detector measurements to average over.

By default this is 16.

property cal_data

Return application calibration data.

The format for the calibration data is:

{ frequency_string: power_in_dbm, ... }

For example:

{'100.0': 0.204, '200.0': -0.031, '300.0': 0.063, ...
 ...
 '4100.0': 0.262, '4200.0': 0.246}

where the frequency is specified in MHz.

If no calibration data is available this will return None.

See also

load_caldata()

property cal_data_conditions

A dictionary for storing any conditions associated with acquisition of detector calibration data. For example, if the detector has a step attenuator associated with it then the attenuation setting for which the calibration was carried out can be saved here.

property calibrating: bool

Inform the controller when a calibration is taking place.

During calibration corrections are not applied and any specified power_offset is ignored.

property enabled: bool

Enable/disable operation of the power detector.

By default the power detector operation is enabled.

property freq: float

The frequency of the detector input signal.

initialize(ser: Serial) None[source]

Initialize the power detector.

insertion_loss(f)[source]

Return the insertion loss at the specified signal frequency.

Parameters:

f (float) – The signal frequency in MHz

Returns:

The insertion loss in dB.

Raises:

ValueError If the specified signal frequency is outside the range of the calibration data.

The insertion loss is calculated by cubic spline interpolation on the calibration data as returned from cal_data.

property insertion_loss_offset: float

The insertion loss offset.

Parameters:

loss (float) – The new insertion loss offset value in dB

The insertion loss offset is added to the insertion loss as calculated from the calibration data (see insertion_loss). The offset is generally used in situations where some known level of attenuation (or amplification) is added between the signal source and the detector after the calibration data has been captured. The correction then becomes an estimate since the additional attenuation/amplification has not been calibrated and may exhibit unquantified variations as a function of frequency (for example).

is_connected(ser: Serial) bool[source]

Test if there is a connected detector.

Parameters:

ser (serial.Serial) – serial device to write commands to

Returns:

True if there is a connected power detector, False otherwise.

property linear_range

Return the detector’s linear response range.

Returns:

A tuple containing the minimum and maximum input signal powers for which the detector provides a linear response. If no calibration data is available the CalibrationDataException is raised.

load_caldata(input_file)[source]

Load calibration data from a file.

Parameters:

input_file (str) – Path to file for loading the calibration data.

See also

cal_data()

property max_frequency: float

The maximum valid detector signal frequency.

measure(ser: Serial) None[source]

Measure the detector signal power.

Parameters:

ser (serial.Serial) – Power detector serial connection

Raises:

rfblocks.CalibrationRangeError

If apply_correction is True then insertion loss correction will be carried out on the measured signal power. Insertion loss is calculated from the calibration data returned by cal_data. If no calibration is available or if the specified signal frequency is outside the calibration data range, a rfblocks.CalibrationRangeError exception is raised.

If apply_correction is False and the detector is not being calibrated then power_offset() is subtracted from the measured signal power.

The insertion_loss_offset() value is applied to the measured signal power regardless of whether apply_correction is True or False.

property min_frequency: float

The minimum valid detector signal frequency.

power_offset(freq: float) float[source]

Calculate the power offset at the specified frequency.

Parameters:

freq (float) – Frequency (in MHz) to calculate power_offset.

Returns:

The power loss (or gain) at the specified frequency.

The power_loss value is added to the measured power value in the circumstance where apply_correction is False. In general, power_loss will be set to the value of any attenuation or gain which is permanently inserted between the power detector and the power meter input.

property pwr: float

Returns the measured signal power in dBm.

Note

If apply_correction is True and cal_data provides valid calibration data then the measured signal power will be corrected using this.

save_caldata(output_file)[source]

Save the prevailing calibration data to a file.

Parameters:

output_file (str) – Path to file for saving the calibration data.

set_power_offset_fn(fn: Callable[[float], float] | None) None[source]

Set the power offset function.

Parameters:

fn (Callable[[float], float]) – A function returning the power loss (or gain) at a specified frequency. The power loss (or gain) value calculated by this function will generally be the (usually frequency dependent) value of an attenuator or amplifier inserted between the power detector and the signal input. This would be used, for example, to condition the input signal to be measured so that it falls into the linear range of the detector.

This function will only be used when apply_correction is False and takes the place of the correction that would be applied using the calibration data.