Logic Functions#
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
of multiple signal traces by
calling the function priority()
with the iterable operands in the
descending order to prioritize. 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
the Truth=1
values of the given operands.
>>> # prioritize binary signals from left to right in descending order
>>> signal = Trace('Signal', [-1.0, -0.5, 0.0, 0.5, 1.0])
>>> priority(signal == 0, signal <= 0, signal >= 1)
Trace(label='Priority', samples=[1, 1, 0, 3, 2])
>>> # prioritize binary signals starting from 1 as highest priority number
>>> signal = Trace('Signal', [-1.0, -0.5, 0.0, 0.5, 1.0])
>>> 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)