diff scripts/control/system/c2d.m @ 3759:110bc441a954

[project @ 2000-12-16 01:25:12 by jwe]
author jwe
date Sat, 16 Dec 2000 01:25:13 +0000
parents b5238ac1dca9
children 13905c3a24af
line wrap: on
line diff
--- a/scripts/control/system/c2d.m	Fri Dec 15 19:47:29 2000 +0000
+++ b/scripts/control/system/c2d.m	Sat Dec 16 01:25:13 2000 +0000
@@ -46,6 +46,9 @@
 ##
 ## @strong{Note} If the 2nd argument is not a string, @code{c2d} assumes that
 ## the 2nd argument is @var{t} and performs appropriate argument checks.
+## @item "matched"
+## Use the matched pole/zero equivalent transformation (currently only
+## works for purely continuous SISO systems).
 ## @end table
 ##
 ## @strong{Outputs}
@@ -84,6 +87,10 @@
     opt = "ex";
   endif
 
+  if (! isstr (opt))
+    error ("expecting option as a string");
+  endif
+
   ## check if sampling period T was passed.
   Ts = sysgettsam(sys);
   if(!exist("T"))
@@ -99,8 +106,10 @@
 
   if (!is_sample(T))
     error("sampling period T must be a postive, real scalar");
-  elseif( ! (strcmp(opt,"ex") | strcmp(opt,"bi") ) )
-    error(["invalid option passed: ",opt])
+  elseif (! (strcmp (opt, "ex")
+	     || strcmp (opt, "bi")
+	     || strcmp (opt, "matched")))
+    error ("invalid option passed: %s", opt);
   endif
 
   sys = sysupdate(sys,"ss");
@@ -167,9 +176,26 @@
       D = d + (c*iab);
       stnamed = strappend(stname,"_d");
       dsys = ss2sys(A,B,C,D,T,0,rows(A),stnamed,inname,outname);
+   elseif(strcmp(opt,"matched"))
+     if(is_digital(sys))
+       error("c2d: system is already digital");
+     elseif((length(sys.inname) != 1) || (length(sys.outname) != 1))
+       error("c2d: system in not single input, single output");
+     else
+       sys = sysupdate(sys,"zp");
+       p = exp(sys.pol*T);
+       z = exp(sys.zer*T);
+       infinite_zeros = max(size(sys.pol))-max(size(sys.zer))-1;
+       for i = 1:infinite_zeros
+	 z = [z ; -1];
+       endfor
+       ## Should the freaquency we adjust around always be 1?   
+       [cmag,cphase,cw] = bode(sys,1);
+       [dmag,dpahse,dw] = bode(zp2sys(z,p,1,T),1);
+      dsys = zp2sys(z,p,cmag/dmag,T);
     endif
   else
-    error(["Bad option=",opt])
+    error ("invalid option = %s", opt);
   endif
 
 endfunction