lcapy.sequence.Sequence

class lcapy.sequence.Sequence(seq, ni=None, origin=None, evaluate=False, var=None, start_trunc=False, end_trunc=False)

Bases: ExprList, SeqDomain

Methods

DTFT([var])

Convert to Fourier domain using discrete time Fourier transform.

__init__(seq[, ni, origin, evaluate, var, ...])

Sequences can be created from an tuple, list, or ndarray.

append(x)

Concatenate with sequence x.

as_array()

Numerically evaluate and store as NumPy array.

as_impulses([var])

Convert to discrete-time signal in the form of a weighted sum of delayed impulses.

convolve(h[, mode])

Convolve with h.

copy()

Return a shallow copy of the list.

delay([m])

Return a new sequence delayed by an integer number of samples m.

discrete_time_fourier_transform([var])

Convert to Fourier domain using discrete time Fourier transform.

evaluate([ni])

Evaluate expression at sequence indices specified by arg.

lfilter([b, a])

Implement digital filter specified by a transfer function.

plot([ni])

Plot the sequence.

pretty(**kwargs)

Make pretty string.

prune()

Remove zeros from ends of sequence.

repeat(x)

Repeat sequence x times.

truncate(size)

Truncate sequence length to size samples.

zeroextend()

Extend sequence by adding zeros so that the origin is included.

zeropad(M)

Add M zeros to end of sequence:

Attributes

expr

Convert sequence to an Lcapy expression.

extent

Determine extent of the sequence.

is_sequence

isempty

True if empty sequence (zero).

origin

Return the element index for n == 0.

quantity

vals

Return the SymPy values as a list.

var

DTFT(var=None, **assumptions)

Convert to Fourier domain using discrete time Fourier transform.

append(x)

Concatenate with sequence x.

as_array()

Numerically evaluate and store as NumPy array.

as_impulses(var=None)

Convert to discrete-time signal in the form of a weighted sum of delayed impulses. For example, {1, 2, 3} -> ui[n] + 2 * ui[n - 1] + 3 * ui[n - 2]

convolve(h, mode='full')

Convolve with h.

copy()

Return a shallow copy of the list.

delay(m=0)

Return a new sequence delayed by an integer number of samples m. If m is negative, the sequence is advanced.

discrete_time_fourier_transform(var=None, **assumptions)

Convert to Fourier domain using discrete time Fourier transform.

evaluate(ni=None)

Evaluate expression at sequence indices specified by arg. arg may be a scalar or a vector. The result is of type float or complex. Zeroes are returned for indices outside the sequence extent.

If arg is iterable, a NumPy array is returned.

property expr

Convert sequence to an Lcapy expression.

property extent

Determine extent of the sequence.

For example, Sequence([1, 1]).extent = 2

Sequence([1, 0, 1]).extent = 3 Sequence([0, 1, 0, 1]).extent = 3

property isempty

True if empty sequence (zero).

lfilter(b=None, a=None)

Implement digital filter specified by a transfer function. The transfer function is described by a vector b of coefficients for the numerator and an a vector of coefficients for the denominator.

If you would like the response with initial conditions see DTfilter.response().

For a FIR filter a = [1].

property origin

Return the element index for n == 0. This may raise a ValueError if the origin is not in the sequence.

plot(ni=None, **kwargs)

Plot the sequence. If ni is not specified, it defaults to the sequence indices. ni can be a vector of specified sequence indices, a tuple specifing the range, or a constant specifying the maximum value with the minimum value set to 0.

kwargs include: axes - the plot axes to use otherwise a new figure is created xlabel - the x-axis label ylabel - the y-axis label xscale - the x-axis scaling, say for plotting as ms yscale - the y-axis scaling, say for plotting mV unfilled - the markers are unfilled markersize - sets the size of the marker markerfacecolor - sets the marker color in addition to those supported by the matplotlib plot command.

The plot axes are returned.

pretty(**kwargs)

Make pretty string.

prune()

Remove zeros from ends of sequence.

{0, 0, 1, 2, 3, 0} -> {1, 2, 3}

repeat(x)

Repeat sequence x times.

seq((1, 2, 3)).repeat(2) gives {1, 2, 3, 1, 2, 3}

truncate(size)

Truncate sequence length to size samples.

property vals

Return the SymPy values as a list.

zeroextend()

Extend sequence by adding zeros so that the origin is included. This is used for printing.

zeropad(M)

Add M zeros to end of sequence:

For example, with M = 3

{1, 2, 3} -> {1, 2, 3, 0, 0, 0}