Mathematical Functions¶
Negation¶
You can negate each signal sample with the '-'
operator or by calling
the method neg()
.
A new Trace
instance labeled with the performed transformation
'neg'
is returned.
>>> # negate samples with operator
>>> -Trace('Signal', [-1, 0, 1])
Trace(label='Signal:neg', samples=[1, 0, -1])
>>> # negate samples with method call
>>> Trace('Signal', [-1, 0, 1]).neg()
Trace(label='Signal:neg', samples=[1, 0, -1])
(Source code, html)
Absolute¶
You can compute the absolute value for each signal sample with the built-in
function abs()
or by calling the method abs()
.
A new Trace
instance labeled with the performed transformation
'abs'
is returned.
>>> abs(Trace('Signal', [-1, 0, 1]))
Trace(label='Signal:abs', samples=[1, 0, 1])
>>> Trace('Signal', [-1, 0, 1]).abs()
Trace(label='Signal:abs', samples=[1, 0, 1])
(Source code, html)
Rounding¶
You can round each signal sample with the built-in function round()
or
by calling the method round()
.
A new Trace
instance labeled with the performed transformation
'round'
is returned.
>>> round(Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]))
Trace(label='Signal:round', samples=[-2, 0, 0, 0, 2])
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).round()
Trace(label='Signal:round', samples=[-2, 0, 0, 0, 2])
(Source code, html)
Truncation¶
You can truncate each signal sample with the function trunc()
from the math
module or by calling the method trunc()
.
A new Trace
instance labeled with the performed transformation
'trunc'
is returned.
>>> import math
>>> math.trunc(Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]))
Trace(label='Signal:trunc', samples=[-1, 0, 0, 0, 1])
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).trunc()
Trace(label='Signal:trunc', samples=[-1, 0, 0, 0, 1])
(Source code, html)
Round to the Floor¶
You can round each signal sample to its floor integer with the function
floor()
from the math
module or by calling the method
floor()
.
A new Trace
instance labeled with the performed transformation
'floor'
is returned.
>>> import math
>>> math.floor(Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]))
Trace(label='Signal:floor', samples=[-2, -1, 0, 0, 1])
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).floor()
Trace(label='Signal:floor', samples=[-2, -1, 0, 0, 1])
(Source code, html)
Round to the Ceil¶
You can round each signal sample to its ceil integer with the function
ceil()
from the math
module or by calling the method
ceil()
.
A new Trace
instance labeled with the performed transformation
'ceil'
is returned.
>>> import math
>>> math.ceil(Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]))
Trace(label='Signal:ceil', samples=[-1, 0, 0, 1, 2])
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).ceil()
Trace(label='Signal:ceil', samples=[-1, 0, 0, 1, 2])
(Source code, html)
Signum¶
You can compute the signum value for each signal sample by calling the
method sign()
.
A new Trace
instance labeled with the performed transformation
'sign'
is returned.
>>> Trace('Signal', [-1.5, -0.5, 0 , 0.5, 1.5]).sign()
Trace(label='Signal:sign', samples=[-1.0, -1.0, 0, 1.0, 1.0])
(Source code, html)
Zeros¶
You can check each signal sample is zero or not by calling the
method zero()
.
A new Trace
instance labeled with the performed transformation
'zero'
is returned.
>>> Trace('Signal', [-0.5, -0.0, 0, +0.0, 0.5]).zero()
Trace(label='Signal:zero', samples=[0, 1, 1, 1, 0])
(Source code, html)
Positives¶
You can check each signal sample is positive or not by calling the
method positive()
.
A new Trace
instance labeled with the performed transformation
'positive'
is returned.
>>> Trace('Signal', [-0.5, -0.0, 0, +0.0, 0.5]).positive()
Trace(label='Signal:positive', samples=[0, 0, 0, 0, 1])
(Source code, html)
Negatives¶
You can check each signal sample is negative or not by calling the
method negative()
.
A new Trace
instance labeled with the performed transformation
'negative'
is returned.
>>> Trace('Signal', [-0.5, -0.0, 0, +0.0, 0.5]).negative()
Trace(label='Signal:negative', samples=[1, 0, 0, 0, 0])
(Source code, html)
Min¶
You can get the minimum of each signal sample and the corresponding element
in other Trace
’s or Iterables
, or an int
or float
numbers by calling the method min()
.
A new Trace
instance labeled with the performed transformation
'min'
is returned.
>>> # minimum of samples
>>> Trace('Signal1', [1, -2, 3]).min(Trace('Signal2', [-1, 2, -3]))
Trace(label='Signal1:min', samples=[-1, -2, -3])
>>> # minimum of samples and iterables
>>> Trace('Signal', [1, -2, 3]).min([-1, 2, -3])
Trace(label='Signal:min', samples=[-1, -2, -3])
>>> # minimum of samples and numbers
>>> Trace('Signal', [1, 2, 3]).min(2)
Trace(label='Signal:min', samples=[1, 2, 2])
Note
An iterable should have at least the same length as the signal
samples
, otherwise only a subset of the signal
samples
is returned!
(Source code, html)
Max¶
You can get the maximum of each signal sample and the corresponding element
in other Trace
’s or Iterables
, or an int
or float
numbers by calling the method max()
.
A new Trace
instance labeled with the performed transformation
'max'
is returned.
>>> # maximum of samples
>>> Trace('Signal1', [1, -2, 3]).max(Trace('Signal2', [-1, 2, -3]))
Trace(label='Signal1:max', samples=[1, 2, 3])
>>> # maximum of samples and iterables
>>> Trace('Signal', [1, -2, 3]).max([-1, 2, -3])
Trace(label='Signal:max', samples=[1, 2, 3])
>>> # maximum of samples and numbers
>>> Trace('Signal', [1, 2, 3]).max(2)
Trace(label='Signal:max', samples=[2, 2, 3])
Note
An iterable should have at least the same length as the signal
samples
, otherwise only a subset of the signal
samples
is returned!
(Source code, html)
Average¶
You can get the average of each signal sample and the corresponding element
in other Trace
’s or Iterables
, or an int
or float
numbers by calling the method average()
.
A new Trace
instance labeled with the performed transformation
'avg'
is returned.
>>> # average of samples
>>> Trace('Signal1', [1, -2, 3]).average(Trace('Signal2', [-1, 2, -3]))
Trace(label='Signal1:avg', samples=[0.0, 0.0, 0.0])
>>> # average of samples and iterables
>>> Trace('Signal', [1, -2, 3]).average([-1, 2, -3])
Trace(label='Signal:avg', samples=[0.0, 0.0, 0.0])
>>> # average of samples and numbers
>>> Trace('Signal', [1, -2, 3]).average(2)
Trace(label='Signal:avg', samples=[1.5, 0.0, 2.5])
Note
An iterable should have at least the same length as the signal
samples
, otherwise only a subset of the signal
samples
is returned!
(Source code, html)