Skip to content

Commit aeba73c

Browse files
committed
Move tf, ss2tf, etc into xferfcn module
1 parent 5cf3e02 commit aeba73c

3 files changed

Lines changed: 190 additions & 218 deletions

File tree

control/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
from .statesp import *
6464
from .timeresp import forced_response, initial_response, step_response, \
6565
impulse_response
66-
from .xferfcn import TransferFunction
66+
from .xferfcn import *
6767
from .ctrlutil import *
6868
from .frdata import FRD
6969
from .canonical import canonical_form, reachable_form
@@ -86,7 +86,6 @@
8686
#! of defaults from the main package. At that point, the matlab module will
8787
#! allow provide compatibility with MATLAB but no package functionality.
8888
#!
89-
from .matlab import tf, ss2tf
9089
from .matlab import pole, zero, evalfr, freqresp, dcgain
9190
from .matlab import nichols, rlocus, margin
9291
# bode and nyquist come directly from freqplot.py

control/matlab/__init__.py

Lines changed: 1 addition & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
from .. import timeresp
7979
from .. import margins
8080
from ..statesp import *
81-
from ..xferfcn import TransferFunction, _convertToTransferFunction
81+
from ..xferfcn import *
8282
from ..lti import LTI # base class of StateSpace, TransferFunction
8383
from ..lti import issiso
8484
from ..frdata import FRD
@@ -388,97 +388,6 @@
388388
"""
389389

390390

391-
def tf(*args):
392-
"""
393-
Create a transfer function system. Can create MIMO systems.
394-
395-
The function accepts either 1 or 2 parameters:
396-
397-
``tf(sys)``
398-
Convert a linear system into transfer function form. Always creates
399-
a new system, even if sys is already a TransferFunction object.
400-
401-
``tf(num, den)``
402-
Create a transfer function system from its numerator and denominator
403-
polynomial coefficients.
404-
405-
If `num` and `den` are 1D array_like objects, the function creates a
406-
SISO system.
407-
408-
To create a MIMO system, `num` and `den` need to be 2D nested lists
409-
of array_like objects. (A 3 dimensional data structure in total.)
410-
(For details see note below.)
411-
412-
``tf(num, den, dt)``
413-
Create a discrete time transfer function system; dt can either be a
414-
positive number indicating the sampling time or 'True' if no
415-
specific timebase is given.
416-
417-
Parameters
418-
----------
419-
sys: LTI (StateSpace or TransferFunction)
420-
A linear system
421-
num: array_like, or list of list of array_like
422-
Polynomial coefficients of the numerator
423-
den: array_like, or list of list of array_like
424-
Polynomial coefficients of the denominator
425-
426-
Returns
427-
-------
428-
out: :class:`TransferFunction`
429-
The new linear system
430-
431-
Raises
432-
------
433-
ValueError
434-
if `num` and `den` have invalid or unequal dimensions
435-
TypeError
436-
if `num` or `den` are of incorrect type
437-
438-
See Also
439-
--------
440-
ss
441-
ss2tf
442-
tf2ss
443-
444-
Notes
445-
--------
446-
447-
``num[i][j]`` contains the polynomial coefficients of the numerator
448-
for the transfer function from the (j+1)st input to the (i+1)st output.
449-
``den[i][j]`` works the same way.
450-
451-
The list ``[2, 3, 4]`` denotes the polynomial :math:`2s^2 + 3s + 4`.
452-
453-
Examples
454-
--------
455-
>>> # Create a MIMO transfer function object
456-
>>> # The transfer function from the 2nd input to the 1st output is
457-
>>> # (3s + 4) / (6s^2 + 5s + 4).
458-
>>> num = [[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]]
459-
>>> den = [[[9., 8., 7.], [6., 5., 4.]], [[3., 2., 1.], [-1., -2., -3.]]]
460-
>>> sys1 = tf(num, den)
461-
462-
>>> # Convert a StateSpace to a TransferFunction object.
463-
>>> sys_ss = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
464-
>>> sys2 = tf(sys1)
465-
466-
"""
467-
468-
if len(args) == 2 or len(args) == 3:
469-
return TransferFunction(*args)
470-
elif len(args) == 1:
471-
sys = args[0]
472-
if isinstance(sys, StateSpace):
473-
return ss2tf(sys)
474-
elif isinstance(sys, TransferFunction):
475-
return deepcopy(sys)
476-
else:
477-
raise TypeError("tf(sys): sys must be a StateSpace or \
478-
TransferFunction object. It is %s." % type(sys))
479-
else:
480-
raise ValueError("Needs 1 or 2 arguments; received %i." % len(args))
481-
482391
def frd(*args):
483392
'''
484393
Construct a Frequency Response Data model, or convert a system
@@ -516,81 +425,6 @@ def frd(*args):
516425
return FRD(*args)
517426

518427

519-
def ss2tf(*args):
520-
"""
521-
Transform a state space system to a transfer function.
522-
523-
The function accepts either 1 or 4 parameters:
524-
525-
``ss2tf(sys)``
526-
Convert a linear system into space system form. Always creates a
527-
new system, even if sys is already a StateSpace object.
528-
529-
``ss2tf(A, B, C, D)``
530-
Create a state space system from the matrices of its state and
531-
output equations.
532-
533-
For details see: :func:`ss`
534-
535-
Parameters
536-
----------
537-
sys: StateSpace
538-
A linear system
539-
A: array_like or string
540-
System matrix
541-
B: array_like or string
542-
Control matrix
543-
C: array_like or string
544-
Output matrix
545-
D: array_like or string
546-
Feedthrough matrix
547-
548-
Returns
549-
-------
550-
out: TransferFunction
551-
New linear system in transfer function form
552-
553-
Raises
554-
------
555-
ValueError
556-
if matrix sizes are not self-consistent, or if an invalid number of
557-
arguments is passed in
558-
TypeError
559-
if `sys` is not a StateSpace object
560-
561-
See Also
562-
--------
563-
tf
564-
ss
565-
tf2ss
566-
567-
Examples
568-
--------
569-
>>> A = [[1., -2], [3, -4]]
570-
>>> B = [[5.], [7]]
571-
>>> C = [[6., 8]]
572-
>>> D = [[9.]]
573-
>>> sys1 = ss2tf(A, B, C, D)
574-
575-
>>> sys_ss = ss(A, B, C, D)
576-
>>> sys2 = ss2tf(sys_ss)
577-
578-
"""
579-
580-
if len(args) == 4 or len(args) == 5:
581-
# Assume we were given the A, B, C, D matrix and (optional) dt
582-
return _convertToTransferFunction(StateSpace(*args))
583-
584-
elif len(args) == 1:
585-
sys = args[0]
586-
if isinstance(sys, StateSpace):
587-
return _convertToTransferFunction(sys)
588-
else:
589-
raise TypeError("ss2tf(sys): sys must be a StateSpace object. It \
590-
is %s." % type(sys))
591-
else:
592-
raise ValueError("Needs 1 or 4 arguments; received %i." % len(args))
593-
594428

595429
def pole(sys):
596430
"""
@@ -1204,24 +1038,6 @@ def lsim(sys, U=0., T=None, X0=0.):
12041038
T, yout, xout = timeresp.forced_response(sys, T, U, X0, transpose = True)
12051039
return yout, T, xout
12061040

1207-
def tfdata(sys):
1208-
'''
1209-
Return transfer function data objects for a system
1210-
1211-
Parameters
1212-
----------
1213-
sys: LTI (StateSpace, or TransferFunction)
1214-
LTI system whose data will be returned
1215-
1216-
Returns
1217-
-------
1218-
(num, den): numerator and denominator arrays
1219-
Transfer function coefficients (SISO only)
1220-
'''
1221-
tf = _convertToTransferFunction(sys)
1222-
1223-
return (tf.num, tf.den)
1224-
12251041
# Convert a continuous time system to a discrete time system
12261042
def c2d(sysc, Ts, method='zoh'):
12271043
'''

0 commit comments

Comments
 (0)