ELEC 3004 Systems: Signals & Controls Tutorial 4 (Week ): Matlab - Digital Control Systems The process of designing and analysing sampled-data systems is enhanced by the use of interactive computer tools i.e. Matlab. Many of the control design functions for continuous-time control design have equivalent counterparts for sampled-data systems. Discrete-time transfer function model objects are obtained with the tf function. Need to check whether you have converted from the continuous domain to the discrete domain correctly? Try playing around with the c2d and d2c functions. TF function: SYS = tf(num,den) sys = tf([], [ 0]) sys = ------- s^2 + s Continuous-time transfer function. If this were in the discrete domain rather than the continuous domain we just add the third parameter of the tf function Ts which is the sampling time. If the sampling time is unknown for some reason simply put - in its place. SYS = tf(num,den,ts) sys = tf([], [ 0], -) sys = ------- z^2 + z Sample time: unspecified
Quite often it will be necessary to convert between the continuous domain and discrete domain, doing this be handy can be a rather tedious process, however sometimes it must be done. But to make life easier, matlab has a nice function for doing just that c2d. This matlab function will take the transfer function of a continuous system and convert it to the discrete domain. sys = tf([], [ 0]) sys = ------- s^2 + s Continuous-time transfer function. SYSD = c2d(sysc,ts,method) sysz = c2d(sys, 0., 'zoh') sysz = 0.004837 z + 0.004679 ---------------------- z^2 -.905 z + 0.9048 Sample time: 0. seconds As you have probably already seen there are a number of different approximations for converting from the continuous domain to the discrete domain. That is the third parameter in the c2d function, you can to conversions with the zero order hold method or matched pole zero or a number of other methods. All the methods that can be provided into this matlab function are all APPROXIMATIONS to the continuous time transfer function. It is possible to do the exact z- transform by hand, but generally it involves a little bit of maths. Wishing to view the root locus of your continuous or discrete transfer function?? There are a number of tools available to you, some of which are interactive i.e. They allow you to move the poles and zeros around so you are able to see what happens to them when varying gains and sampling times. Pzmap: pzmap(sys) All you have to give this function is your transfer function and it will map all the poles and zeros for you on a pretty little rool locus.
sysz = c2d(sys, 0., 'zoh') sysz = 0.004837 z + 0.004679 ---------------------- z^2 -.905 z + 0.9048 Sample time: 0. seconds pzmap(sysz) grid on Rltool u --->O--->[ COMP ]--->[ PLANT ]----+---> y - +----------------------------------------+ rltool(plant) further specifies the plant model PLANT to be used in the SISO Tool. PLANT is any linear model created with TF, ZPK, or SS.
rltool(plant,comp) also specifies an initial value COMP for the compensator (also a linear model created with TF, ZPK, or SS). With this tool you are not only capable of mapping out the locations of your poles and zeros but you are also capable of seeing how a compensator will affect your system. For those of you who may not know, generally you apply a compensator to an unstable system to bring it back to stability. This is done by adding additional poles and zeros to the system along with system gains that will bring the poles of the plant back to stability. sysz = c2d(sys, 0., 'zoh') sysz = 0.004837 z + 0.004679 ---------------------- z^2 -.905 z + 0.9048 Sample time: 0. seconds syscomp = tf([ 0], [ 0.2 0.], 0.) syscomp = z ----------------- z^2 + 0.2 z + 0. Sample time: 0. seconds rltool(sysz, syscomp)
As you can see in the plot above the pink squares are originally where the poles are, however you are able to click and drag them and it will show you how the other poles react to that change. Additionally, rltool is capable of converting between continuous and discrete after the plot has been done. Rlocus: Assume we have some discrete transfer function: 0.3678 0.789 0.3680 And a compensator for this system: 0.3678 0.2400 We wish to find the maximum gain possible for our system with the applied compensator without making the system unstable. One way to do this is to use the rlocus function and conjunction with rlocfind.
%This script generates the root locus for %the sampled dtaa system % K(0.3678)(z + 0.789) % --------------------- % (z - )(z+0.2400) % %Plot the root locus num = [0.3678 0.2644]; den = [.0-0.76-0.24]; sys = tf(num, den); rlocus(sys); hold on %plot the unit circle x = [-:0.:]; y = sqrt(-x.^2); plot(x, y, '--', x, -y, '--'); Once we have the plot simply use to rlocfind function, click on the intersect of the unit circle and the possible path taken by the poles to find the maximum possible gain without making the system unstable. In this example the gain comes out to be approximately 4.639 (K = 4.369). Simulation of sampled-data: The functions step, impulse and Isim are used for simulation of sampled data systems. The step function and the impulse function will apply a step and impulse to your system respectively.
%This script generates the unit step response y(kt), % for the sampled data system % 0.3679 z + 0.2642 % G(Z) = ----------------- % z^2 - z + 0.632 num = []; den = [ 0]; sysc = (tf(num, den)); sysd = c2d(sysc,, 'zoh'); sys = feedback(sysd, []) T = [0::20]; %Note the form of T. It should be in the form T i :T s :T f where T s is the sample time. step(sys, T); An impulse can be applied to the system similarly.