home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / zp2sys.m < prev    next >
Text File  |  1999-12-24  |  4KB  |  147 lines

  1. ## Copyright (C) 1996,1998 Auburn University.  All Rights Reserved
  2. ##
  3. ## This file is part of Octave. 
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it 
  6. ## under the terms of the GNU General Public License as published by the 
  7. ## Free Software Foundation; either version 2, or (at your option) any 
  8. ## later version. 
  9. ## 
  10. ## Octave is distributed in the hope that it will be useful, but WITHOUT 
  11. ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  12. ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  13. ## for more details.
  14. ## 
  15. ## You should have received a copy of the GNU General Public License 
  16. ## along with Octave; see the file COPYING.  If not, write to the Free 
  17. ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. 
  18.  
  19. ## -*- texinfo -*-
  20. ## @deftypefn {Function File } { @var{sys} =} zp2sys (@var{zer},@var{pol},@var{k}@{,@var{tsam},@var{inname},@var{outname}@})
  21. ##  Create system data structure from zero-pole data
  22. ## 
  23. ## @strong{Inputs}
  24. ## @table @var
  25. ## @item   zer
  26. ##  vector of system zeros
  27. ## @item   pol
  28. ##  vector of system poles
  29. ## @item   k
  30. ##  scalar leading coefficient
  31. ## @item   tsam
  32. ##  sampling period. default: 0 (continuous system)
  33. ## @item   inname, outname
  34. ##  input/output signal names (lists of strings)
  35. ## @end table
  36. ## 
  37. ## @strong{Outputs}
  38. ##  sys: system data structure
  39. ## 
  40. ## @strong{Example}
  41. ## @example
  42. ## octave:1> sys=zp2sys([1 -1],[-2 -2 0],1);
  43. ## octave:2> sysout(sys)
  44. ## Input(s)
  45. ##         1: u_1
  46. ## Output(s):
  47. ##         1: y_1
  48. ## zero-pole form:
  49. ## 1 (s - 1) (s + 1)
  50. ## -----------------
  51. ## s (s + 2) (s + 2)
  52. ## @end example
  53. ## @end deftypefn
  54.  
  55. function outsys = zp2sys (zer, pol, k, tsam, inname, outname)
  56.  
  57.   ## Modified by John Ingram  July 20, 1996  
  58.  
  59.   ## Test for the correct number of input arguments
  60.   if ((nargin < 3) || (nargin > 6))
  61.     usage("outsys = zp2sys(zer,pol,k[,tsam,inname,outname])");
  62.   endif
  63.  
  64.   ## check input format 
  65.   if( ! (is_vec(zer) | isempty(zer) ) )
  66.     error("zer must be a vector or empty");
  67.   endif
  68.   if(!isempty(zer))
  69.     zer = reshape(zer,1,length(zer));        # make it a row vector
  70.   endif
  71.  
  72.   if( ! (is_vec(pol) | isempty(pol)))
  73.     error("pol must be a vector");
  74.   endif
  75.   if(!isempty(pol))
  76.     pol = reshape(pol,1,length(pol));
  77.   endif
  78.  
  79.   if (! is_scal(k))
  80.      error('k must be a scalar');
  81.   endif
  82.  
  83.   ## Test proper numbers of poles and zeros.  The number of poles must be 
  84.   ## greater than or equal to the number of zeros.
  85.   if (length(zer) >  length(pol))
  86.     error(["number of poles (", num2str(length(pol)), ...
  87.     ") < number of zeros (", num2str(length(zer)),")"]);
  88.   endif
  89.  
  90.   ## Set the system transfer function
  91.   outsys.zer = zer;
  92.   outsys.pol = pol;
  93.   outsys.k = k;
  94.  
  95.   ## Set the system vector:  active = 1, updated = [0 1 0];
  96.   outsys.sys = [1, 0, 1, 0];
  97.  
  98.   ## Set defaults
  99.   outsys.tsam = 0;
  100.   outsys.n = length(pol);
  101.   outsys.nz = 0;
  102.   outsys.yd = 0;    # assume (for now) continuous time outputs
  103.  
  104.   ## Set the type of system
  105.   if (nargin > 3)
  106.     if( !is_scal(tsam) )
  107.       error("tsam must be a nonnegative scalar");
  108.     endif
  109.     if (tsam < 0)
  110.       error("sampling time must be positve")
  111.     elseif (tsam > 0)
  112.       [outsys.n,outsys.nz] = swap(outsys.n, outsys.nz);
  113.       outsys.yd = 1;        # discrete-time output
  114.     endif
  115.  
  116.     outsys.tsam = tsam;
  117.   endif
  118.  
  119.   outsys.inname = sysdefio(1,"u");
  120.   outsys.outname = sysdefio(1,"y");
  121.   outsys.stname = sysdefst(outsys.n,outsys.nz);
  122.  
  123.   ## Set name of input
  124.   if (nargin > 4)
  125.     ## make sure its a string
  126.     if(!isempty(inname))
  127.       if(!is_list(inname))  inname = list(inname); endif
  128.       if(!is_siglt(inname))
  129.         error("inname must be a single signal name");
  130.       endif
  131.       outsys.inname = inname(1);
  132.     endif
  133.   endif
  134.  
  135.   ## Set name of output
  136.   if (nargin > 5)
  137.     if(!isempty(outname))
  138.       if(!is_list(outname))        outname = list(outname);    endif
  139.       if(!is_siglt(outname))
  140.         error("outname must be a single signal name");
  141.       endif
  142.       outsys.outname = outname(1);
  143.     endif
  144.   endif 
  145.  
  146. endfunction
  147.