X-Axis Transformations#
Move#
You can move the signal samples
by a number of samples to the
right by calling the method move()
with the positive number of
samples the signal samples
shall be moved to the right.
A new Trace
instance labeled with the performed transformation
'move'
is returned.
>>> # move samples by the number of samples to the right
>>> Trace('Signal', [1, 2, 3, 4, 5]).move(2)
Trace(label='Signal:move', samples=[1, 1, 1, 2, 3])
Note
The first signal sample is used as the fill value to move the signal
samples
to the right.
(Source code, html)
You can move the signal samples
by a number of samples to the
left by calling the method move()
with the negative number of
samples the signal samples
shall be moved to the left.
A new Trace
instance labeled with the performed transformation
'move'
is returned.
>>> # move samples by the number of samples to the left
>>> Trace('Signal', [1, 2, 3, 4, 5]).move(-2)
Trace(label='Signal:move', samples=[3, 4, 5, 5, 5])
Note
The last signal sample is used as the fill value to move the signal
samples
to the left.
(Source code, html)
Slice#
You can slice the signal samples
according to the built-in
function slice()
by calling the the method slice()
.
A new Trace
instance labeled with the performed transformation
'slice'
is returned.
>>> # get new trace with all samples
>>> Trace('Signal', [1, 2, 3, 4, 5]).slice()
Trace(label='Signal:slice', samples=[1, 2, 3, 4, 5])
>>> # get new trace with the first sample
>>> Trace('Signal', [1, 2, 3, 4, 5]).slice(1)
Trace(label='Signal:slice', samples=[1])
>>> # get new trace without the last sample
>>> Trace('Signal', [1, 2, 3, 4, 5]).slice(-1)
Trace(label='Signal:slice', samples=[1, 2, 3, 4])
>>> # get new trace with samples between first and last sample
>>> Trace('Signal', [1, 2, 3, 4, 5]).slice(1, -1)
Trace(label='Signal:slice', samples=[2, 3, 4])
>>> # get new trace without the first sample
>>> Trace('Signal', [1, 2, 3, 4, 5]).slice(1, None)
Trace(label='Signal:slice', samples=[2, 3, 4, 5])
>>> # get new trace with the last sample
>>> Trace('Signal', [1, 2, 3, 4, 5]).slice(-1, None)
Trace(label='Signal:slice', samples=[5])
>>> # get new trace with the odd samples
>>> Trace('Signal', [1, 2, 3, 4, 5]).slice(None, None, 2)
Trace(label='Signal:slice', samples=[1, 3, 5])
>>> # get new trace with the even samples
>>> Trace('Signal', [1, 2, 3, 4, 5]).slice(1, None, 2)
Trace(label='Signal:slice', samples=[2, 4])
(Source code, html)