-
Notifications
You must be signed in to change notification settings - Fork 438
Update frequency response plots to use _response/_plot pattern #924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
8a4b6c1
to
c383014
Compare
Just a few quick thoughts/comments, I may have more late if/when I have a chance to test it. Overall this seems to be very much in the spirit of the original discussion and will fix some oddities as well as making mimo plots easier to work with. I think breaking code that does Clever idea for how to handle lists of responses. Is this considered a legit pythonic way to do that? |
plot=True, omega_limits=None, omega_num=None, | ||
margins=None, method='best', *args, **kwargs): | ||
def bode_plot( | ||
data, omega=None, *fmt, ax=None, omega_limits=None, omega_num=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be the time to deprecate omega
, omega_limits
, and omega_num
in favor of the more general frequency
,frequency_limits
, and frequency_num
given that omega suggests rad/s even though these are specified in either rad/s or hz depending on the defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: looking elsewhere, sticking with omega
may make more sense for nyquist and nichols. not sure about bode yet. Would be nice to be able to specify ranges in Hz for the bode plot though - was this a feature before?
This is looking good and fixes some long-standing bugs/cobwebs. A few comments/questions, some of which I might be able to answer by deeply looking into the code, but I a quick reply giving the high level thinking might be very informative:
|
I think so. It is allows to use
This is worth thinking about. I find the
Yes. All of the plots keep track of the type of command that generated them and then call the appropriate Regarding the frequency points/ranges: these are different for Bode and Nyquist. A Bode plot uses the frequency response, which evaluates an LTI system on the positive imaginary axis. A Nyquist plot evaluates the response along the Nyquist "D" contour. So these are not exactly interchangeable (more below).
Yes, but not for Bode and Nyquist, since those are actually different responses. Here's a summary of various things that work:
Agree.
Those changes are all in the main branch now (via #534). I'll leave this open for a bit longer in case others have comments, but looks to me like this is OK to merge, with a later PR for thinking through improving |
8467f14
to
8e84d00
Compare
This PR updates frequency response plots to use the _response/_plot calling pattern described in #645. For Bode, Nichols, and singular values plots, the following patterns will work:
There are also updates to
gangof4_response/plot
andnyquist_response/plot
.Everything is mostly backwards compatible except that the outputs from a _plot function are now an array of Line2D objects instead of other information (mag/phase/frequency, counts, etc). You can still get the original data using the _response function and there is some legacy processing if you used the
plot
keyword (eg,plot=False
) to try let some code work without changes.The changes to Nyquist plots are illustrative of where code might break. Before, you could do this:
to get both a Nyquist plot and a count of the number of encirclements. That will no longer work, since
nyquist_plot
returns an array of lines. Instead, you need to do thisThere are also some changes when you pass a list of systems. Before, you would say
This no longer works because nyquist_response returns a list of responses (one response for each system). In the new version, you say
Note that even though
nyquist_response
is returning a list of responses, you can still sayresponses.plot()
to get the (single) Nyquist plot for the list of systems (with different systems in different colors). This (and similar functionality forfrequency_response
/bode_plot
) works through returning a specialNyquistResponseList
object (FrequencyResponseList
forfrequency_response
) that extends the Pythonlist
data type and adds aplot
method).Summary of changes:
_response
functions and a_plot
function. You can access the latter via the.plot()
method on the response._response
function or a list of systems (in which case the_response
function is called internally). This allows the common pattern ofbode_plot(sys)
,nyquist_plot(sys)
to work as expected.plot_type
keyword in theplot
method (soct.frequency_response(sys).plot(plot_type='nichols')
will work).ct.singular_values_plot(sys).plot()
generates a singular values plot, not a Bode plot).bode
,nyquist
, andnichols
are still there.control.matlab
version ofbode
returnsmag, phase, freq
(compatible with MATLAB)Plot
andlabelFreq
keywords).This PR is going to break existing code. It would be great if a few people could try this out so that we can make sure we are OK with the changes here. There are still a few things I am implementing (see top of
freqplot.py
) so I'll leave this in draft mode for a bit, but wanted to start getting feedback on the changes, since they are pretty substantial.Examples (from the user documentation):
Linear time invariant (LTI) systems can be analyzed in terms of their frequency response and python-control provides a variety of tools for carrying out frequency response analysis. The most basic of these is the
frequency_response
function, which will compute the frequency response for one or more linear systems:A Bode plot provide a graphical view of the response an LTI system and can be generated using the
bode_plot
function:Computing the response for multiple systems at the same time yields a common frequency range that covers the features of all listed systems.
Bode plots can also be created directly using the
FrequencyResponseData.plot
method:A variety of options are available for customizing Bode plots, for example allowing the display of the phase to be turned off or overlaying the inputs or outputs:
The
singular_values_response
function can be used to generate Bode plots that show the singular values of a transfer function:Different types of plots can also be specified for a given frequency response. For example, to plot the frequency response using a a Nichols plot, use
plot_type='nichols'
:Another response function that can be used to generate Bode plots is the :func:
gangof4
function, which computes the four primary sensitivity functions for a feedback control system in standard form: