ENG M 54 Laboratory #7 University of Alberta ENGM 54: Modeling and Simulation of Engineering Systems Laboratory #7 M.G. Lipsett & M. Mashkournia 2 Mixed Systems Modeling with MATLAB & SIMULINK Mixed systems are modeled in exactly the same way as any other set of governing equations. The governing equations for different subsystems are in terms of different units, and so the process of non-dimensionalising is a little more complicated in that it is done for several different types of units. The procedure, however, is the same for each set of units that needs to be non-dimensionalised. In many systems, the response of one subsystem may be much faster than another part. For example, an electric shovel may have mechanical dynamics that are low-bandwidth (that is, they change slowly), whereas the electrical drive system may have a very fast response. The system may be stiff if the sensitivity of one subsystem to variations is much greater than other parts of the overall system. In such cases, non-dimensionalising allows scaling to make the set of equations more stable. SIMULINK has add-on packages that can be purchased with custom blocks for different types of physical systems. SimMechanics is a rigid-body dynamics package that allows a mechanism to be constructed graphically and then simulated. The library has the following element types: Figure : SimMechanics toolbox The resulting simulation can be animated in OpenGL, and converted to a few different formats for playback. SimHydraulics is a mechano-hydraulic systems simulation package for SIMULINK, which allows a designer to analyse power hydraulics and control systems. It does not model fluid transportation, water supply and sewer systems, or distributed parameter systems. SimHydraulics assumes that fluid temperature and volume of entrapped air remain constant during the simulated time interval. The library contains the following element types:
Figure 2: SimHydraulics toolbox Model Conversion In this course, we have been developing state-space representations of systems. An alternative and powerful approach for modeling linearised systems is to use Laplace transforms to create transfer functions (covered in Chapter of the course text). MATLAB has functions that allow the user to convert between different model types, including: c2d to convert from continuous-time state-space to discrete-time state-space form, d2c to convert from discrete-time state-space to continuous state-space form, ss2tf to convert from state-space to transfer function form, ss2zp to convert from state-space to zero-pole-gain form, tf2ss to convert from transfer function to state-space form, tf2zp to convert transfer function to zero-pole-gain form, zp2ss to convert zero-pole-gain to canonical state-space form, and zp2tf to convert from zero-pole-gain to transfer function form. For example, to convert the continuous-time state-space representation to discrete-time, where ẋ = Ax + Bu () [ A = 3 4 ], B = [ ] (2) we use the following statements: >> A = [, ; 3, 4]; 2
>> B = [; ]; >> [Ad, Bd] = c2d(a, B,.); where the third argument specifies the discrete sampling time of. seconds. The resulting discrete form is x[n + ] = A d x[n] + B d x[n] (3) where x[n+] is the value of the vector x at the n+st time step. The calculated matrices are [ ] [ ].9868.82.44 A =, B =.246.6588.82 This is a good way to represent a discrete linear system (such as a discrete manufacturing process) in which state changes occur synchronously (at the same time), with a uniform time step. As an example of converting from continuous state-space form to transfer function form, consider the system { } [ ] { } [ ] x x = + u (5) x 2 3 4 x 2 } which is in state-space form y = [ ] { x x 2 (4) + []u, (6) ẋ = Ax + Bu (7) y = Cx + Du (8) This linear system converts to a polynomial transfer function with the following statements: >> A = [, ; 3, 4]; >> B = [; ]; >> C = [, ]; >> D = ; >> iu = ; >> [num, den] = ss2tf(a, B, C, D, iu); where the transfer function is defined by numerator polynomial vector num and denominator polynomial vector den. The values are found to be num = [ ], den = [ 4 3] and so the transfer function is y(s) u(s) = s 2 + 4s + 3 We can use tf2ss to convert from transfer function to state-space form. For our example the commands are >> num = ; % here, the numerator has only one term >> den = [, 4, 3];% denominator polynomial terms (descending order) >> [A, B, C, D] = tf2ss(num, den); With the resulting matrices A = [ 4 3 ], B = [ The syntax for the other functions is given in the MATLAB help. Exercise ) For the transfer function ] (9), C = [ ], D = [], () H(s) = s + 3 S 2 + 4s 2 () 3
use the tf 2ss function to convert the transfer function to state-space representation; and then use the c2d function to convert the continuous state-space representation to discrete-time equations, using a sample period of.5 seconds. 2) In electromechanical control applications, a common task is to model the dynamics of actuators(eg. a dc motor). For high performance applications it is sometimes necessary to model the amplifier as well. The following are the two transfer functions for the amplifier and motor pair. H(s) = G(s) = 2(s + 5) s 2 + 3s + 2 22 s 3 + 2s 2 + 345s + 325 (2) (3) Find the state-space form the electromechanical system. (Example taken from Dynamic Modeling and Control of Engineering Systems) Analysis of linear systems (This example comes from www.me.cmu.edu/ctms/modeling which is a good site with several interesting and well explained examples.) A loudspeaker is a common example of a mixed dynamical system, combining an electrical subsystem that drives a mechanical subsystem (the vibrating speaker that produces the sound) through a linear motor. Figure illustrates the two subsystems, which are coupled by the linear motor. The state space model of this electromechanical system can be expressed as: Figure 3: Loud Speaker Model ẋ = Ax + Buy = Cx + Du (4) where is the vector of outputs, is the state vector, and is the input vector. The state-space model can be found using the following steps: Identify the energy storing elements Select state variables Identify any trivial state equations 4
Determine the other state equations using loop/node equations and constitutive relationships Express the state equations in first-order form Put the first-order state equations in vector-matrix form The mass, the spring, and the inductor can store energy. A trivial state equation is a definition of a time derivative of a variable. In this system, there is only one such state variable, the time derivative of the displacement (loop) variable in the mechanical subsystem: ẋ = v (5) From the node admissibility equations, we get the governing equation for the mechanical subsystem mẍ bẋ kx + qi = (6) where qi is the Lorentz force (motive force); and from the loop admissibility in the electrical subsystem we obtain the governing equation e i (t) Ri qẋ Li = (7) where is the Lorentz force response in the electrical subsystem (back emf). In first-order form, the state equations are ẋ = v (8) v = k m x b m v + q m i (9) i = q L v R L i + e i(t) L Let s use x(t) as our output of the system. The state vector can be written as x = x v i (2) (2) The first row of A and the first row of B contain the coefficients of the state equation for x. Likewise the second rows contain the coefficients of the state equation for v, and the third rows contain the coefficients of the state equation for i. Then write the vector form of the state equations ẋ = Ax + Bu, where A = k m b m q L q m R L, B = L (22) and the output equation y = Cx + Du, where C = [ ]; D = []. Enter this state space model into MATLAB with the specified values for each parameter, and convert it using ss to a state-space structure called electromech ss: >> R = 5; L = 5e 5; k = 2e5; b = 5; m = 4e 3; q = pi; >> A = [ ; k/m b/m q/m; q/l R/L]; >> B = [; ; /L]; 5
>> C = [ ]; >> D = []; >> electromech ss = ss(a, B, C, D) a = x x2 x3 x x2 5e + 7.25e + 4 785.4 x3 6.28e + 4 e + 5 b = u x x2 x3 2e + 4 c = x x2 x3 y d = u y Continuous timemodel. Now find the (linear) frequency response of this speaker driver by plotting the bode plot using the MATLAB command bode: >> bode(electromech ss); Figure 4: Bode Diagram The frequency response of this speaker driver rolls off by -3dB at approximately 54rad/sec (86Hz), and so this speaker would likely be a low-frequency woofer. The high-frequency asymptote for the magnitude 6
drops off at -6dB per decade, and the phase changes from degrees to -27 degrees, both characteristics of a 3rd-order system. MATLAB can plot the impulse response of this system when the state-space model is available. The impulse response is how the speaker responds to a brief peak in the input signal. Type the command >> impulse(electromech s s) and examine the plot of the impulse response function for this linear system: The transfer function for this Figure 5: Impulse Response system is the ratio of the Laplace Transform of the output of the system x(t) to the input Laplace Transform ei(t) : X(s)/Ei(s). The transfer function for this system is X(s) E i (x) = q (Ls + R)(ms 2 + bs + k) q 2 s (23) Enter this transfer function using the specified parameter values, defining s as a Laplace operator, to get the system transfer function structure electromech tf: >> R = 5; L = 5e 5; k = 2e5; b = 5; m = 4e 3; q = pi; >> s = tf( s ); >> electromech t f = q/((l s + R) (m s 2 + b s + k) q 2 s) T ransferfunction : 3.42 2e 7s 3 +.225s 2 + 25.s + e6 As discussed in the text Section 4.5, methods for analysing lower-order linear systems (such as finding the roots of the characteristic input-output equation to determine the poles of the system) get very involved and complicated for third-order and higher-order systems. Usually a third-order system is analysed by determining the poles, zeros, and DC Gain of the transfer function, or by examining characteristics of the frequency 7
response from the Bode Plot. The poles of this system are found using the MATLAB pole command, using the transfer function form of the system model: >> pole(electromech tf) ans =.e + 5.56.597 +.375i.597.375i which tells us the system has one real pole and one pair of complex conjugates, in this case scaled by the amount.x 5. We can also examine the natural frequencies of a system. For a second-order system with one pair of complex conjugate poles, the system has a single natural frequency, which is the frequency at which the system would exchange energy amongst the energy-storing elements within the system. The undamped natural frequency represents how elements exchange energy in a system with no energy dissipation. If there are also energy-dissipating elements in the system, then the system also has a damping ratio. This can be found using the damp command for the system in transfer function form: >> damp(electromech t f) Eigenvalue Damping F req.(rad/s) 5.97e + 3 + 3.75e + 3i 8.47e 7.5e + 3 5.97e + 3 3.75e + 3i 8.47e 7.5e + 3.e + 5.e +.e + 5 A system of order three or higher has a natural frequency and damping ratio for each pair of complex conjugate poles, which is a mode in which the system can oscillate. This system has only one pair of complex conjugates, and so there is one natural frequency, which is 7,5 rad/sec. (For high-order systems, the number of natural frequencies depends on the number of complex conjugate poles.) The natural frequency is equal to the magnitude of the associated complex conjugate pole. It is not affected by damping. The resonant frequency (also called the damped frequency) is the frequency of oscillation associated with a set of complex conjugate poles, but affected by the damping in the system: ω d = ω n ζ 2 (24) The resonant frequency in rad/sec is equal to the magnitude of the imaginary part of the complex poles which can be found using this combined MATLAB expression: >> abs(imag(pole(electromech t f))) ans =.e + 3 3.754 3.754 The first value is zero, which is the magnitude of the imaginary part of the real pole. The second two values are the resonant frequency of the complex conjugate pole, which in this system is 3,75 rad/sec. MATLAB can also show other aspects of system behavior. Exercise 2 An Inverted Pendulum is an interesting unstable system for analysis. The system equations for this system can be derived to be x x mg x2 x3 = M x2 x3 + M u (25) x4 (M+m)g x4 ML ML 8
Figure 6: Inverted Pendulum y = [ ] x x2 x3 x4 (26) where state variables x = x, x2 = ẋ, x3 = θ, x4 = θ For this example take m = kg, M = 3kg, and L =.2m. Convert the system into a state-space structure. Determine the Bode, impulse and step response of the system. Determine the poles and zeros of the system by first transforming it into a transfer function. Submit the plots and code used. References: D. Etter, Engineering Problem Solving with MATLAB. Prentice-Hall 997. http://www.me.cmu.edu/ctms/modeling www.mathworks.com Chi-Tsong Chen, Linear System Theory and Design, 3rd Edition. 9