Skip to content

14.11 Computation Using MATLAB

← Back to Fundamentals of Electric Circuits Overview

14.11 Computation Using MATLAB

MATLAB is a software package that is widely used for engineering computation and simulation. A review of MATLAB is provided in Appen dix E for the beginner. This section shows how to use the software to numerically perform most of the operations presented in this chapter and Chapter 15. The key to describing a system in MATLAB is to specify the numerator (num) and denominator (den) of the transfer function of the system. Once this is done, we can use several MATLAB commands to obtain the system’s Bode plots (frequency response) and the system’s response to a given input.

The command bode produces the Bode plots (both magnitude and phase) of a given transfer function H(s). The format of the com mand is bode (num, den), where num is the numerator of H(s) and den is its denominator. The frequency range and number of points are automatically selected. For example, consider the transfer function in Example 14.3. It is better to first write the numerator and denominator in polynomial forms.

Thus,

H(s)=200jω(jω+2)(jω+10)=200ss2+12s+20,s=jωH(s) = \frac{200 j\omega}{(j\omega + 2)(j\omega + 10)} = \frac{200s}{s^2 + 12s + 20}, \qquad s = j\omega

Using the following commands, the Bode plots are generated as shown in Fig. 14.59. If necessary, the command logspace can be included to generate a logarithmically spaced frequency and the command semilogx can be used to produce a semilog scale.

num = [200 0]; % specify the numerator of H(s) >> den = [1 12 20]; % specify the denominator of H(s) >> bode(num, den); % determine and draw Bode plots

The step response y(t) of a system is the output when the input x(t) is the unit step function. The command step plots the step response of a system given the numerator and denominator of the transfer function of that sys tem. The time range and number of points are automatically selected. F or example, consider a second-order system with the transfer function

H(s)=12s2+3s+12H(s) = \frac{12}{s^2 + 3s + 12}

We obtain the step response of the system shown in Fig. 14.60 by using the following commands.

n = 12; >> d = [1 3 12]; >> step(n,d);

We can verify the plot in Fig. 14.60 by obtaining y(t) = x(t) * u(t) or Y(s) = X(s)H(s).

The command lsim is a more general command than step. It calculates the time response of a system to any arbitrary input signal. The format of the command is y = lsim (num, den, x, t), where x(t) is the input signal, t is the time vector, and y(t) is the output generated. For example, assume a system is described by the transfer function

for, and

y(t)y(t)

is the output gen-
cribed by the transfer function

H(s)=s+4s3+2s2+5s+10H(s) = \frac{s+4}{s^3 + 2s^2 + 5s + 10}

To find the response y(t) of the system to input x(t) = 10eβˆ’t u(t), we use the following MATLAB commands. Both the response y(t) and the input x(t) are plotted in Fig. 14.61.

>> t = 0:0.02:5; % time vector 0 < t < 5 with increment
0.02
>> x = 10*exp(-t);
>> num = [1 4];
>> den = [1 2 5 10];
>> y = lsim(num,den,x,t);
>> plot(t,x,t,y)

Figure 14.61

The response of the system described by H(s) = (s + 4)βˆ•(s 2 + 2s 2 + 5s + 10) to an exponential input.