Documentation

bode

Bode plot of frequency response, magnitude and phase of frequency response

Syntax

bode(sys)
bode(sys1,...,sysN)
bode(sys1,PlotStyle1,...,sysN,PlotStyleN)
bode(...,w)
[mag,phase] = bode(sys,w)
[mag,phase,wout] = bode(sys)
[mag,phase,wout,sdmag,sdphase] = bode(sys)

Description

bode(sys) creates a Bode plot of the frequency response of a dynamic system model sys. The plot displays the magnitude (in dB) and phase (in degrees) of the system response as a function of frequency.

When sys is a multi-input, multi-output (MIMO) model, bode produces an array of Bode plots, each plot showing the frequency response of one I/O pair.

bode automatically determines the plot frequency range based on system dynamics.

bode(sys1,...,sysN) plots the frequency response of multiple dynamic systems in a single figure. All systems must have the same number of inputs and outputs.

bode(sys1,PlotStyle1,...,sysN,PlotStyleN) plots system responses using the color, linestyle, and markers specified by the PlotStyle strings.

bode(...,w) plots system responses at frequencies determined by w.

  • If w is a cell array {wmin,wmax}, bode(sys,w) plots the system response at frequency values in the range {wmin,wmax}.

  • If w is a vector of frequencies, bode(sys,w) plots the system response at each of the frequencies specified in w.

[mag,phase] = bode(sys,w) returns magnitudes mag in absolute units and phase values phase in degrees. The response values in mag and phase correspond to the frequencies specified by w as follows:

  • If w is a cell array {wmin,wmax}, [mag,phase] = bode(sys,w) returns the system response at frequency values in the range {wmin,wmax}.

  • If w is a vector of frequencies, [mag,phase] = bode(sys,w) returns the system response at each of the frequencies specified in w.

[mag,phase,wout] = bode(sys) returns magnitudes, phase values, and frequency values wout corresponding to bode(sys).

[mag,phase,wout,sdmag,sdphase] = bode(sys) additionally returns the estimated standard deviation of the magnitude and phase values when sys is an identified model and [] otherwise.

Input Arguments

sys

Dynamic system model, such as a Numeric LTI model, or an array of such models.

PlotStyle

Line style, marker, and color of both the line and marker, specified as a one-, two-, or three-part string enclosed in single quotes (' '). The elements of the string can appear in any order. The string can specify only the line style, the marker, or the color.

For more information about configuring the PlotStyle string, see Specify Line Style, Color, and Markers in the MATLAB® documentation.

w

Input frequency values, specified as a row vector or a two-element cell array.

Possible values of w:

  • Two-element cell array {wmin,wmax}, where wmin is the minimum frequency value and wmax is the maximum frequency value.

  • Row vector of frequency values.

    For example, use logspace to generate a row vector with logarithmically-spaced frequency values.

Specify frequency values in radians per TimeUnit, where TimeUnit is the time units of the input dynamic system, specified in the TimeUnit property of sys.

Output Arguments

mag

Bode magnitude of the system response in absolute units, returned as a 3-D array with dimensions (number of outputs) × (number of inputs) × (number of frequency points).

  • For a single-input, single-output (SISO) sys, mag(1,1,k) gives the magnitude of the response at the kth frequency.

  • For MIMO systems, mag(i,j,k) gives the magnitude of the response from the jth input to the ith output.

You can convert the magnitude from absolute units to decibels using:

magdb = 20*log10(mag)

phase

Phase of the system response in degrees, returned as a 3-D array with dimensions are (number of outputs) × (number of inputs) × (number of frequency points).

  • For SISO sys, phase(1,1,k) gives the phase of the response at the kth frequency.

  • For MIMO systems, phase(i,j,k) gives the phase of the response from the jth input to the ith output.

wout

Response frequencies, returned as a row vector of frequency points. Frequency values are in radians per TimeUnit, where TimeUnit is the value of the TimeUnit property of sys.

sdmag

Estimated standard deviation of the magnitude. sdmag has the same dimensions as mag.

If sys is not an identified LTI model, sdmag is [].

sdphase

Estimated standard deviation of the phase. sdphase has the same dimensions as phase.

If sys is not an identified LTI model, sdphase is [].

Examples

Bode Plot of Dynamic System

Create a Bode plot of the following continuous-time SISO dynamic system.

$$H(s) = \frac{{{s^2} + 0.1s + 7.5}}{{{s^4} + 0.12{s^3} + 9{s^2}}}.$$

H = tf([1 0.1 7.5],[1 0.12 9 0 0]);
bode(H)

bode automatically selects the plot range based on the system dynamics.

Bode Plot at Specified Frequencies

Create a Bode plot over a specified frequency range. Use this approach when you want to focus on the dynamics in a particular range of frequencies.

H = tf([1 0.1 7.5],[1 0.12 9 0 0]);
bode(H,{0.1,10})

The cell array {0.1,10} specifies the minimum and maximum frequency values in the Bode plot. When you provide frequency bounds in this way, the software selects intermediate points for frequency response data.

Alternatively, specify a vector of frequency points to use for evaluating and plotting the frequency response.

w = logspace(-1,1,100);
bode(H,w)

logspace defines a logarithmically spaced frequency vector in the range of 0.1-10 rad/s.

Compare Bode Plots of Several Dynamic Systems

Compare the frequency response of a continuous-time system to an equivalent discretized system on the same Bode plot.

Create continuous-time and discrete-time dynamic systems.

H = tf([1 0.1 7.5],[1 0.12 9 0 0]);
Hd = c2d(H,0.5,'zoh');

Create a Bode plot that displays both systems.

bode(H,Hd)

The Bode plot of a discrete-time system includes a vertical line marking the Nyquist frequency of the system.

Bode Plot with Specified Line and Marker Attributes

Specify the color, linestyle, or marker for each system in a Bode plot using the PlotStyle input arguments.

H = tf([1 0.1 7.5],[1 0.12 9 0 0]);
Hd = c2d(H,0.5,'zoh');
bode(H,'r',Hd,'b--')

The string 'r' specifies a solid red line for the response of H. The string 'b--' specifies a dashed blue line for the response of Hd.

Obtain Magnitude and Phase Data

Compute the magnitude and phase of the frequency response of a dynamic system.

H = tf([1 0.1 7.5],[1 0.12 9 0 0]);
[mag phase wout] = bode(H);

Because H is a SISO model, the first two dimensions of mag and phase are both 1. The third dimension is the number of frequencies in wout.

Bode Plot of Identified Model

Compare the frequency response of a parametric model, identified from input/output data, to a nonparametric model identified using the same data.

Identify parametric and non-parametric models based on data.

load iddata2 z2;
w = linspace(0,10*pi,128);
sys_np = spa(z2,[],w);
sys_p = tfest(z2,2);

sys_np is a non-parametric identified model. sys_p is a parametric identified model.

Create a Bode plot that includes both systems.

bode(sys_np,sys_p,w);
legend('sys-np','sys-p')

Obtain Magnitude and Phase Standard Deviation Data of Identified Model

Compute the standard deviation of the magnitude and phase of an identified model. Use this data to create a 3σ plot of the response uncertainty.

Identify a transfer function model based on data. Obtain the standard deviation data for the magnitude and phase of the frequency response.

load iddata2 z2;
sys_p = tfest(z2,2);
w = linspace(0,10*pi,128);
[mag,ph,w,sdmag,sdphase] = bode(sys_p,w);

sys_p is an identified transfer function model. sdmag and sdphase contain the standard deviation data for the magnitude and phase of the frequency response, respectively.

Use the standard deviation data to create a 3σ plot corresponding to the confidence region.

mag = squeeze(mag);
sdmag = squeeze(sdmag);
semilogx(w,mag,'b',w,mag+3*sdmag,'k:',w,mag-3*sdmag,'k:');

Alternatives

Use bodeplot when you need additional plot customization options.

More About

expand all

Algorithms

bode computes the frequency response using these steps:

  1. Computes the zero-pole-gain (zpk) representation of the dynamic system.

  2. Evaluates the gain and phase of the frequency response based on the zero, pole, and gain data for each input/output channel of the system.

    1. For continuous-time systems, bode evaluates the frequency response on the imaginary axis s = and considers only positive frequencies.

    2. For discrete-time systems, bode evaluates the frequency response on the unit circle. To facilitate interpretation, the command parameterizes the upper half of the unit circle as

      z=ejωTs,0ωωN=πTs,

      where Ts is the sampling time. ωN is the Nyquist frequency. The equivalent continuous-time frequency ω is then used as the x-axis variable. Because H(ejωTs) is periodic and has a period 2 ωN, bode plots the response only up to the Nyquist frequency ωN. If you do not specify a sampling time, bode uses Ts = 1.

Was this topic helpful?