Skip to content

Commit 135734a

Browse files
committed
added more documentation on return_magphase per @sawyerbfuller
1 parent afa4967 commit 135734a

File tree

4 files changed

+67
-11
lines changed

4 files changed

+67
-11
lines changed

control/frdata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def __init__(self, *args, **kwargs):
151151
FRD object.
152152
153153
To construct frequency response data for an existing LTI
154-
object, other than an FRD, call FRD(sys, omega)
154+
object, other than an FRD, call FRD(sys, omega).
155155
156156
"""
157157
# TODO: discrete-time FRD systems?

control/lti.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -412,18 +412,21 @@ def frequency_response(sys, omega, squeeze=None):
412412
413413
Returns
414414
-------
415-
mag : ndarray
416-
The magnitude (absolute value, not dB or log10) of the system
417-
frequency response. If the system is SISO and squeeze is not True,
418-
the array is 1D, indexed by frequency. If the system is not SISO or
419-
squeeze is False, the array is 3D, indexed by the output, input, and
415+
response : FrequencyResponseData
416+
Frequency response data object representing the frequency response.
417+
This object can be assigned to a tuple using
418+
419+
mag, phase, omega = response
420+
421+
where ``mag`` is the magnitude (absolute value, not dB or log10) of
422+
the system frequency response, ``phase`` is the wrapped phase in
423+
radians of the system frequency response, and ``omega`` is the
424+
(sorted) frequencies at which the response was evaluated. If the
425+
system is SISO and squeeze is not True, ``magnitude`` and ``phase``
426+
are 1D, indexed by frequency. If the system is not SISO or squeeze
427+
is False, the array is 3D, indexed by the output, input, and
420428
frequency. If ``squeeze`` is True then single-dimensional axes are
421429
removed.
422-
phase : ndarray
423-
The wrapped phase in radians of the system frequency response.
424-
omega : ndarray
425-
The list of sorted frequencies at which the response was
426-
evaluated.
427430
428431
See Also
429432
--------

control/tests/frd_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,34 @@ def test_frequency_response():
532532
np.testing.assert_equal(resp.magnitude, np.abs(eval))
533533
np.testing.assert_equal(resp.phase, np.angle(eval))
534534
np.testing.assert_equal(resp.omega, omega)
535+
536+
# Make sure that we can change the properties of the response
537+
sys = ct.rss(2, 1, 1)
538+
resp_default = ct.frequency_response(sys, omega)
539+
mag_default, phase_default, omega_default = resp_default
540+
assert mag_default.ndim == 1
541+
assert phase_default.ndim == 1
542+
assert omega_default.ndim == 1
543+
assert mag_default.shape[0] == omega_default.shape[0]
544+
assert phase_default.shape[0] == omega_default.shape[0]
545+
546+
resp_nosqueeze = ct.frequency_response(sys, omega, squeeze=False)
547+
mag_nosqueeze, phase_nosqueeze, omega_nosqueeze = resp_nosqueeze
548+
assert mag_nosqueeze.ndim == 3
549+
assert phase_nosqueeze.ndim == 3
550+
assert omega_nosqueeze.ndim == 1
551+
assert mag_nosqueeze.shape[2] == omega_nosqueeze.shape[0]
552+
assert phase_nosqueeze.shape[2] == omega_nosqueeze.shape[0]
553+
554+
# Try changing the response
555+
resp_def_nosq = resp_default(squeeze=False)
556+
mag_def_nosq, phase_def_nosq, omega_def_nosq = resp_def_nosq
557+
assert mag_def_nosq.shape == mag_nosqueeze.shape
558+
assert phase_def_nosq.shape == phase_nosqueeze.shape
559+
assert omega_def_nosq.shape == omega_nosqueeze.shape
560+
561+
resp_nosq_sq = resp_nosqueeze(squeeze=True)
562+
mag_nosq_sq, phase_nosq_sq, omega_nosq_sq = resp_nosq_sq
563+
assert mag_nosq_sq.shape == mag_default.shape
564+
assert phase_nosq_sq.shape == phase_default.shape
565+
assert omega_nosq_sq.shape == omega_default.shape

doc/conventions.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@ FRD systems have a somewhat more limited set of functions that are
7474
available, although all of the standard algebraic manipulations can be
7575
performed.
7676

77+
The FRD class is also used as the return type for the
78+
:func:`frequency_response` function (and the equivalent method for the
79+
:class:`StateSpace` and :class:`TransferFunction` classes). This
80+
object can be assigned to a tuple using
81+
82+
mag, phase, omega = response
83+
84+
where `mag` is the magnitude (absolute value, not dB or log10) of the
85+
system frequency response, `phase` is the wrapped phase in radians of
86+
the system frequency response, and `omega` is the (sorted) frequencies
87+
at which the response was evaluated. If the system is SISO and the
88+
`squeeze` argument to :func:`frequency_response` is not True,
89+
`magnitude` and `phase` are 1D, indexed by frequency. If the system
90+
is not SISO or `squeeze` is False, the array is 3D, indexed by the
91+
output, input, and frequency. If `squeeze` is True then
92+
single-dimensional axes are removed. The processing of the `squeeze`
93+
keyword can be changed by calling the response function with a new
94+
argument:
95+
96+
mag, phase, omega = response(squeeze=False)
97+
98+
7799
Discrete time systems
78100
---------------------
79101
A discrete time system is created by specifying a nonzero 'timebase', dt.

0 commit comments

Comments
 (0)