Analog-to-Digital Converter#

Implements an analog-to digital converter. Currently only uniform quantization is considered.

The following figure visualizes the quantizer responses.

(Source code, png, hires.png, pdf)

../_images/plot_quantizer.png
class GainControlType(value)#

Bases: SerializableEnum

Type of automatig gain control

NONE = 0#
MAX_AMPLITUDE = 1#
RMS_AMPLITUDE = 2#
class GainType#

Type of gain.

alias of TypeVar(‘GainType’, bound=Gain)

class GainControlBase(rescale_quantization=False)#

Bases: ABC

Base class for all ADC gain control models.

Parameters:

rescale_quantization (bool, optional) – If enabled, the quantized signal is rescaled to the original signal range before gain adjustment. Disabled by default.

property rescale_quantization: bool#

Rescale the quantized signal to the original signal range before gain adjustment.

abstract estimate_gain(input_signal)#

Estimate the gain required to adjust the signal to the ADC input range.

Parameters:

input_signal (Signal) – Input signal to be adjusted.

Return type:

float

Returns: Linear gain to be applied to the input_signal’s Voltage samples.

adjust_signal(input_signal, gain)#

Adjust the signal to the ADC input range.

Parameters:
  • input_signal (Signal) – Input signal to be adjusted.

  • gain (float) – Linear gain to be applied to the input_signal’s Voltage samples.

Return type:

Signal

Returns: The adjusted signal.

scale_quantized_signal(quantized_signal, gain)#

Scale the quantized signal back to the original signal range before gain adjustment.

Only applied if rescale_quantization is enabled.

Parameters:
  • quantized_signal (Signal) – Quantized signal to be adjusted.

  • gain (float) – Linear gain to applied to the input_signal’s Voltage samples before quantization.

Return type:

Signal

Returns: The scaled qzanitized signal.

class Gain(gain=1.0, rescale_quantization=False)#

Bases: Serializable, GainControlBase

Constant gain model.

Parameters:
  • gain (float, optional) – Linear signal gain to be applied before ADC quantization. Unit by default, meaning no gain adjustment.

  • rescale_quantization (bool, optional) – If enabled, the quantized signal is rescaled to the original signal range before gain adjustment. Disabled by default.

yaml_tag: Optional[str] = 'Gain'#

YAML serialization tag.

property gain: float#

Linear gain before ADC quantization.

Quantizer operates by default between -1. and +1. Signal can be adjusted by to this range by appropriate gain setting.

Returns: Gain in Volt.

Raises:

ValueError – If gain is smaller or equal to zero.

estimate_gain(input_signal)#

Estimate the gain required to adjust the signal to the ADC input range.

Parameters:

input_signal (Signal) – Input signal to be adjusted.

Return type:

float

Returns: Linear gain to be applied to the input_signal’s Voltage samples.

class AutomaticGainControl(agc_type=GainControlType.MAX_AMPLITUDE, backoff=1.0, rescale_quantization=False)#

Bases: Serializable, GainControlBase

Analog-to-digital conversion automatic gain control modeling.

Parameters:
  • agc_type (GainControlType, optional) – Type of amplitude gain control at ADC input. Default is GainControlType.MAX_AMPLITUDE.

  • backoff (float, optional) – this is the ratio between maximum amplitude and the rms value or maximum of input signal, depending on AGC type. Default value is 1.0.

  • rescale_quantization (bool, optional) – If enabled, the quantized signal is rescaled to the original signal range before gain adjustment. Disabled by default.

yaml_tag: Optional[str] = 'AutomaticGainControl'#

YAML serialization tag.

property agc_type: GainControlType#

Automatic Gain Control

The AGC may have the following types of gain control, which wil specify the quantizer range: - GainControlType.NONE: no gain control, range must be specified - GainControlType.MAX_AMPLITUDE: the range is given by the maximum amplitude of the - GainControlType.RMS_AMPLITUDE: the range is given by the rms value plus a given backoff Note the for complex numbers, amplitude is calculated for both real and imaginary parts separately, and the greatest value is considered.

Return type:

GainControlType

property backoff: float#

Quantizer backoff in linear scale

This quantity determines the ratio between the maximum quantization level and the signal rms value :returns: the backoff in linear scale :rtype: float

estimate_gain(input_signal)#

Estimate the gain required to adjust the signal to the ADC input range.

Parameters:

input_signal (Signal) – Input signal to be adjusted.

Return type:

float

Returns: Linear gain to be applied to the input_signal’s Voltage samples.

class QuantizerType(value)#

Bases: SerializableEnum

Type of quantizer

MID_RISER = 0#
MID_TREAD = 1#
class AnalogDigitalConverter(num_quantization_bits=None, gain=None, quantizer_type=QuantizerType.MID_RISER)#

Bases: Serializable

Implements an ADC (analog-to-digital converter)

Models the behaviour of an ADC, including: - Sampling Jitter (to be implemented) - Automatic Gain Control - Quantization. Currently only uniform and symmetric quantization is supported.

This class only implements the quantization noise, the output data is still in floating point representation with the same amplitude as the input.

Parameters:
  • num_quantization_bits (int, optional) – ADC resolution in bits. Default is infinite resolution (no quantization)

  • gain (Gain, optional) – Amplitude gain control at ADC input. Default is Gain(1.0), i.e., no gain.

  • quantizer_type (QuantizerType, optional) – Determines quantizer behaviour at zero. Default is QuantizerType.MID_RISER.

yaml_tag: Optional[str] = 'ADC'#

YAML serialization tag

gain: Gain#
property num_quantization_bits: int | None#

Quantization resolution in bits

Returns:

Bit resolution, None if no quantization is applied.

Raises:

ValueError – If resolution is less than zero.

property num_quantization_levels: float#

Number of quantization levels

Returns:

Number of levels

Return type:

int

property quantizer_type: QuantizerType#

Type of quantizer

  • QuantizationType.MID_TREAD: 0 can be the output of a quantization step. Since the number of quantization step

    must be even, negative values will have one step more than positive values

  • QuantizerType.MID_RISE: input values around zero are quantized as either -delta/2 or delta/2, with delta the

    quantization step

Returns:

type of quantizer

Return type:

QuantizerType

convert(input_signal, frame_duration=0.0)#

Converts an analog signal into a digitally quantized signal.

Parameters:
  • input_signal (Signal) – Signal to be converted.

  • frame_duration (float, optional) – Duration of a signal frame frame in seconds. Each frame will get converted indepentedly. By default the whole signal is converted at once.

Return type:

Signal

Returns: Gain adjusted and quantized signal.

plot_quantizer(input_samples=None, label='', fig_axes=None)#

Plot the quantizer characteristics.

Generates a matplotlib plot depicting the staircase amplitude response. Note that only the real part is plotted, as the quantizer is applied separately in the real and imaginary parts.

Parameters:
  • input_samples (np.ndarray, optional) – Sample points at which to evaluate the characteristics, i.e., the x-axis of the resulting characteristics plot. It should be a sorted number sequence.

  • label (str, optional) – A label describing the desired plot.

  • fig_axes (Optional[plt.axes], optional) – Axes to which to plot the charateristics. By default, a new figure is created.

Return type:

None