Logic Functions#

All Samples True#

You can test with the built-in function all() if all of the signal samples of a signal trace are True.

>>> all(Trace('Signal', [1, 1.0, True, 0x1, 0o1, 0b1]))
True
>>> all(Trace('Signal', [0, 1.0, True, 0x1, 0o1, 0b1]))
False

Any Sample True#

You can test with the built-in function any() if any of the signal samples of a signal trace is True.

>>> any(Trace('Signal', [0, 0.0, False, 0x0, 0o0, 0b0]))
False
>>> any(Trace('Signal', [1, 0.0, False, 0x0, 0o0, 0b0]))
True

Logical AND#

You can logical AND the signal samples of multiple signal traces by calling the function logical_and().

A new Trace instance labeled with the preformed logic function 'And' is returned.

>>> # logical AND between binary signals
>>> signal = Trace('Signal', [-1.0, -0.5, 0.0, 0.5, 1.0])
>>> logical_and(signal != 0, signal > -1, signal < 1)
Trace(label='And', samples=[0, 1, 0, 1, 0])

Note

The operands should have the same length, otherwise only a subset of the signal samples is returned!

(Source code, html)

Logical OR#

You can logical OR the signal samples of multiple signal traces by calling the function logical_or().

A new Trace instance labeled with the preformed logic function 'Or' is returned.

>>> # logical OR between binary signals
>>> signal = Trace('Signal', [-1.0, -0.5, 0.0, 0.5, 1.0])
>>> logical_or(signal == 0 , signal < -0.5, signal > 0.5)
Trace(label='Or', samples=[1, 0, 1, 0, 1])

Note

The operands should have the same length, otherwise only a subset of the signal samples is returned!

(Source code, html)

Priority Encoder#

Important

The operands are converted to int before the operation is performed.

You can prioritize the Truth=1 values of the binary signal samples from multiple signal traces by calling the function priority() with the iterable operands in the descending order to prioritize them.

This means the highest priority have the Truth=1 values of the first provided operand.

The lowest priority number is determined by the number of the provided operands.

A new Trace instance labeled with the preformed logic function 'Priority' is returned containing the priority numbers for the prioritized Truth=1 values of the given operands.

>>> signal = Trace('Signal', [-1.0, -0.5, 0.0, 0.5, 1.0])
>>> # prioritize binary signals from left to right in descending order
>>> priority(signal == 0, signal <= 0, signal >= 1)
Trace(label='Priority', samples=[1, 1, 0, 3, 2])
>>> signal = Trace('Signal', [-1.0, -0.5, 0.0, 0.5, 1.0])
>>> # prioritize binary signals starting from 1 as highest priority number
>>> priority(signal == 0, signal <= 0, signal >= 1, highest=1)
Trace(label='Priority', samples=[2, 2, 1, 4, 3])

Note

The operands should have the same length, otherwise only a subset of the signal samples is returned!

(Source code, html)