Escolar Documentos
Profissional Documentos
Cultura Documentos
Introduction
Matlab provides an interactive environment for visualizing the behavior of systems. Using matlab, we can plot system characteristics such as frequency response and pole-zero locations as well as the response of the system to arbitrary inputs. Matlab can also aid in the otherwise tedious calculations involved in solving system equations analytically. Matlab makes it easy to tweak parameters of the system and view the corresponding changes in its behavior in order to better understand it.
+ Vin C=1F
+ Vo -
For the circuit shown in gure 1 the differential equation governing the behavior of V o for zero initial conditions is:
dVo Vo 0 dt RC Using Laplace transforms, we nd the transfer function of the system to be:
(1)
H s
1 sRC 1
Matlab has a number of tools for analyzing transfer functions. First we must enter the values for the resistor and capacitor.
>> R = 10e3; >> C = 1e-6;
Next we enter the numerator and denominator of the transfer function as polynomial coefcients of s.
>> num = 1; >> den = [R*C 1];
We know that a general transfer function can be written in terms of its zeros, poles, and gain:
H s
k s z1 s z2 s p1 s p2
(2)
Given a transfer function as polynomials in s, matlab will identify the zeros, poles, and gain.
>> [z,p,k] = tf2zp(num,den)
where z is the list of zeros of the tranfer function, which for this example is empty, p is the list of poles, and k is the gain. The reverse operation can be done with the command [num,den]=zp2tf(z,p,k). To analyze the various repsonse characteristics of the system, we combine the numerator and denominator into one structure that matlab recongnizes as a trasnfer function. >> sys=tf(num,den); Now we are ready to analyze the system. First, we may want to plot the frequency response of the system as a Bode plot. In matlab this is done easily:
>> [mag,phase]=bode(sys);
10 15 20 25 0
45
90 1 10
10 Frequency (rad/sec)
10
This command stores the magnitude and phase of the transfer function and produces the plots in gure 2. The magnitude is stored in standard units, but plotted as decibels. We can easily convert the stored magnitude to decibels with the command >> magdb=20*10log(mag);. Note that in general, giving output arguments to a matlab command will stop it from generating a plot. If you want to plot and save the output of a function, you will have to run the command twice. Next, we may want the observe the behavior of the system in response to various inputs. This is also done easliy in matlab. We can observe the response of the system to an impulse using the command:
>> impulse(sys);
Similarly, for a step input, the command step(sys); is used. Beside these common inputs, we can simulate 3
the response to an arbitrary input. Suppose we want to see how the system will respond to a constant input that is on for 50 ms, then shuts off. We rst create the time vector for which we want our input dened, then we create the input as a function of that time vector.
>> t = 0:.001:.1; >> Vin=t<0.05;
Now we can observe the response of the system to this input using
>> lsim(num,den,x,t);
The reponse of the system to the impulse, step, and custom inputs are shown in gure 3. Figure 3: Response of RC Circuit to Various Inputs
Impulse Response 10000
Amplitude
5000
0.01
0.02
0.04
0.05
0.06
100
Amplitude
50
0.01
0.02
0.05
0.06
100
Amplitude
50
0.02
0.04
0.08
0.1
0.12
Finally, matlab can help us nd the time domain solution to the differential equation by aiding in a partial fraction expansion. We know that a transfer function can be rewritten as a partial fraction expansion
H s k s
r1 r2 s p1 s p2
We can use matlab to obtain the values of k, r, and p with the residue command
>> [r,p,k]=residue(num,den)
Since out transfer function is already in partial fraction form, we need to create another one to test the function.
>> num = [2 1]; >> den = [1 2 1]; >> [r,p,k]=residue(num,den) r = 2 -3 p = -1 -1 k = []
2s
2 1
+ Vin
-
C=1mF
+ Vo -
a. Find the differential equation governing the behavior of V o for zero initial conditions: d 2Vo R dVo 1 Vo dt 2 L dt LC RC Vin LC
(3)
s2
1 LC
c. Find the poles and zeros of the system and plot them on the provided axes.
80
60
40
20
Imag Axis
20
40
60
80 8 6 4 2 0 Real Axis 2 4 6 8
d. Plot the magnitude and phase of the transfer function and plot them on the provided semilog axes.
20
20
40 0
45
90
135
180 0 10
10 Frequency (rad/sec)
10
e. Plot the step response of the system on the provided axes. Is the system under, critically, or overdamped? Figure 7: Step Response for RLC Circuit
Step Response 2 1.8 1.6 1.4 1.2
Amplitude
10 Time (sec)
15
20
25
Underdamped.
f. Select parameters such that the system is critcally damped. Plot the resulting step response. One possible arrangement is set C=1, R=2; Figure 8: Step Response for Critically Damped RLC Circuit
Step Response 1000 900 800 700 600
Amplitude
5 Time (sec)
10
15
g. Select parameters such that the system is overdamped. Plot the resulting Step response. One possible arrangement is changing R=20; Figure 9: Step Response for Overdamped RLC Circuit
Step Response 1000 900 800 700 600
Amplitude
20
40
60 Time (sec)
80
100
120
h. Find the time-domain analytical expression for the step response of the overdamped circuit. Use matlab to do the partial fraction expansion. Depending on the parameters, solution should have the form: Vo t C1 e
at
C2 e
bt
(4)
10
b. We can use the inline command to dene a function for matlab to evaluate. For example if want to store the function y 2x, we would use the inline command as follows:
>> y=inline(2*x);
As always you can learn more about the inline command by typing >> help inline. Using inline, store the state space differential equations for the RLC circuit. Write the command you use below. Remember that since the state equations are differential, your function must be of time as well as the state variable. Inline input to ode solvers is not supported by earlier versions of matlab. Instead we must dene our differential state equation in a separate le, call it xdot.m. In this le we dene the function as follows:
function yy=xdot(t,x) yy=[-.5 -.500; 1 0]*x;
c. Now that we have the state space equations stored, we can use one of the matlab differential equation solvers to solve them. Use ode23 to solve the state equations up to 10 seconds, for an initial condition of Vo = 1. Write the command you used below and plot the values of your state variables vs. time on the axes provided. Figure 10: Solutions to State Equations vs. Time
1
0.8
0.6
0.4
0.2
0.2
0.4
0.6
0.8
10
Call ode23 as follows: [t,y]=ode23(xdot,[0 10],[1 0]); Argument 1 is the le that stores the state equations. Argument 2 is the vector with the initial and nal times. Argument 3 is the vector of initial conditions. The output t is the time vector the equations are evaluated over and y is the solution vector. We can plot the solutions vs. time by plot(t,y);
11
d. Use matlab to plot the solutions to the state equations in the phase plane. Plot and label the results on the axes below. Figure 11: Phase Plane Plot for RLC Circuit
0.06
0.04
0.02
0.02
0.04
0.06 1
0.8
0.6
0.4
0.2
0.2
0.4
0.6
0.8
plot(y(:,1),y(:,2))
12