Defines decoding behaviors for each implemented waveform encoding
algorithm. Expects to find the codec (and its parameters) the arrays where
encoded with among the LGDO attributes.
Offset added to the input waveform before encoding.
The radware-sigcompress algorithm is limited to encoding of 16-bit
integer values. In certain cases (notably, with unsigned 16-bit integer
values), shifting incompatible data by a fixed amount circumvents the
issue.
After decoding, the signal values are shifted by -shift to restore the
original waveform. The dtype of sig_out must be large enough to contain it.
Almost literal translations of decompress_signal() from the
radware-sigcompress v1.0 C-code by David Radford [1]. See
_radware_sigcompress_encode() for a list of changes to the original
algorithm.
Parameters:
sig_in (ndarray[Any, dtype[uint8]]) – array holding the input, compressed signal. In the original code, an
array of 16-bit unsigned integers was expected.
sig_out (ndarray[Any, dtype[_ScalarType_co]]) – pre-allocated array for the decompressed signal. In the original code,
an array of 16-bit integers was expected.
shift (int32) – the value the original signal(s) was shifted before compression. The
value is subtracted from samples in sig_out right after decoding.
Shifts the signal values by +shift and internally interprets the result
as numpy.int16. Shifted signals must be therefore representable as
numpy.int16, for lossless compression.
Note
The algorithm also computes the first derivative of the input signal, which
cannot always be represented as a 16-bit integer. In such cases, overflows
occur, but they seem to be innocuous.
Almost literal translations of compress_signal() from the
radware-sigcompress v1.0 C-code by David Radford [1]. Summary of
changes:
Shift the input signal by shift before encoding.
Store encoded, numpy.uint16 signal as an array of bytes
(numpy.ubyte), in big-endian ordering.
Declare mask globally to avoid extra memory allocation.
sig_in (ndarray[Any, dtype[_ScalarType_co]]) – array of integers holding the input signal. In the original C code,
an array of 16-bit integers was expected.
sig_out (ndarray[Any, dtype[uint8]]) – pre-allocated array for the unsigned 8-bit encoded signal. In the
original C code, an array of unsigned 16-bit integers was expected.
shift (int32) – value to be added to sig_in before compression.
siglen (uint32) – array that will hold the lengths of the compressed signals.
Decompress digital signal(s) with radware-sigcompress.
Wraps _radware_sigcompress_decode() and adds support for decoding
LGDOs. Resizes the decoded signals to their actual length.
Note
If sig_in is a NumPy array, no resizing (along the last dimension) of
sig_out to its actual length is performed. Not even of the internally
allocated one. If a pre-allocated ArrayOfEqualSizedArrays is
provided, it won’t be resized too. The internally allocated
ArrayOfEqualSizedArrays sig_out has instead always the correct
size.
Because of the current (hardware vectorized) implementation, providing a
pre-allocated VectorOfVectors as sig_out is not possible.
Parameters:
sig_in (NDArray[ubyte] | lgdo.VectorOfEncodedVectors | lgdo.ArrayOfEncodedEqualSizedArrays) – array(s) holding the input, compressed signal(s). Output of
encode().
sig_out (NDArray | lgdo.ArrayOfEqualSizedArrays) – pre-allocated array(s) for the decompressed signal(s). If not
provided, will allocate a 32-bit integer array(s) structure.
shift (int32) – the value the original signal(s) was shifted before compression. The
value is subtracted from samples in sig_out right after decoding.
Returns:
sig_out, nbytes | LGDO – given pre-allocated structure or new structure of 32-bit integers, plus
the number of bytes (length) of the decoded signal.
The compression algorithm internally interprets the input waveform values as
16-bit integers. Make sure that your signal can be safely cast to such a
numeric type. If not, you may want to apply a shift to the waveform.
sig_out (NDArray[ubyte]) – pre-allocated unsigned 8-bit integer array(s) for the compressed
signal(s). If not provided, a new one will be allocated.
shift (int32) – value to be added to sig_in before compression.
Returns:
sig_out, nbytes | LGDO – given pre-allocated sig_out structure or new structure of unsigned
8-bit integers, plus the number of bytes (length) of the encoded
signal. If sig_in is an LGDO, only a newly allocated
VectorOfEncodedVectors or
ArrayOfEncodedEqualSizedArrays is returned.
If sig_in is a NumPy array, no resizing (along the last dimension) of
sig_out to its actual length is performed. Not even of the internally
allocated one. If a pre-allocated ArrayOfEqualSizedArrays is
provided, it won’t be resized too. The internally allocated
ArrayOfEqualSizedArrays sig_out has instead always the correct
size.
Because of the current (hardware vectorized) implementation, providing a
pre-allocated VectorOfVectors as sig_out is not possible.
Parameters:
sig_in ((NDArray[ubyte], NDArray[uint32]) | lgdo.VectorOfEncodedVectors | lgdo.ArrayOfEncodedEqualSizedArrays) – array(s) holding the input, compressed signal(s). Output of
encode().
sig_out (NDArray | lgdo.ArrayOfEqualSizedArrays) – pre-allocated array(s) for the decompressed signal(s). If not
provided, will allocate a 32-bit integer array(s) structure.
Returns:
sig_out, nbytes | LGDO – given pre-allocated structure or new structure of 32-bit integers, plus
the number of bytes (length) of the decoded signal.
sig_out (NDArray[ubyte]) – pre-allocated unsigned 8-bit integer array(s) for the compressed
signal(s). If not provided, a new one will be allocated.
Returns:
sig_out, nbytes | LGDO – given pre-allocated sig_out structure or new structure of unsigned
8-bit integers, plus the number of bytes (length) of the encoded
signal. If sig_in is an LGDO, only a newly allocated
VectorOfEncodedVectors or
ArrayOfEncodedEqualSizedArrays is returned.
The algorithm inverts uleb128_zigzag_diff_array_encode() by decoding
the variable-length binary data in sig_in with uleb128_decode(),
then reconstructing the original signal derivative with
zigzag_decode() and finally computing its cumulative (i.e. the
original signal).
Parameters:
sig_in (ndarray[Any, dtype[uint8]]) – the array of bytes encoding the variable-length integers.
nbytes (int) – the number of bytes to read from sig_in (stored in the first index of
this array).
sig_out (ndarray[Any, dtype[int]]) – pre-allocated array for the output decoded signal.
siglen (int) – the length of the decoded signal, (stored in the first index of this
array).
The algorithm computes the derivative (prepending 0 first) of sig_in,
maps it to positive numbers by applying zigzag_encode() and finally
computes its variable-length binary representation with
uleb128_encode().
The encoded data is stored in sig_out as an array of bytes. The number of
bytes written is stored in nbytes. The actual encoded data can therefore
be found in sig_out[:nbytes].