ECE 350 – Linear Systems I MATLAB Tutorial #4 Stability and Frequency Response of Linear Systems This tutorial describes the MATLAB commands that can be used to determine the stability and/or frequency response of a system from its transfer function. System Stability If a linear system is described by a transfer function H(s), the system is said to be stable if the poles of H(s) are in the left half of the complex plane. For example, if: H (s) = s+2 s + 4s + 3s 3 + 6s 2 + 8s + 10 5 4 we can determine whether or not the system is stable by plotting the poles of H(s) (roots of the denominator). First, the poles are found by using the “roots” command. The argument of the roots command is a vector of the coefficients of the polynomial going from highest order coefficient to lowest. >> poles = roots([1, 4, 3, 6, 8, 10]); Then the poles can be plotted by using: >> plot(real(poles), imag(poles), ‘x’) By default, MATLAB connects data points with solid lines. The ‘x’ string in the plot command tells MATLAB that we want each point marked with an ‘x’ and no connecting line. The following plot will result: 1 Note that since there are poles on the right half plane the system is NOT stable. There is also a built in command for generating the pole-zero diagram in the Control Systems Toolbox. To use this command we need to define the transfer function, H(s), using the tf command as follows: Hs=tf([1 2], [1 4 3 6 8 10]); Vectors of their coefficients specify the numerator and denominator of the transfer function. The pole-zero diagram is then generated with: >> iopzmap(Hs) Frequency Response The frequency response function, H(jω), is found by setting s = jω in the transfer function for a system. For example, if: H (s) = s 2 + 100 s 2 + 2s + 100 we can specify the numerator and denominator polynomials as B and A respectively: >> B = [1, 0, 100]; >> A = [1, 2, 100]; 2 The freqs command can be used to compute the frequency response function over a range of frequencies. The general form of freqs is: H = freqs(B,A,W) where W is the frequency range in rad/sec. Thus, we can plot the magnitude of this frequency response with: >> >> >> >> B = [ 1 0 100]; A = [ 1 2 100]; H=freqs(B, A, 0:30); plot(0:30, abs(H)) resulting in the following plot. We often want to plot the frequency axis on a log scale (and select frequency points spread evenly on that scale). This can be done as follows: >> omega = logspace(0, 2, 100); Note that this will create a set of 100 points spaced evenly on a log scale from 1 (10^0) to 100 (10^2). Then we can plot the magnitude of H on a log scale using: >> H=freqs(B, A, omega); >> semilogx(omega, abs(H)) resulting in: 3 Or, to plot the values of the magnitude of H in decibels (dB) we use: >> semilogx(omega, 20*log(abs(H))) resulting in: The phase angle of H is plotted using: >> semilogx(omega, angle(H)) resulting in: 4 This graph shows the phase angle in radians. We can convert and plot the angle in degrees with: >> semilogx(omega, (180/pi)*angle(H)) resulting in: Using Simulink to Model a Transfer Function The Transfer Function block in Simulink can be used to model any transfer function. Open a new Simulink model window. Build the model shown in the figure below. The step block is found in the Sources sub-library and the Transfer Fcn block is found in the Continuous sub-library. Double click on the Step source and set the Step time to 0, the initial value to 0 and the final value to 1. This will produce a step function u(t). In order to simulate the transfer function in the previous section, input the vector [1, 0, 100] 5 for the numerator coefficients and [ 1, 2, 100] for the denominator coefficients. Set the Configuration Parameters to have a stop time of 5, a type: fixed-step and a fixed step size of 0.01. Run the simulation. The scope output is as shown in the figure below. The output converges to a finite value (1 in this case). This confirms that the system is stable. Note that the poles are: >> roots(A) ans = -1.0000 + 9.9499i -1.0000 - 9.9499i which are on the left half plane. If we change the transfer function in the Simulink model to be: H (s) = 1 s −1 by changing the numerator and denominator coefficients to be [1] and [1 -1] respectively, the following output is displayed on the scope: 6 Note that this unstable system (pole of +1) has an output that grows without bound. 7