5454#
5555
5656# Bode plot
57- def bode (syslist , omega = None , dB = False , Hz = False , color = None ):
57+ def bode (syslist , omega = None , dB = False , Hz = False , color = None , Plot = True ):
5858 """Bode plot for a system
5959
6060 Usage
6161 =====
62- (magh, phaseh) = bode(syslist, omega=None, dB=False, Hz=False)
62+ (magh, phaseh, omega ) = bode(syslist, omega=None, dB=False, Hz=False, color=None, Plot=True )
6363
6464 Plots a Bode plot for the system over a (optional) frequency range.
6565
@@ -73,16 +73,18 @@ def bode(syslist, omega=None, dB=False, Hz=False, color=None):
7373 If True, plot result in dB
7474 Hz : boolean
7575 If True, plot frequency in Hz (omega must be provided in rad/sec)
76+ Plot : boolean
77+ If True, plot magnitude and phase
7678
7779 Return values
7880 -------------
79- magh : graphics handle to magnitude plot (for rescaling, etc)
80- phaseh : graphics handle to phase plot
81+ magh : magnitude array
82+ phaseh : phase array
83+ omega : frequency array
8184
8285 Notes
8386 -----
84- 1. Use (mag, phase, freq) = sys.freqresp(freq) to generate the
85- frequency response for a system.
87+ 1. Alternatively, may use (mag, phase, freq) = sys.freqresp(freq) to generate the frequency response for a system.
8688 """
8789 # If argument was a singleton, turn it into a list
8890 if (not getattr (syslist , '__iter__' , False )):
@@ -108,46 +110,47 @@ def bode(syslist, omega=None, dB=False, Hz=False, color=None):
108110 # Get the dimensions of the current axis, which we will divide up
109111 #! TODO: Not current implemented; just use subplot for now
110112
111- # Magnitude plot
112- plt .subplot (211 );
113- if dB :
114- if color == None :
115- plt .semilogx (omega , mag )
113+ if (Plot ):
114+ # Magnitude plot
115+ plt .subplot (211 );
116+ if dB :
117+ if color == None :
118+ plt .semilogx (omega , mag )
119+ else :
120+ plt .semilogx (omega , mag , color = color )
121+ plt .ylabel ("Magnitude (dB)" )
116122 else :
117- plt .semilogx (omega , mag , color = color )
118- plt .ylabel ("Magnitude (dB)" )
119- else :
123+ if color == None :
124+ plt .loglog (omega , mag )
125+ else :
126+ plt .loglog (omega , mag , color = color )
127+ plt .ylabel ("Magnitude" )
128+
129+ # Add a grid to the plot
130+ plt .grid (True )
131+ plt .grid (True , which = 'minor' )
132+ plt .hold (True );
133+
134+ # Phase plot
135+ plt .subplot (212 );
120136 if color == None :
121- plt .loglog (omega , mag )
122- else :
123- plt .loglog (omega , mag , color = color )
124- plt .ylabel ("Magnitude" )
125-
126- # Add a grid to the plot
127- plt .grid (True )
128- plt .grid (True , which = 'minor' )
129- plt .hold (True );
130-
131- # Phase plot
132- plt .subplot (212 );
133- if color == None :
134- plt .semilogx (omega , phase )
135- else :
136- plt .semilogx (omega , phase , color = color )
137- plt .hold (True )
138-
139- # Add a grid to the plot
140- plt .grid (True )
141- plt .grid (True , which = 'minor' )
142- plt .ylabel ("Phase (deg)" )
143-
144- # Label the frequency axis
145- if Hz :
146- plt .xlabel ("Frequency (Hz)" )
147- else :
148- plt .xlabel ("Frequency (rad/sec)" )
149-
150- return (211 , 212 )
137+ plt .semilogx (omega , phase )
138+ else :
139+ plt .semilogx (omega , phase , color = color )
140+ plt .hold (True )
141+
142+ # Add a grid to the plot
143+ plt .grid (True )
144+ plt .grid (True , which = 'minor' )
145+ plt .ylabel ("Phase (deg)" )
146+
147+ # Label the frequency axis
148+ if Hz :
149+ plt .xlabel ("Frequency (Hz)" )
150+ else :
151+ plt .xlabel ("Frequency (rad/sec)" )
152+
153+ return mag , phase , omega
151154
152155# Nyquist plot
153156def nyquist (syslist , omega = None ):
0 commit comments