home *** CD-ROM | disk | FTP | other *** search
- //------------------------------------------------------------------------------
- //
- // ss2tf
- //
- // Syntax: A=ss2tf(a,b,c,d,Inp)
- //
- // This routine converts a state-space model to a transfer function model.
- // It creates the transfer function:
- //
- // num(s) -1
- // H(s) = -------- = C(sI-A) B + D
- // den(s)
- //
- // of the system:
- // .
- // x = Ax + Bu
- // y = Cx + Du
- //
- // for the specified input Inp (optional input). The vector den contains
- // the coefficients of the denominator in descending powers of s. The
- // numerator coefficients are returned in the vector num. All transfer
- // functions for all outputs will be returned with each row of num
- // containing the numerator for the transfer function.
- //
- // The results are returned in a list:
- // A.num = numerator
- // A.den = denominator
- //
- // Copyright (C), by Jeffrey B. Layton, 1994
- // Version JBL 940919
- //------------------------------------------------------------------------------
-
- rfile abcdchk
- rfile poly
-
- ss2tf = function(a,b,c,d,Inp)
- {
- local(msg,estr,b,d,i,num,den)
-
- // Check state space system.
- msg="";
- msg=abcdchk(a,b,c,d);
- if (msg != "") {
- estr="SS2TF: "+msg;
- error(estr);
- }
-
- // error Cheking on Inp
- if (exist(Inp)) {
- if (Inp > b.nc) {
- error("SS2TF: Inp > number of inputs.");
- }
- b=b[;Inp];
- d=d[;Inp];
- else
- if (b.nc > 1) {
- error("SS2TF: Inp must be input for systems with more than 1 input.");
- }
- }
-
- // Find Denominator
- den=poly(a);
-
- // Special Case: The input system (a,b,c,d) is just a simple gain
- // or only has a denominator (don't need to find numerator).
- if ( (isempty(b)) && (isempty(c)) ) {
- num=d;
- if ( (!isempty(d)) && (!isempty(a)) ) {
- den=[];
- }
- return << num=num; den=den >>
- }
-
- num = ones(d.nr,length(a)+1);
- for (i in 1:d.nr) {
- num[i;]=poly(a-b*c[i;])+(d[i]-1)*den;
- }
-
- return << num=num; den=den >>
- };
-