Skip to content

Commit

Permalink
Implement LTIFilter.response
Browse files Browse the repository at this point in the history
  • Loading branch information
mph- committed Dec 8, 2024
1 parent b506786 commit 68c36f2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
Binary file added doc/examples/schematics/L2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions doc/examples/schematics/L2.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
L 1 2; right, inductors/coils=3, purple, thick
1 change: 1 addition & 0 deletions doc/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ The input and output signals can be plotted using::
>>> ax = v_i.plot((-1, 10), label='input')
>>> ax = v_o.plot((-1, 10), axes=ax, label='output')
>>> ax.legend()
>>> # Note, the show() method is not required when using IPython or Jupyter
>>> plt.show()

.. image:: examples/tutorials/basic/VRC2plot.png
Expand Down
3 changes: 3 additions & 0 deletions lcapy/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,9 @@ def convolve(self, x, commutate=False, **assumptions):
If `commutate` is True, swap order of functions in integral.
`taumin` defaults to -oo and `taumax` defaults to oo. These
are relaxed if either or both of the expressions are causal.
The result is an unevaluated integral. It can be evaluated using
the `doit()` method.
Expand Down
23 changes: 13 additions & 10 deletions lcapy/ltifilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .expr import expr, equation, ExprTuple
from .differentialequation import DifferentialEquation
from .functions import Derivative, Function, exp, cos
from .texpr import TimeDomainExpression
from .texpr import texpr
from .transfer import transfer
from .symbols import t, s, omega0, j, pi, f
from .utils import isiterable
Expand Down Expand Up @@ -177,7 +177,7 @@ def sdomain_initial_response(self, ic=None):
from .sym import ssym

if ic is None:
ic = ()
return s * 0

if not isiterable(ic):
ic = (ic, )
Expand Down Expand Up @@ -221,16 +221,19 @@ def initial_response(self, ic=None):
Ysi = self.sdomain_initial_response(ic)
return Ysi(t)

def response(self, x, ic=None, ni=None):
"""Calculate response of filter to input `x` given a list of initial conditions
`ic` for time indexes specified by `ni`. If `ni` is a tuple,
this specifies the first and last (inclusive) time index.
The initial conditions are valid prior to the time indices given by the ni
`x` can be an expression, a sequence, or a list/array of values.
def response(self, x, ic=None, use_time_domain=False):
"""Calculate response of filter to input expression `x` given a list
of initial conditions `ic`.
"""

return 0
x = texpr(x)

if use_time_domain:
return self.impulse_response().convolve(x) + self.initial_response(ic)
else:

Y = self.transfer_function() * x(s) + self.sdomain_initial_response(ic)
return Y(t)

def subs(self, *args, **kwargs):

Expand Down
6 changes: 5 additions & 1 deletion lcapy/sexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ def lti_filter(self, normalize_a0=True):
return LTIFilter.from_transfer_function(self, normalize_a0)

def dlti_filter(self, method='bilinear', alpha=0.5):
"""Create DLTI filter using bilinear transform."""
"""Create DLTI filter using bilinear transform.
See `discretize` for available methods."""

from .transfer import transfer

Expand Down Expand Up @@ -764,6 +766,8 @@ def discretize(self, method=None, alpha=0.5, scale=None):
'backward-diff', 'backward-euler' 'simpson', 'matched-Z',
'zero-pole-matching'
See also `dlti_filter`.
"""

signal = self.is_signal or self.is_squared or self.is_power
Expand Down

0 comments on commit 68c36f2

Please sign in to comment.