Lecture 25 Introduction to Some Matlab c2d Code in Relation to Sampled Sytem here are many way to convert a continuou time function, { h( t) ; t [0, )} into a dicrete time function { h ( k) ; k {0,,, }} Recall that the table of Laplace/-tranform i contructed by (i) electing h(t) to get h(k), and then taking the -tranform of h(k) to arrive at H () In the cae where, (ii) ampling i a ytem tranfer function, then h(t) i the ytem impule repone In thi cae, h(k) i the ampled impule repone In word, we are ampling in uch a manner that the ampled impule repone matche the original impule repone at the ample time here i no variability between the two at the ampling time For thi reaon, we have the following Fact : he Laplace/-tranform table i contructed via impule-invariant ampling Per the Matlab decription below, thi method i alo called the impule-invariant mapping method Chooing a Converion Method he c2d command dicretie continuou-time model Converely, d2c convert dicrete-time model to continuou time Both command upport everal dicretiation and interpolation method, a hown in the following table Dicretiation Method Ue when: Zero-Order Hold You want an exact dicretiation in the time domain for taircae input Firt-Order Hold You want an exact dicretiation in the time domain for piecewie linear input Impule-Invariant Mapping (c2d only) You want an exact dicretiation in the time domain for impule train input utin Approximation Zero-Pole Matching Equivalent You want good matching in the frequency domain between the continuou- and dicrete-time model Your model ha important dynamic at ome particular frequency You have a SISO model, and you want good matching in the frequency domain between the continuou- and dicrete-time model We will now addre the Zero-Order Hold (ZOH) method in the above table he following i Matlab decription Zero-Order Hold he Zero-Order Hold (ZOH) method provide an exact match between the continuou- and dicrete-time ytem in the time domain for taircae input he following block diagram illutrate the ero-order-hold dicretiation H d() of a continuou-time linear model he ZOH block generate the continuoutime input ignal u(t) by holding each ample value u(k) contant over one ample period he ignal u(t) i the input to the continuou ytem he output y[k] reult from ampling y(t) every econd Converely, given a dicrete ytem H d(), d2c produce a continuou ytem he ZOH dicretiation of coincide with H d() Clearly, the ZOH method i different from the impule-invariant method We will now elaborate on the above decription via the following example Example Conider the firt order ytem Y ( / U ( For a unit tep, Y ( Wherea the unit ( ) impule i not a taircae input, the unit tep i a trivial example of one (ie it ha only one tep) From a table of Laplace t tranform, we have y( t) e he above decription tate that, uing the ZOH method, we will have y k ( k) e for the ampled input u ( k) Uing the Matlab command
c2d with the oh flag (which, by the way, i the default flag), we have: H=tf(,[ ]); =005; H=c2d(H,,'oh') H =004877/(-0952) he Figure at right verifie the fact that the ampled ytem tep repone Matche that of the continuou time ytem For thi reaon, one could Decribe the ZOH method a tep-invariant ampling We will now develop the reult: 004877 H ( ) o thi end, recall that 0952 Figure Step repone for ZO, giving ( e ) ) ( )( e ZOH( From a table of Laplace/-tranform, we have ) ) Hence, the ampled verion of ZO i ) e 00488 H( ) he Bode plot for and are e 0952 hown at right A expected, we ee amplitude and phae aliaing near the Nyquit frequency / 6283r N / H () and H () he atute tudent might wonder why we did not include the factor of in the Laplace/-tranform pair above Recall that thi factor wa included in the impule-invariant ampling method, where the impule i Figure Bode plot for H ( and H () approximated by a pule with width and height / (hence, having area equal to ) In thi example the input i not an impule It i a more well-behaved function of time (ie a unit tep, which i a well-defined function) Hence, Matlab doe not include it in the c2d command uing the oh flag Uing the imp flag give: (t) H=c2d(H,,'imp') H =( 005 + 555e-8)/( - 0952) = 005/(-0952) From the table of Laplace/-tranform we have: of i included ) e Since 0 05, it i clear that for thi flag, the factor At thi point, it i reaonable to ak: When hould I ue the imp flag, and when hould I ue the oh flag? he anwer to thi quetion i given in Matlab above block diagram When you have a dicrete-time input u (k) from a digital controller that you want to power a plant H ( with, you mut ue a D/A circuit, uch a the ZOH, to convert number into voltage Even though the output of H (, y (t), i a continuou-time output, we cannot eaily analye it in continuou time hi i becaue the digital input i only defined at dicrete time So, the imple way to conduct an analyi i to ample the output of at the ample time uing the oh flag On the other hand, if you want a dicrete approximation for H (, then you hould ue the imp flag Before leaving thi example, we will cover one more point Specifically, conider the three tranfer function: (i) (ii) H '( ZO (iii) ) 00488 H ( ) 0952
Recall that the ZOH tranfer function ZO ( ) / wa obtained by computing the continuou time repone to a continuou time unit impule, (t) Clearly, (i) and (ii) are different However, they can both be viewed a continuou time tranfer function We will now proceed to compare their FRF o thi end, we will firt cale (ii) to have unity tatic gain For mall value of, we have e Hence, we will cale (ii) by dividing by hi cale factor change the output of the ZOH form a pule of width and height 0 to a pule of height / And o, the input to i now an approximate unit impule Unlike (t), which ha equal energy at all frequencie, thi pule ha Laplace tranform ZO / ( ) / It FRF i hown at right It energy i contant at low frequencie However, it decay rapidly at frequencie above the Nyquit frequency hi obervation, in itelf, i an important one in relation to tet engineering A mall value of correpond to a hammer Figure 3 FRF for a pule of width =05 with a hard tip he ofter the tip, the le excitation energy at higher frequencie will be imparted to the tet object Hence, the high frequency dynamic of the object, not being excited, will remain hidden We ee thi effect in relation to he FRF for (ii) i hown at right he energy above the Nyquit frequency i notably le than it would be if were excited by In other word, uing the ZOH i akin to (t) applying a low pa filter to H ( he bandwidth of thi filter extend to the Nyquit frequency Figure 4 FRF for the tranfer function (ii) Viewing D/A Converion a Numerical Integration Recall that ZO / ( ) / wa arrived at by contructing it impule repone a the uperpoition of a unit tep followed by a negative unit tep delayed by, a hown at right Since the impule repone i h( t) u ( t) u ( t ), it tranfer function i e H( o view thi a an integration problem, write ( ) H( H 2( t From the block diagram at right, we have v( t) u( ) d and y( t) v( t) v( t ) u( ) d Hence, for a general input, u (t), the output, y (t), i imply thi integral Written in a recurive fahion, we have: 0 k y( k) y[( k ) u( ) d () ( k) t t u H ( v H 2 ( y
he ZOH A/D circuit approximate the integral in () a area of a rectangle having width and height thi cae, () become he -tranform of (2a) give : utin method doe not hold the value the average of u[( k ) and u(k) u[( k ) k u ( k) ( ) d u[( k ) In word, it approximate it a the ; that i, it hold the value u[( k ) for one ample period In y( k) y[( k ) u[( k ) (2a) u[( k ) p602 of the book) Uing thi integration method, (2a) change to: Y ( ) (2b) U ( ) Intead, it hold the value { u[( k ) u( k)}/ 2 In word, it hold hi method of integration i known a trapeoidal integration (ee Figure 87 on he -tranform of (3a) give: u[( k ) u[( k) y( k) y[( k ) (3a) 2 Y( ) U( ) 2 (3b) Conider now the tranfer function a From the table of Laplace/-tranform we have a QUESION: What value of hould we ubtitute into H ( to obtain H ()? H a e ( ) a ANSWER: Setting H( H( ) and olving for give: a ( a) e Recall that the table of Laplace/ tranform wa created uing the Riemann um method of numerical integration QUESION: What value of hould we ubtitute into H ( to obtain H () aociated with trapeoidal integration? ANSWER: 2 hi anwer i not eay to prove, even for the imple a However, it can be hown to hold for any H ( a Example 2 Suppoe that we have a command ytem that include a forward loop continuou time lead compenator with tranfer function / 2 G c ( 0 U( / E(, and that we want to replace it by a digital one /0 (including the D/A circuit) Compare the Bode plot of the digital compenator uing a oh and a tutin A/D for 0 0 Solution: he figure at right how that thee method are comparable Figure 2 Digital controller Bode plot
Summary he goal of thee note wa to introduce you to ome of the Matlab c2d command flag he imp flag can be ued a an e-table of Laplace/-tranform pair he oh and tutin flag are ued to incorporate an A/D converter Even though the output of an A/D converter i analog, the dicrete tranfer function allow one to evaluate thi analog output at the ampling time