home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / control / is_digital.m < prev    next >
Encoding:
Text File  |  1999-12-15  |  2.3 KB  |  73 lines

  1. ## Copyright (C) 1996, 1999 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{retval} =} is_digital ( @var{sys})
  21. ## Return nonzero if system is digital;
  22. ##  inputs:
  23. ##    sys: system data structure
  24. ##    eflg: 0 [default] exit with an error if system is mixed (continuous and
  25. ##            discrete components)
  26. ##        : 1 print a warning if system is mixed (continuous and discrete)
  27. ##        : 2 silent operation
  28. ##  outputs:
  29. ##    DIGITAL:  0: system is purely continuous
  30. ##           :  1: system is purely discrete
  31. ##           : -1: system is mixed continuous and discrete
  32. ## Exits with an error of sys is a mixed (continuous and discrete) system
  33. ## @end deftypefn
  34.  
  35. function DIGITAL = is_digital (sys, eflg)
  36.  
  37.   ## a s hodel July 1996
  38.  
  39.   switch(nargin)
  40.   case(1),  eflg = 0;
  41.   case(2),  
  42.     if( isempty(find(eflg == [0, 1, 2])) )
  43.       error("Illegal value of eflg=%d (%e)",eflg,eflg);
  44.     endif
  45.   otherwise,
  46.     usage("DIGITAL = is_digital(sys{,eflg})");
  47.   endswitch
  48.  
  49.   ## checked for sampled data system (mixed)
  50.   ## discrete system
  51.   sysyd = sysgetsignals(sys,"yd");
  52.   [nn,nz] = sysdimensions(sys);
  53.   cont = sum(sysyd == 0) + nn;
  54.   tsam = sysgettsam(sys);
  55.   dig = sum(sysyd != 0) + nz + tsam;
  56.  
  57.   ## check for mixed system
  58.   if( cont*dig != 0)
  59.    switch(eflg)
  60.    case(0),
  61.      error("continuous/discrete system; use syscont, sysdisc, or c2d first");
  62.    case(1),
  63.      warning("is_digital: mixed continuous/discrete system");
  64.    endswitch
  65.    dig_sign = -1;
  66.   else
  67.    dig_sign = 1;
  68.   endif
  69.  
  70.   DIGITAL = dig_sign*(tsam > 0);
  71.  
  72. endfunction
  73.