Clipping#
The signal samples
of a signal trace can be
clipped by another set of samples
or a number at a lower and/or
upper bound.
Lower Bound Clipping#
You can hard clip each signal sample at the corresponding element in another
Trace
or Iterable
, or at an int
or float
number
assigned as lower bound for the signal samples
by calling the
method clip()
.
A new Trace
instance labeled with the performed transformation
'clip'
is returned.
>>> # clip samples at lower bound trace samples
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(
... lower=Trace('Lower', [1, 0, 0, 0, -1]))
Trace(label='Signal:clip', samples=[1, 0, 0, 0.5, 1.5])
>>> # clip samples at lower bound iterable items
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(lower=[1, 0, 0, 0, -1])
Trace(label='Signal:clip', samples=[1, 0, 0, 0.5, 1.5])
>>> # clip samples at lower bound number
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(0)
Trace(label='Signal:clip', samples=[0, 0, 0, 0.5, 1.5])
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(lower=0)
Trace(label='Signal:clip', samples=[0, 0, 0, 0.5, 1.5])
Upper Bound Clipping#
You can hard clip each signal sample at the corresponding element in another
Trace
or Iterable
, or at an int
or float
number
assigned as upper bound for the signal samples
by calling the
method clip()
.
A new Trace
instance labeled with the performed transformation
'clip'
is returned.
>>> # clip samples at upper bound trace samples
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(
... upper=Trace('Upper', [1, 0, 0, 0, -1]))
Trace(label='Signal:clip', samples=[-1.5, -0.5, 0, 0, -1])
>>> # clip samples at upper bound iterable items
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(upper=[1, 0, 0, 0, -1])
Trace(label='Signal:clip', samples=[-1.5, -0.5, 0, 0, -1])
>>> # clip samples at upper bound number
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(upper=0)
Trace(label='Signal:clip', samples=[-1.5, -0.5, 0, 0, 0])
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(None, 0)
Trace(label='Signal:clip', samples=[-1.5, -0.5, 0, 0, 0])
Lower & Upper Bound Clipping#
You can hard clip each signal sample at the corresponding element in another
Trace
or Iterable
, or at an int
or float
number
assigned as lower bound or upper bound for the signal samples
by
calling the method clip()
.
A new Trace
instance labeled with the performed transformation
'clip'
is returned.
>>> # clip samples at lower & upper bound trace samples
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(
... lower=Trace('Lower', [-1, 0, 0.5, 0, -1]),
... upper=Trace('Upper', [1, 0, -0.5, 0, 1]))
Trace(label='Signal:clip', samples=[-1, 0, -0.5, 0, 1])
>>> # clip samples at lower & upper bound iterable items
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(
... lower=[-1, 0, 0,5, 0, -1],
... upper=[1, 0, -0.5, 0, 1])
Trace(label='Signal:clip', samples=[-1, 0, -0.5, 0, 1])
>>> # clip samples at lower & upper bound numbers
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(-0.5, 1.0)
Trace(label='Signal:clip', samples=[-0.5, -0.5, 0, 0.5, 1.0])
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clip(lower=-0.5, upper=1.0)
Trace(label='Signal:clip', samples=[-0.5, -0.5, 0, 0.5, 1.0])
Note
The upper bound is dominant over the lower bound.
Note
An iterable bound should have at least the same length as the signal
samples
, otherwise only a subset of the signal
samples
is returned!
(Source code, html)
Symmetrically Clamping#
You can symmetrically clamp each signal sample at the corresponding element
in another Trace
or Iterable
, or at an int
or float
number by calling the method clamp()
.
A new Trace
instance labeled with the performed transformation
'clamp'
is returned.
>>> # clip samples at trace samples
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clamp(
... Trace('Bound', [1, 0, 0, 0, -1]))
Trace(label='Signal:clamp', samples=[-1, 0, 0, 0, 1])
>>> # clip samples at iterable items
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clamp([1, 0, 0, 0, -1])
Trace(label='Signal:clamp', samples=[-1, 0, 0, 0, 1])
>>> # clip samples at number
>>> Trace('Signal', [-1.5, -0.5, 0, 0.5, 1.5]).clamp(-1.0)
Trace(label='Signal:clamp', samples=[-1.0, -0.5, 0, 0.5, 1.0])
Note
An iterable bound should have at least the same length as the signal
samples
, otherwise only a subset of the signal
samples
is returned!
(Source code, html)