home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 2.ddi / MUTOOLS2.DI$ / MSDEMO2.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  5.8 KB  |  226 lines

  1. %msdemo2
  2. echo on
  3. clc
  4. %     msdemo1 was an introduction to the data
  5. %     types, and some commands for generating system
  6. %     matrices and frequency responses from system matrices,
  7. %     and plotting the results.
  8.  
  9. %     Let's now consider time responses. First
  10. %     make up a very simple 1 state, 1 input, 1 output
  11. %     system. Recall the syntax for PCK, SYS = PCK(a,b,c,d)
  12. %     Hence   PCK(-4,4,1,0)   will produce a system with
  13. %     Laplace transform 4/(s+4).
  14.  
  15. pause; % strike any key to continue
  16.  
  17. sys = pck(-4,4,1,0);
  18.  
  19. pause; % strike any key to continue
  20. clc
  21.  
  22. %   now create a STEP INPUT VARYING matrix
  23. %   using STEP_TR. the syntax is
  24. %
  25. %        INPUT = STEP_TR(TIMEDATA,STEPDATA,T_INC,FINALT)
  26. %
  27. %   TIMEDATA is the times at which the step changes occur
  28. %   STEPDATA is the corresponding values of this
  29. %            piecewise-constant signal
  30. %   T_INC is the time increment between values in the 
  31. %   FINALT is the last time in the varying matrix INPUT
  32. %
  33. %   as an example, try
  34. %
  35. %         u = step_tr([0 1 2 3],[0 1 -1 -2],0.01,4);
  36. %
  37. pause; % strike any key to continue
  38.  
  39. %    this will represent a staircase-like time-varying
  40. %    signal. it begins at t=0, with a 
  41.  
  42. pause; % strike any key to continue
  43.  
  44. u = step_tr([0 1 2 3],[0 1 -1 -2],0.01,4);
  45.  
  46. pause; % strike any key to continue
  47.  
  48. %   this represents a varying matrix (note the INF
  49. %   in the lower right corner) There are two data 
  50. %   points, the independent variable's values are 0
  51. %   and 0.05, and the value of the matrix at both
  52. %   values is 1.
  53. %   
  54.  
  55. pause; % strike any key to continue
  56. clc
  57.  
  58. minfo(u)
  59.  
  60. pause; % strike any key to continue
  61. clc
  62.  
  63. %    the time response command is called TRSP.
  64. %    Basically, there are two input arguments - the
  65. %    system (a system matrix) and the input function
  66. %    (a varying matrix). The command TRSP assumes
  67. %    that the input function is equal to zero 
  68. %    until its independent variable's first value.
  69. %    After that first value, the 
  70. %    input function is assumed to be constant between 
  71. %    independent variable values. So, to the command 
  72. %    TRSP, the varying matrix U created above
  73. %         (recall      U = [1 0 ; 1 0.05 ; 2 inf])
  74. %    represents a unit step input at t=0.
  75.    
  76. pause; % strike any key to continue
  77. clc
  78.  
  79. %    Create another varying matrix UTILDE
  80. %    as follows:
  81.  
  82. pause; % strike any key to continue
  83.  
  84. utilde = [ 4*ones(50,1) (0:0.05:2.45)' ; 1 2.5 ; 51 inf ];  
  85.  
  86. pause; % strike any key to continue
  87.  
  88. utilde
  89.  
  90. pause; % strike any key to continue
  91.  
  92.  
  93. %    To the command TRSP, this represents a signal
  94. %    that is zero for t < 0, for t between 0 and 2.5,
  95. %    the signal level is 4, and for t > 2.5, the signal
  96. %    level drops to 1.
  97.  
  98. pause; % strike any key to continue
  99. clc
  100.  
  101. minfo(utilde)
  102.  
  103. pause; % strike any key to continue
  104. clc
  105.  
  106. %    Now, the actual syntax for TRSP is
  107. %             yout = trsp(sys,u,tfinal,x0)
  108.  
  109. %    Since the input is assumed to be constant
  110. %    between independent variable values, the
  111. %    system SYS is transformed to a discrete
  112. %    system by a sample-hold, with sampling time
  113. %    defined as the difference between the first
  114. %    and second times in the input signal u. IT IS
  115. %    ASSUMED THAT THE INDEPENDENT VARIABLES IN THE
  116. %    INPUT SIGNAL ARE EVENLY SPACED, AND THIS SPACING
  117. %    DEFINES THE SAMPLING TIME. The
  118. %    third argument, TFINAL, denotes how long the
  119. %    response is computed, and the 4th argument, x0, 
  120. %    is the desired initial state at the first time
  121. %    value of the input. If the 4th argument is omitted,
  122. %    then it is assumed to be 0.
  123.  
  124. pause; % strike any key to continue
  125. clc
  126.  
  127. %    The first response will be to the step input,
  128. %    with zero initial state (sample time of 0.05
  129. %    seconds), TFINAL = 4 seconds, and zero initial
  130. %    condition. 
  131.  
  132. pause; % strike any key to continue
  133.  
  134. yout = trsp(sys,u,4);
  135. pause;% strike any key to PLOT THE RESPONSE
  136. echo off
  137. vplot('iv,d',yout)
  138. xlabel('strike any key to continue')
  139. pause;
  140. echo on
  141.  
  142. pause;  % strike any key to continue
  143. clc
  144.  
  145. %    Now force SYS with the other input, UTILDE
  146.  
  147. pause;  % strike any key to continue
  148.  
  149. yout = trsp(sys,utilde,4);
  150. pause; % strike any key to PLOT THE RESPONSE
  151. echo off
  152. vplot('iv,d',yout)
  153. xlabel('strike any key to continue')
  154. pause
  155. echo on
  156.  
  157. pause;  % strike any key to continue
  158. clc
  159.  
  160. %    create a simple 5 input, 5 output, 5 state
  161. %    system as follows:
  162.  
  163. pause;  % strike any key to continue
  164.  
  165. a = diag([-1 -2 -3 -4 -5]);
  166. b = diag([1 2 3 4 5]);
  167. c = eye(5);
  168. sys = pck(a,b,c);
  169.  
  170. pause;  % strike any key to continue
  171.  
  172. %   this represents a diagonal transfer function matrix
  173.  
  174. %      diag[ 1/(s+1)  2/(s+2)  3/(s+3)  4/(s+4)  5/(s+5)]
  175.  
  176. pause;  % strike any key to continue
  177. clc
  178.  
  179. %    set up identically zero input for 2 seconds, then
  180. %    a unit step input in each channel
  181.  
  182. pause;  % strike any key to continue
  183.  
  184. %   first generate one signal like that
  185. pause;  % strike any key to continue
  186.  
  187. u = [ [zeros(41,1) [0:0.05:2]'] ; [ones(5,1) [2.05:.05:2.25]' ; 46 inf]];
  188. %u = [ [zeros(41,1) [0:0.05:2]'] ; [ones(5,1) [2.05 ;zeros(4,1)] ; 46 inf]];
  189. %u = [ [0; 2 ] [0;1] ; 2 inf];
  190. pause;  % strike any key to continue
  191. clc
  192.  
  193. %   now use abv to stack up several of these signals
  194. pause;  % strike any key to continue
  195.  
  196. twou = abv(u,u);    % twou  is a 2x1 varying matrix
  197. fouru = abv(twou,twou);    % fouru  is a 4x1 varying matrix
  198. input = abv(fouru,u);      % input  is a 5x1 varying matrix
  199.  
  200. pause;  % strike any key to continue
  201.  
  202. minfo(input)
  203.  
  204. pause;  % strike any key to continue
  205. clc
  206. %    set up an initial condition of 1 in each state
  207.  
  208. xo = ones(5,1);
  209.  
  210. pause;  % strike any key to continue
  211.  
  212. %    compute the time response, and plot it
  213.  
  214. pause;  % strike any key to continue
  215. clc
  216.  
  217. yout = trsp(sys,input,4,.05,xo);
  218. echo off
  219. vplot('iv,d',yout)
  220. pause
  221. echo on
  222.  
  223.  
  224. %
  225. % Copyright MUSYN INC 1991,  All Rights Reserved
  226.