Skip to content

qiu_signals.signal

Signals given by their samples on a physical axis.

Classes:

  • Signal –

    A signal given by its sampled values on a physical axis.

Signal

Signal(axis: PhysicalAxis, data: ArrayLike)

Bases: ArithmeticOperators

A signal given by its sampled values on a physical axis.

The sample data[k] is the value of the signal at axis.values[k].

Signals support the arithmetic operators +, -, *, / and **, elementwise with scalars and with signals on an equal axis, e.g. 2 * signal + other. The result is a new Signal.

Parameters:

  • axis (PhysicalAxis) –

    The axis the signal is sampled on.

  • data (ArrayLike) –

    The sampled values, a one-dimensional numeric array with one value per axis sample.

Raises:

  • ValueError –

    If the data does not have the shape (axis.size,) of the axis, or if it is not numeric.

Attributes:

Source code in packages/qiu-signals/src/qiu_signals/signal.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def __init__(self, axis: PhysicalAxis, data: npt.ArrayLike) -> None:
    """Initialize the signal from its sampled values.

    Args:
        axis: The axis the signal is sampled on.
        data: The sampled values, a one-dimensional numeric array with one value
            per axis sample.

    Raises:
        ValueError: If the data does not have the shape `(axis.size,)` of the axis,
            or if it is not numeric.
    """
    data = np.asarray(data)
    if data.shape != (axis.size,):
        raise ValueError(
            f"The data must have the shape ({axis.size},) of the axis, "
            f"got {data.shape}."
        )
    if not np.issubdtype(data.dtype, np.number):
        raise ValueError(f"The data must be numeric, got dtype {data.dtype}.")

    self.axis = axis
    self.data = data

axis instance-attribute

axis: PhysicalAxis = axis

The axis the signal is sampled on.

data instance-attribute

data: NDArray[number] = data

The sampled values of the signal, real or complex, one per axis sample.

size property

size: int

Return the number of samples of the signal.

normalized_data property

normalized_data: NDArray[number]

Return the sampled values normalized to unit Euclidean norm.

An all-zero signal is returned unchanged.