Skip to content

Commit 456fcaf

Browse files
committed
Move pole, zero, evalfr, freqresp to lti module
1 parent 1b9070a commit 456fcaf

3 files changed

Lines changed: 166 additions & 165 deletions

File tree

control/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@
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 pole, zero, evalfr, freqresp, dcgain
89+
from .matlab import dcgain
9090
from .matlab import nichols, rlocus, margin
9191
# bode and nyquist come directly from freqplot.py
9292
from .matlab import step, impulse, initial, lsim
93-
from .matlab import ssdata, tfdata
9493

9594
# The following is to use Numpy's testing framework
9695
# Tests go under directory tests/, benchmarks under directory benchmarks/

control/lti.py

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
from numpy import absolute, real
1616

17+
__all__ = ['issiso', 'timebase', 'timebaseEqual', 'isdtime', 'isctime',
18+
'pole', 'zero', 'evalfr', 'freqresp']
19+
1720
class LTI:
1821
"""LTI is a parent class to linear time-invariant (LTI) system objects.
1922
@@ -189,3 +192,164 @@ def isctime(sys, strict=False):
189192

190193
# Got passed something we don't recognize
191194
return False
195+
196+
def pole(sys):
197+
"""
198+
Compute system poles.
199+
200+
Parameters
201+
----------
202+
sys: StateSpace or TransferFunction
203+
Linear system
204+
205+
Returns
206+
-------
207+
poles: ndarray
208+
Array that contains the system's poles.
209+
210+
Raises
211+
------
212+
NotImplementedError
213+
when called on a TransferFunction object
214+
215+
See Also
216+
--------
217+
zero
218+
219+
Notes
220+
-----
221+
This function is a wrapper for StateSpace.pole and
222+
TransferFunction.pole.
223+
224+
"""
225+
226+
return sys.pole()
227+
228+
229+
def zero(sys):
230+
"""
231+
Compute system zeros.
232+
233+
Parameters
234+
----------
235+
sys: StateSpace or TransferFunction
236+
Linear system
237+
238+
Returns
239+
-------
240+
zeros: ndarray
241+
Array that contains the system's zeros.
242+
243+
Raises
244+
------
245+
NotImplementedError
246+
when called on a TransferFunction object or a MIMO StateSpace object
247+
248+
See Also
249+
--------
250+
pole
251+
252+
Notes
253+
-----
254+
This function is a wrapper for StateSpace.zero and
255+
TransferFunction.zero.
256+
257+
"""
258+
259+
return sys.zero()
260+
261+
def evalfr(sys, x):
262+
"""
263+
Evaluate the transfer function of an LTI system for a single complex
264+
number x.
265+
266+
To evaluate at a frequency, enter x = omega*j, where omega is the
267+
frequency in radians
268+
269+
Parameters
270+
----------
271+
sys: StateSpace or TransferFunction
272+
Linear system
273+
x: scalar
274+
Complex number
275+
276+
Returns
277+
-------
278+
fresp: ndarray
279+
280+
See Also
281+
--------
282+
freqresp
283+
bode
284+
285+
Notes
286+
-----
287+
This function is a wrapper for StateSpace.evalfr and
288+
TransferFunction.evalfr.
289+
290+
Examples
291+
--------
292+
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
293+
>>> evalfr(sys, 1j)
294+
array([[ 44.8-21.4j]])
295+
>>> # This is the transfer function matrix evaluated at s = i.
296+
297+
.. todo:: Add example with MIMO system
298+
"""
299+
if issiso(sys):
300+
return sys.horner(x)[0][0]
301+
return sys.horner(x)
302+
303+
def freqresp(sys, omega):
304+
"""
305+
Frequency response of an LTI system at multiple angular frequencies.
306+
307+
Parameters
308+
----------
309+
sys: StateSpace or TransferFunction
310+
Linear system
311+
omega: array_like
312+
List of frequencies
313+
314+
Returns
315+
-------
316+
mag: ndarray
317+
phase: ndarray
318+
omega: list, tuple, or ndarray
319+
320+
See Also
321+
--------
322+
evalfr
323+
bode
324+
325+
Notes
326+
-----
327+
This function is a wrapper for StateSpace.freqresp and
328+
TransferFunction.freqresp. The output omega is a sorted version of the
329+
input omega.
330+
331+
Examples
332+
--------
333+
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
334+
>>> mag, phase, omega = freqresp(sys, [0.1, 1., 10.])
335+
>>> mag
336+
array([[[ 58.8576682 , 49.64876635, 13.40825927]]])
337+
>>> phase
338+
array([[[-0.05408304, -0.44563154, -0.66837155]]])
339+
340+
.. todo::
341+
Add example with MIMO system
342+
343+
#>>> sys = rss(3, 2, 2)
344+
#>>> mag, phase, omega = freqresp(sys, [0.1, 1., 10.])
345+
#>>> mag[0, 1, :]
346+
#array([ 55.43747231, 42.47766549, 1.97225895])
347+
#>>> phase[1, 0, :]
348+
#array([-0.12611087, -1.14294316, 2.5764547 ])
349+
#>>> # This is the magnitude of the frequency response from the 2nd
350+
#>>> # input to the 1st output, and the phase (in radians) of the
351+
#>>> # frequency response from the 1st input to the 2nd output, for
352+
#>>> # s = 0.1i, i, 10i.
353+
"""
354+
355+
return sys.freqresp(omega)

control/matlab/__init__.py

Lines changed: 1 addition & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
from .. import margins
8080
from ..statesp import *
8181
from ..xferfcn import *
82-
from ..lti import issiso
82+
from ..lti import *
8383
from ..frdata import *
8484
from ..dtime import sample_system
8585
from ..exception import ControlArgument
@@ -387,168 +387,6 @@
387387
388388
"""
389389

390-
391-
def pole(sys):
392-
"""
393-
Compute system poles.
394-
395-
Parameters
396-
----------
397-
sys: StateSpace or TransferFunction
398-
Linear system
399-
400-
Returns
401-
-------
402-
poles: ndarray
403-
Array that contains the system's poles.
404-
405-
Raises
406-
------
407-
NotImplementedError
408-
when called on a TransferFunction object
409-
410-
See Also
411-
--------
412-
zero
413-
414-
Notes
415-
-----
416-
This function is a wrapper for StateSpace.pole and
417-
TransferFunction.pole.
418-
419-
"""
420-
421-
return sys.pole()
422-
423-
def zero(sys):
424-
"""
425-
Compute system zeros.
426-
427-
Parameters
428-
----------
429-
sys: StateSpace or TransferFunction
430-
Linear system
431-
432-
Returns
433-
-------
434-
zeros: ndarray
435-
Array that contains the system's zeros.
436-
437-
Raises
438-
------
439-
NotImplementedError
440-
when called on a TransferFunction object or a MIMO StateSpace object
441-
442-
See Also
443-
--------
444-
pole
445-
446-
Notes
447-
-----
448-
This function is a wrapper for StateSpace.zero and
449-
TransferFunction.zero.
450-
451-
"""
452-
453-
return sys.zero()
454-
455-
def evalfr(sys, x):
456-
"""
457-
Evaluate the transfer function of an LTI system for a single complex
458-
number x.
459-
460-
To evaluate at a frequency, enter x = omega*j, where omega is the
461-
frequency in radians
462-
463-
Parameters
464-
----------
465-
sys: StateSpace or TransferFunction
466-
Linear system
467-
x: scalar
468-
Complex number
469-
470-
Returns
471-
-------
472-
fresp: ndarray
473-
474-
See Also
475-
--------
476-
freqresp
477-
bode
478-
479-
Notes
480-
-----
481-
This function is a wrapper for StateSpace.evalfr and
482-
TransferFunction.evalfr.
483-
484-
Examples
485-
--------
486-
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
487-
>>> evalfr(sys, 1j)
488-
array([[ 44.8-21.4j]])
489-
>>> # This is the transfer function matrix evaluated at s = i.
490-
491-
.. todo:: Add example with MIMO system
492-
"""
493-
if issiso(sys):
494-
return sys.horner(x)[0][0]
495-
return sys.horner(x)
496-
497-
498-
def freqresp(sys, omega):
499-
"""
500-
Frequency response of an LTI system at multiple angular frequencies.
501-
502-
Parameters
503-
----------
504-
sys: StateSpace or TransferFunction
505-
Linear system
506-
omega: array_like
507-
List of frequencies
508-
509-
Returns
510-
-------
511-
mag: ndarray
512-
phase: ndarray
513-
omega: list, tuple, or ndarray
514-
515-
See Also
516-
--------
517-
evalfr
518-
bode
519-
520-
Notes
521-
-----
522-
This function is a wrapper for StateSpace.freqresp and
523-
TransferFunction.freqresp. The output omega is a sorted version of the
524-
input omega.
525-
526-
Examples
527-
--------
528-
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
529-
>>> mag, phase, omega = freqresp(sys, [0.1, 1., 10.])
530-
>>> mag
531-
array([[[ 58.8576682 , 49.64876635, 13.40825927]]])
532-
>>> phase
533-
array([[[-0.05408304, -0.44563154, -0.66837155]]])
534-
535-
.. todo::
536-
Add example with MIMO system
537-
538-
#>>> sys = rss(3, 2, 2)
539-
#>>> mag, phase, omega = freqresp(sys, [0.1, 1., 10.])
540-
#>>> mag[0, 1, :]
541-
#array([ 55.43747231, 42.47766549, 1.97225895])
542-
#>>> phase[1, 0, :]
543-
#array([-0.12611087, -1.14294316, 2.5764547 ])
544-
#>>> # This is the magnitude of the frequency response from the 2nd
545-
#>>> # input to the 1st output, and the phase (in radians) of the
546-
#>>> # frequency response from the 1st input to the 2nd output, for
547-
#>>> # s = 0.1i, i, 10i.
548-
"""
549-
550-
return sys.freqresp(omega)
551-
552390
# Bode plots
553391
def bode(*args, **keywords):
554392
"""Bode plot of the frequency response

0 commit comments

Comments
 (0)