lib_quant module¶
Module with basic quantizer and dequantizer.
-
lib_quant.
compute_range_bits
(bits_per_sample)[source]¶ Compute list of values for unpacking samples. [Used by decode_samples_red()]
Example:>>bits_per_sample=2>>list(compute_range_bits(bits_per_sample))[6, 4, 2, 0]
-
lib_quant.
decode_samples_red
(words, bits_per_sample)[source]¶ Unpack samples given a binary vector with the packed samples and the number of bits per sample. [Used by sub_unpack_samples()]
words bits_per_sample : int
number of bits per sample.- words_nostack : numpy 1D array
- unpacked samples.
-
lib_quant.
get_samples
(samples_quant, bits_per_sample, current_data_type, num_samples=-1, single_precision=0)[source]¶ Get dequantized samples from samples in binary format.
- samples_quant : numpy 1D array
- samples (components if complex), packed in binary format (uint8).
- bits_per_sample : int
- number of bits per sample.
- current_data_type : char {‘c’,’r’}
- ‘c’ for complex, ‘r’ for real data.
- num_samples : int
- number of samples to be returned (first num_samples). This is used to avoid errors if the number
- samples is smaller than the number of samples fitting a uint8.
- v_2bps_complex : list
- quantization levels for 2 bit complex.
- v_2bps_real : list
- quantization levels for 2 bit real.
- result : numpy 1D array
- complex with dequantized samples.
TO DO:Currently only 2 bits per sample, generalize for different numbers of bits per sample.
-
lib_quant.
group_pairs_complex
(samples)[source]¶ From a given list of samples, group into pairs of 2 (real and imaginary).
-
lib_quant.
np_take_samples
(v_2bps, unpacked_samples)[source]¶ Translate vector with sampled values into dequantized values. [Used by sub_unpack_samples()]
- v_2bps : list
- quantization values.
- unpacked_samples
- quantized samples.
- out : numpy 1D array
- dequantized sample components.
-
lib_quant.
simple_dequantizer
(signal=[], bits_quant=1, limits=[-1, 1])[source]¶ - Basic dequantizer: it takes as input a list of quantized samples (output of simple_quantizer())
and returns a list of the same size with float values from limits[0] to limits[1], representing the quantization thressholds, distributed at equal intervals between these limits
- Example:
- signal = [0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3] bits_quant = 2 output=simple_dequantizer(signal,bits_quant) output = [-0.75, -0.75, -0.75, -0.75, -0.25, -0.25, -0.25, 0.25, 0.25, 0.25, 0.75, 0.75, 0.75]
(!) Use only for testing. (!) TO DO: migrate code using this function to newer implementation.
-
lib_quant.
simple_quantizer
(samples, bits_quant=1, signal_limits=[-1, 1], force_limits=0)[source]¶ - Basic quantizer: it takes as input a list of samples and returns a list of the same size
with integers from 0 to 2**bits_quant - 1, representing the quantization thressholds, distributed at equal intervals between teh minimum and the maximum of the signal.
- Example:
- signal = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] bits_quant = 2 output=simple_quantizer(signal,bits_quant) output = [0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]
- To be done:
- -Introduce other quantization strategies
(!) Use only for testing. (!) TO DO: migrate code using this function to newer implementation.
-
lib_quant.
sub_pack_complex_samples
(samples, bits_per_sample)[source]¶ Group dequantized values into complex values (pair where first one is real part, second one imaginary part).
- samples : numpy 1D array
- samples components (complex): [real_part_0, imag_part_0, real_part_1, ... ].
- bits_per_sample : int
- number of bits per sample.
- complex_samples : numpy 1D array
- complex samples: [complex_0, complex_1, ...]
TO DO:Currently only 2 bits per sample.