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
yaml_tag: Optional[str] = 'GainControlType'

YAML serialization tag.

property_blacklist: Set[str] = {}

Set of properties to be ignored during serialization.

serialized_attributes: Set[str] = {}

Set of object attributes to be serialized.

class Gain(gain=1.0)

Bases: Serializable

Base class for analog-to-digital conversion gain modeling.

Parameters

gain (float, optional) – signal gain

yaml_tag: Optional[str] = 'Gain'

YAML serialization tag.

property gain: float

Gain before quantizer

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

Returns

fixed gain

Return type

float

multiply_signal(input_signal)
Return type

None

divide_signal(input_signal)
Return type

None

classmethod to_yaml(representer, node)

Serialize a Gain object to YAML.

Parameters
  • representer (BaseRepresenter) – A handle to a representer used to generate valid YAML code. The representer gets passed down the serialization tree to each node.

  • node (AutomaticGainControl) – The ADC instance to be serialized.

Returns

The serialized YAML node.

Return type

Node

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

Bases: Gain

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.

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

multiply_signal(input_signal)
Return type

None

classmethod from_yaml(constructor, node)

Recall a new AnalogDigitalConverter instance from YAML.

Parameters
  • constructor (RoundTripConstructor) – A handle to the constructor extracting the YAML information.

  • node (Union[ScalarNode, MappingNode]) – YAML node representing the AnalogDigitalConverter serialization.

Returns

Newly created AnalogDigitalConverter instance.

Return type

AnalogDigitalConverter

classmethod to_yaml(representer, node)

Serialize a AutomaticGainControl object to YAML.

Parameters
  • representer (BaseRepresenter) – A handle to a representer used to generate valid YAML code. The representer gets passed down the serialization tree to each node.

  • node (AutomaticGainControl) – The ADC instance to be serialized.

Returns

The serialized YAML node.

Return type

Node

class QuantizerType(value)

Bases: SerializableEnum

Type of quantizer

MID_RISER = 0
MID_TREAD = 1
yaml_tag: Optional[str] = 'QuantizerType'

YAML serialization tag.

property_blacklist: Set[str] = {}

Set of properties to be ignored during serialization.

serialized_attributes: Set[str] = {}

Set of object attributes to be serialized.

class AnalogDigitalConverter(num_quantization_bits=inf, 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

Quantization resolution in bits

Returns

Bit resolution (if 0 or np.inf, then no quantization is applied)

Return type

int

Raises

ValueError – If resolution is less than zero.

property num_quantization_levels: Union[int, 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)
Return type

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