changeset 3247:256f98d26275

[project @ 1999-06-19 06:51:10 by jwe]
author jwe
date Sat, 19 Jun 1999 06:51:15 +0000
parents a41cc560087a
children 68259f410026
files scripts/control/bodquist.m scripts/control/buildssic.m scripts/control/is_digital.m scripts/control/stepimp.m scripts/control/syssetsignals.m
diffstat 5 files changed, 107 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/control/bodquist.m	Sat Jun 19 06:46:35 1999 +0000
+++ b/scripts/control/bodquist.m	Sat Jun 19 06:51:15 1999 +0000
@@ -96,17 +96,19 @@
         wnew = [];
         crossover_points = find ( phase(1:lp1).*phase(2:lp) < 0);
         pd(crossover_points) = abs(359.99+dphase - pd(crossover_points));
-        np_pts = ceil(pd/dphase)+2;		# phase points
-        nm_pts = ceil(log(fd./fm)/log(dmag))+2; 	# magnitude points
+        np_pts = max(3,ceil(pd/dphase)+2);		# phase points
+        nm_pts = max(3,ceil(log(fd./fm)/log(dmag))+2); 	# magnitude points
         npts = min(5,max(np_pts, nm_pts));
+
         w1 = log10(w(1:lp1));
         w2 = log10(w(2:lp));
         for ii=bigpts
           if(npts(ii))
-            wseg(ii,1:npts(ii)) = logspace(w1(ii),w2(ii),npts(ii));
+            wtmp = logspace(w1(ii),w2(ii),npts(ii));
+            wseg(ii,1:(npts(ii)-2)) = wtmp(2:(npts(ii)-1));
           endif
         endfor
-        wnew = reshape(wseg,1,rows(wseg)*columns(wseg)); # make a row vector
+        wnew = vec(wseg)'; # make a row vector
         wnew = wnew(find(wnew != 0));
         wnew = sort(wnew);
         wnew = create_set(wnew);
@@ -123,5 +125,15 @@
       endif
     endwhile
   endif
+
+  # ensure unique frequency values
+  [w,idx] = sort(w);
+  f = f(idx);
+
+  w_diff = diff(w);
+  w_dup = find(w_diff == 0);
+  w_idx = complement(w_dup,1:length(w));
+  w = w(w_idx);
+  f = f(w_idx);
     
 endfunction
--- a/scripts/control/buildssic.m	Sat Jun 19 06:46:35 1999 +0000
+++ b/scripts/control/buildssic.m	Sat Jun 19 06:51:15 1999 +0000
@@ -225,7 +225,7 @@
   # R = (I-D*K)   must exist.
   # 
   R = eye(p) - D*K;
-  if (rank(R) < m)
+  if (rank(R) < p)
     error("---> singularity in algebraic loop.");
   else
     R = inv(R);
--- a/scripts/control/is_digital.m	Sat Jun 19 06:46:35 1999 +0000
+++ b/scripts/control/is_digital.m	Sat Jun 19 06:51:15 1999 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 1996 A. Scottedward Hodel 
+# Copyright (C) 1996, 1999 A. Scottedward Hodel 
 #
 # This file is part of Octave. 
 #
@@ -16,13 +16,32 @@
 # along with Octave; see the file COPYING.  If not, write to the Free 
 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  
-function DIGITAL = is_digital(sys)
-# function DIGITAL = is_digital(sys)
-# retrurn nonzero if system is digital
+function DIGITAL = is_digital(sys,eflg)
+# function DIGITAL = is_digital(sys{,eflg})
+# return nonzero if system is digital
+# inputs:
+#   sys: system data structure
+#   eflg: 0 [default] exit with an error if system is mixed (continuous and
+#           discrete components)
+#       : 1 print a warning if system is mixed (continuous and discrete)
+#       : 2 silent operation
+# outputs:
+#   DIGITAL:  0: system is purely continuous
+#          :  1: system is purely discrete
+#          : -1: system is mixed continuous and discrete
 # exits with an error of sys is a mixed (continuous and discrete) system
 
 # a s hodel July 1996
-# SYS_INTERNAL accesses members of system structure
+
+  switch(nargin)
+  case(1),  eflg = 0;
+  case(2),  
+    if( isempty(find(eflg == [0 1 2])) )
+      error("Illegal value of eflg=%d (%e)",eflg,eflg);
+    endif
+  otherwise,
+    usage("DIGITAL = is_digital(sys{,eflg})");
+  endswitch
 
   # checked for sampled data system (mixed)
   # discrete system
@@ -31,11 +50,20 @@
   cont = sum(sysyd == 0) + nn;
   tsam = sysgettsam(sys);
   dig = sum(sysyd != 0) + nz + tsam;
+
+  # check for mixed system
   if( cont*dig != 0)
-   sysout(sys);
-   error("continuous/discrete system; use syscont, sysdisc, or c2d first");
+   switch(eflg)
+   case(0),
+     error("continuous/discrete system; use syscont, sysdisc, or c2d first");
+   case(1),
+     warning("is_digital: mixed continuous/discrete system");
+   endswitch
+   dig_sign = -1;
   else
-    DIGITAL = (tsam > 0);
+   dig_sign = 1;
   endif
+
+  DIGITAL = dig_sign*(tsam > 0);
  
 endfunction
--- a/scripts/control/stepimp.m	Sat Jun 19 06:46:35 1999 +0000
+++ b/scripts/control/stepimp.m	Sat Jun 19 06:51:15 1999 +0000
@@ -187,7 +187,7 @@
       error("impulse: D matrix is nonzero, impulse response infinite.")
     endif
     if (DIGITAL)
-      y(:,1) = D;
+      y(:,1) = D / t_step;
       x = G / t_step;
     else
       x = B;
--- a/scripts/control/syssetsignals.m	Sat Jun 19 06:46:35 1999 +0000
+++ b/scripts/control/syssetsignals.m	Sat Jun 19 06:51:15 1999 +0000
@@ -109,47 +109,61 @@
     endfor
 
   else
-    nsigs = length(sig_vals);
-    if(!is_vector(names))
-      error("syssetsignals: opt=yd, names(%dx%d) must be a vector", ...
-        rows(names), columns(names));
-    endif
-    if(nargin == 3)
-      if(length(names) != nsigs)
-        error("opt=yd, sig_idx omitted: names(%d) should be length(%d)", ...
-          length(names), nsigs);
+    # update yd
+    # 1st check pathological case: no outputs
+    nout = sysdimensions(sys,"out");
+    if(nout == 0)
+      if(nargin != 3)
+        error("opt=%s, %d outputs, sysgetsignals cannot take 4 arguments", ...
+          yd,nout);
+      endif
+      if(!isempty(names))
+        error("opt=%s, %d outputs, names is not empty");
+      endif
+      sigvals = [];
+    else
+      nsigs = length(sig_vals);
+      if(!is_vector(names))
+        error("syssetsignals: opt=yd, names(%dx%d) must be a vector", ...
+          rows(names), columns(names));
       endif
-      sig_idx = 1:nsigs;
-    elseif(length(names) != length(sig_idx))
-      error("opt=yd: length(names)=%d, length(sig_idx)=%d",length(names), ...
-        length(sig_idx) );
+      if(nargin == 3)
+        if(length(names) != nsigs)
+          error("opt=yd, sig_idx omitted: names(%d) should be length(%d)", ...
+            length(names), nsigs);
+        endif
+        sig_idx = 1:nsigs;
+      elseif(length(names) != length(sig_idx))
+        error("opt=yd: length(names)=%d, length(sig_idx)=%d",length(names), ...
+          length(sig_idx) );
+      endif
+  
+      badidx = find(names != 0 & names != 1);
+      if(! isempty(badidx) )
+        for ii=1:length(badidx)
+          warning("syssetsignals: opt=yd: names(%d)=%e, must be 0 or 1", ...
+            badidx(ii), names(badidx(ii)) );
+        endfor
+        error("opt=yd: illegal values in names");
+      endif
+  
+      for ii=1:length(sig_idx)
+        jj = sig_idx(ii);
+        if(jj < 1 | jj > nsigs | jj != floor(jj))
+          error("sig_idx(%d)=%d, %e: must be an integer between 1 and %d", ...
+            ii,jj, jj, nsigs);
+        endif
+        sig_vals(jj) = names(ii);
+      endfor
+      if(any(sig_vals == 1) & sysgettsam(sys) == 0)
+        warning("Setting system sampling time to 1");
+        printf("syssetsignals: original system sampling time=0 but output(s)\n");
+        disp(find(sig_vals==1))
+        printf("are digital\n");
+        sys = syschtsam(sys,1);
+      endif
+      
     endif
-
-    badidx = find(names != 0 & names != 1);
-    if(! isempty(badidx) )
-      for ii=1:length(badidx)
-        warning("syssetsignals: opt=yd: names(%d)=%e, must be 0 or 1", ...
-          badidx(ii), names(badidx(ii)) );
-      endfor
-      error("opt=yd: illegal values in names");
-    endif
-
-    for ii=1:length(sig_idx)
-      jj = sig_idx(ii);
-      if(jj < 1 | jj > nsigs | jj != floor(jj))
-        error("sig_idx(%d)=%d, %e: must be an integer between 1 and %d", ...
-          ii,jj, jj, nsigs);
-      endif
-      sig_vals(jj) = names(ii);
-    endfor
-    if(any(sig_vals == 1) & sysgettsam(sys) == 0)
-      warning("Setting system sampling time to 1");
-      printf("syssetsignals: original system sampling time=0 but output(s)\n");
-      disp(find(sig_vals==1))
-      printf("are digital\n");
-      sys = syschtsam(sys,1);
-    endif
-    
   endif
 
   if(strcmp(opt,"st"))