From: <kk...@us...> - 2011-02-08 22:19:54
|
Revision: 121 http://python-control.svn.sourceforge.net/python-control/?rev=121&view=rev Author: kkchen Date: 2011-02-08 22:19:48 +0000 (Tue, 08 Feb 2011) Log Message: ----------- Added a keyword for plotting and now returning mag/phase/freq etc. for nyquist and nichols. Lauren Padilla <lpa...@pr...> Modified Paths: -------------- branches/control-0.4a/src/freqplot.py Modified: branches/control-0.4a/src/freqplot.py =================================================================== --- branches/control-0.4a/src/freqplot.py 2011-02-08 22:19:44 UTC (rev 120) +++ branches/control-0.4a/src/freqplot.py 2011-02-08 22:19:48 UTC (rev 121) @@ -153,12 +153,12 @@ return mag, phase, omega # Nyquist plot -def nyquist(syslist, omega=None): +def nyquist(syslist, omega=None, Plot=True): """Nyquist plot for a system Usage ===== - magh = nyquist(sys, omega=None) + real, imag, freq = nyquist(sys, omega=None, Plot=True) Plots a Nyquist plot for the system over a (optional) frequency range. @@ -168,10 +168,14 @@ List of linear input/output systems (single system is OK) omega : freq_range Range of frequencies (list or bounds) in rad/sec + Plot : boolean + if True, plot magnitude Return values ------------- - None + real : real part of the frequency response array + imag : imaginary part of the frequency response array + freq : frequencies """ # If argument was a singleton, turn it into a list if (not getattr(syslist, '__iter__', False)): @@ -199,22 +203,25 @@ # Compute the primary curve x = sp.multiply(mag, sp.cos(phase)); y = sp.multiply(mag, sp.sin(phase)); - - # Plot the primary curve and mirror image - plt.plot(x, y, '-'); - plt.plot(x, -y, '--'); - # Mark the -1 point - plt.plot([-1], [0], 'r+') + if (Plot): + # Plot the primary curve and mirror image + plt.plot(x, y, '-'); + plt.plot(x, -y, '--'); + # Mark the -1 point + plt.plot([-1], [0], 'r+') + + return x, y, omega + # Nichols plot # Contributed by Allan McInnes <All...@ca...> #! TODO: need unit test code -def nichols(syslist, omega=None): +def nichols(syslist, omega=None, Plot=True): """Nichols plot for a system Usage ===== - magh = nichols(sys, omega=None) + mag, phase, freq = nichols(sys, omega=None, Plot=True) Plots a Nichols plot for the system over a (optional) frequency range. @@ -224,10 +231,15 @@ List of linear input/output systems (single system is OK) omega : freq_range Range of frequencies (list or bounds) in rad/sec + Plot : boolean + if True, plot the Nichols frequency response Return values ------------- - None + mag : array of magnitudes + phase : array of phases + freq : array of frequencies + """ # If argument was a singleton, turn it into a list @@ -254,16 +266,19 @@ x = unwrap(sp.degrees(phase), 360) y = 20*sp.log10(mag) - # Generate the plot - plt.plot(x, y) + if (Plot): + # Generate the plot + plt.plot(x, y) - plt.xlabel('Phase (deg)') - plt.ylabel('Magnitude (dB)') - plt.title('Nichols Plot') + plt.xlabel('Phase (deg)') + plt.ylabel('Magnitude (dB)') + plt.title('Nichols Plot') - # Mark the -180 point - plt.plot([-180], [0], 'r+') + # Mark the -180 point + plt.plot([-180], [0], 'r+') + return mag, phase, omega + # Gang of Four #! TODO: think about how (and whether) to handle lists of systems def gangof4(P, C, omega=None): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |