Signal Processing

genalyzer.downsample(a, ratio, interleaved=False)

Decimate a waveform by keeping every Nth sample.

Keeps every ratio-th sample from the input. If interleaved is True, the input is treated as interleaved I/Q pairs and decimation preserves pair alignment.

Args:

a (ndarray) : Input array of type complex128, float64, int16, int32, or int64

ratio (int) : Decimation ratio (keep every Nth sample)

interleaved (bool) : If True, treat a as interleaved I/Q data

Returns:

out (ndarray) : Downsampled waveform with same dtype as input

genalyzer.fshift(a, *args)

Perform frequency shift

Args:

a (ndarray) : Input array of type complex128, float64, int16, int32, or int64

args (list)Additional arguments
  1. If a is of type complex128 or float64, then perform frequency shift of interleaved normalized samples with the following interpretation.

    fs (double) : Sample rate

    fshift_ (double) : Shift frequency

    In this case, if a is not complex, then a is interpreted to contain interleaved I/Q samples.

  2. If a is of type float64, then perform frequency shift of split normalized samples.

    q (float64) : Quadrature component

    fs (double) : Sample rate

    fshift_ (double) : Shift frequency

    In this case, a is interpreted to be the In-phase component.

  3. If a is of type int16, int32, or int64, then perform frequency shift of interleaved quantized samples with the following interpretation.

    n (int) : Resolution (Bitwidth of a)

    fs (double) : Sample rate

    fshift_ (double) : Shift frequency

    fmt (CodeFormat): Code format

    In this case, a is interpreted to contain interleaved quantized samples.

  4. If a is of type int16, int32, or int64, then perform frequency shift of split quantized samples with the following interpretation.

    q (int16, int32, or int64) : Quadrature component

    n (int) : Resolution (Bitwidth of a)

    fs (double) : Sample rate

    fshift_ (double) : Shift frequency

    fmt (CodeFormat): Code format

    In this case, a is interpreted to to be the In-phase component.

Returns:

out (ndarray) : Frequency-shifted input waveform. The output datatype is the same as the input datatype.

genalyzer.normalize(a, n, fmt=CodeFormat.TWOS_COMPLEMENT)

Convert quantized integer samples to normalized floating-point values in [-1, 1).

For two’s complement, scales by 2/2^n. For offset binary, subtracts the midpoint offset before scaling.

Args:

a (ndarray) : Input array of type int16, int32, or int64

n (int) : ADC resolution in bits

fmt (CodeFormat) : Binary code format (default: TWOS_COMPLEMENT)

Returns:

out (ndarray) : float64 array of normalized values in [-1, 1)

genalyzer.polyval(a, c)

Evaluate a polynomial at each element of the input array using Horner’s method.

Coefficients are ordered as [c0, c1, c2, …] where y = c0 + c1*x + c2*x^2 + … Commonly used to model nonlinear transfer function distortion.

Args:

a (ndarray) : Input array of type float64

c (ndarray or list) : Polynomial coefficients [c0, c1, c2, …] of type float64

Returns:

out (ndarray) : float64 array of polynomial evaluation results

genalyzer.quantize16(a, fsr, n, noise=0.0, fmt=CodeFormat.TWOS_COMPLEMENT)

Quantize floating-point samples to 16-bit integer codes.

The full-scale range determines the LSB size: LSB = fsr / 2^n. Samples are mapped to codes by floor(sample/LSB), clamped to the valid code range. Optional Gaussian noise can be added before quantization to model thermal noise.

Args:

a (ndarray) : Input array of type float64

fsr (float) : Full-scale range of the waveform

n (int) : ADC resolution in bits

noise (float) : RMS level of Gaussian noise to add before quantization (default: 0.0)

fmt (CodeFormat) : Binary code format (default: TWOS_COMPLEMENT)

Returns:

out (ndarray) : int16 array of quantized codes

genalyzer.quantize32(a, fsr, n, noise=0.0, fmt=CodeFormat.TWOS_COMPLEMENT)

Quantize floating-point samples to 32-bit integer codes.

The full-scale range determines the LSB size: LSB = fsr / 2^n. Samples are mapped to codes by floor(sample/LSB), clamped to the valid code range. Optional Gaussian noise can be added before quantization to model thermal noise.

Args:

a (ndarray) : Input array of type float64

fsr (float) : Full-scale range of the waveform

n (int) : ADC resolution in bits

noise (float) : RMS level of Gaussian noise to add before quantization (default: 0.0)

fmt (CodeFormat) : Binary code format (default: TWOS_COMPLEMENT)

Returns:

out (ndarray) : int32 array of quantized codes

genalyzer.quantize64(a, fsr, n, noise=0.0, fmt=CodeFormat.TWOS_COMPLEMENT)

Quantize floating-point samples to 64-bit integer codes.

The full-scale range determines the LSB size: LSB = fsr / 2^n. Samples are mapped to codes by floor(sample/LSB), clamped to the valid code range. Optional Gaussian noise can be added before quantization to model thermal noise.

Args:

a (ndarray) : Input array of type float64

fsr (float) : Full-scale range of the waveform

n (int) : ADC resolution in bits

noise (float) : RMS level of Gaussian noise to add before quantization (default: 0.0)

fmt (CodeFormat) : Binary code format (default: TWOS_COMPLEMENT)

Returns:

out (ndarray) : int64 array of quantized codes

genalyzer.quantize(a, fsr, n, noise=0.0, fmt=CodeFormat.TWOS_COMPLEMENT)

Quantize floating-point samples to integer codes with automatic bit-width selection.

Selects int16 output if n <= 16 (two’s complement) or n < 16 (offset binary), and int32 otherwise. See quantize16 and quantize32 for details.

Args:

a (ndarray) : Input array of type float64

fsr (float) : Full-scale range of the waveform

n (int) : ADC resolution in bits

noise (float) : RMS level of Gaussian noise to add before quantization (default: 0.0)

fmt (CodeFormat) : Binary code format (default: TWOS_COMPLEMENT)

Returns:

out (ndarray) : int16 or int32 array of quantized codes