From: <par...@us...> - 2009-08-25 15:15:57
|
Revision: 6136 http://octave.svn.sourceforge.net/octave/?rev=6136&view=rev Author: paramaniac Date: 2009-08-25 15:15:49 +0000 (Tue, 25 Aug 2009) Log Message: ----------- parallel: improved m*tl*b compatibility Modified Paths: -------------- trunk/octave-forge/main/control/inst/bddemo.m trunk/octave-forge/main/control/inst/parallel.m Added Paths: ----------- trunk/octave-forge/main/control/inst/sysparallel.m Modified: trunk/octave-forge/main/control/inst/bddemo.m =================================================================== --- trunk/octave-forge/main/control/inst/bddemo.m 2009-08-25 10:09:44 UTC (rev 6135) +++ trunk/octave-forge/main/control/inst/bddemo.m 2009-08-25 15:15:49 UTC (rev 6136) @@ -46,7 +46,7 @@ "sysmult: F(s) = G(s)*H(s) (series connection)", ... "sysprune: keep only specified inputs/outputs", ... "sysscale: scale inputs/outputs by specified gain matrices", ... - "parallel: parallel connection of two systems", ... + "sysparallel: parallel connection of two systems", ... "sysfeedback: closed loop of a system", ... "buildssic: the combination of all", ... "Design examples:", ... @@ -273,8 +273,8 @@ disp("See the design examples (option 14) for use of sysscale.") prompt elseif ( k == 11) - help parallel - disp("parallel operates by making a call to sysgroup and sysscale.") + help sysparallel + disp("sysparallel operates by making a call to sysgroup and sysscale.") disp("Example:") sys1 = tf(1,[1, 1],0,"in1","out1"); sys2 = tf(2,[1, 2],0,"in2","out2"); @@ -282,12 +282,12 @@ sysout(sys1); disp("sys2=") sysout(sys2); - cmd = "sysp = parallel(sys1,sys2);"; + cmd = "sysp = sysparallel(sys1,sys2);"; run_cmd disp("sysp=") sysout(sysp); prompt - disp("parallel can be used for multiple input systems as well:") + disp("sysparallel can be used for multiple input systems as well:") in1 = {"u1.1","u1.2"}; in2 = {"u2.1","u2.2"}; @@ -307,7 +307,7 @@ sysout(sys1); disp("sys2=") sysout(sys2); - cmd = "sysp = parallel(sys1,sys2);"; + cmd = "sysp = sysparallel(sys1,sys2);"; run_cmd disp("sysp=") sysout(sysp); @@ -333,7 +333,7 @@ disp("The interconnections may be of arbitrary complexity.") disp("The use of buildssic is an alternative to sysgroup,") disp("sysadd/syssub, sysappend, sysconnect, sysdup, sysmult") - disp("sysprune, sysscale, parallel etc.") + disp("sysprune, sysscale, sysparallel etc.") disp("In contrast to these functions buildssic does not") disp("handle mixed continuous and discrete systems. However,") disp("discrete systems can be connected as long as their") Modified: trunk/octave-forge/main/control/inst/parallel.m =================================================================== --- trunk/octave-forge/main/control/inst/parallel.m 2009-08-25 10:09:44 UTC (rev 6135) +++ trunk/octave-forge/main/control/inst/parallel.m 2009-08-25 15:15:49 UTC (rev 6136) @@ -1,72 +1,157 @@ -## Copyright (C) 1996, 2000, 2002, 2004, 2005, 2006, 2007 -## Auburn University. All rights reserved. +## Copyright (C) 2009 Lukas Reichlin <luk...@sw...> ## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. ## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. ## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## ## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. +## along with this program. If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{ksys} =} parallel (@var{asys}, @var{bsys}) -## Forms the parallel connection of two systems. +## @deftypefn{Function File} {@var{sys} =} parallel (@var{sys1}, @var{sys2}) +## @deftypefnx{Function File} {@var{sys} =} parallel (@var{sys1}, @var{sys2}, @var{in1}, @var{in2}, @var{out1}, @var{out2}) +## Parallel connection of two systems. +## @math{sys = sys1 + sys2} ## +## @strong{Inputs} +## @table @var +## @item sys1 +## System data structure or gain matrix. +## @item sys2 +## System data structure or gain matrix. +## @item in1 +## . +## @item in2 +## . +## @item out1 +## . +## @item out2 +## . +## @end table +## +## @strong{Outputs} +## @table @var +## @item sys +## System data structure of parallel connection. +## @end table +## +## @seealso{sysmult} +## ## @example ## @group -## -------------------- -## | -------- | -## u ----->|----> | asys |--->|----> y1 -## | | -------- | -## | | -------- | -## |--->|----> | bsys |--->|----> y2 -## | -------- | -## -------------------- -## ksys +## .......................... +## : +--------+ : +## : +-->| sys1 |---+ : +## u : | +--------+ | + : y +## -------+ O---------> +## : | +--------+ | + : +## : +-->| sys2 |---+ : +## : +--------+ : +## :.........sys............: +## +## sys = parallel (sys1, sys2) +## +## +## .......................... +## v1 : +--------+ : z1 +## ---------->| |-------------> +## : | sys1 | : +## : +-->| |---+ : +## u : | +--------+ | + : y +## -------+ O---------> +## : | +--------+ | + : +## : +-->| |---+ : +## v2 : | sys2 | : z2 +## ---------->| |-------------> +## : +--------+ : +## :.........sys............. +## +## in1 = [2] +## in2 = [1] +## out1 = [2] +## out2 = [1] +## sys = parallel (sys1, sys2, in1, in2, out1, out2) ## @end group ## @end example +## ## @end deftypefn -## Author: David Clem -## Created: August 15, 1994 -## completely rewritten Oct 1996 a s hodel -## SYS_INTERNAL accesses members of system structure +## Author: Lukas Reichlin +## Rewritten from scratch for better compatibility in July 2009 +## Version: 0.1 -function sysp = parallel (Asys, Bsys) +function sys = parallel (_sys1, _sys2, in1, in2, out1, out2) - if(nargin != 2) + if (nargin != 2 && nargin != 6) print_usage (); endif - if (! isstruct(Asys) ) - error ("1st input argument is not a system data structure"); - elseif (! isstruct(Bsys) ) - error ("2nd input argument is not a system data structure"); + + ## Sanitize sys1 + if (isstruct (_sys1)) + sys1 = _sys1; + sys1wasmatrix = 0; + elseif (ismatrix (_sys1)) + sys1 = ss ([], [], [], _sys1); + sys1wasmatrix = 1; + else + error ("parallel: argument 1 (sys1) invalid"); endif - [Ann, Anz, mA] = sysdimensions(Asys); - [Bnn, Bnz, mB] = sysdimensions(Bsys); - if (mA != mB) - error ("Asys has %d inputs, Bsys has %d inputs", mA, mB); + + ## Sanitize sys2 + if (isstruct (_sys2)) + sys2 = _sys2; + sys2wasmatrix = 0; + elseif (ismatrix (_sys2)) + sys2 = ss ([], [], [], _sys2); + sys2wasmatrix = 1; + else + error ("parallel: argument 2 (sys2) invalid"); endif - ## save signal names - Ain = sysgetsignals (Asys, "in"); + ## Handle digital gains + if (sys1wasmatrix) + if (is_digital (sys2, 2) == 1) # -1 for mixed systems! + t_sam = sysgettsam (sys2); + sys1 = ss ([], [], [], _sys1, t_sam); # sys1 = c2d (sys1, t_sam) doesn't work + endif + endif - ## change signal names to avoid warning messages from sysgroup - Asys = syssetsignals (Asys, "in", __sysdefioname__ (length (Ain), "Ain_u")); - Bsys = syssetsignals (Bsys, "in", __sysdefioname__ (length (Ain), "Bin_u")); + if (sys2wasmatrix) + if (is_digital (sys1, 2) == 1) + t_sam = sysgettsam (sys1); + sys2 = ss ([], [], [], _sys2, t_sam); + endif + endif - sysp = sysgroup (Asys, Bsys); - sysD = ss ([], [], [], [eye(mA); eye(mA)]); - sysp = sysmult (sysp, sysD); - sysp = syssetsignals (sysp, "in", Ain); + if (nargin == 2) # Simple case + warning ("parallel: meaning has changed for compatibility reasons. use sysparallel for the old octave implementation."); + + ## Let sysadd do the job + sys = sysadd (sys1, sys2); + + else # Complex case + + error ("parallel: complex case (6 arguments) not implemented yet"); + + endif + endfunction + + +%!shared G, H, sys, num, den, num_exp, den_exp +%! G = ss ([0], [1], [1], [0]); +%! H = 1; +%! sys = parallel1 (G, H); +%! [num, den] = sys2tf (sys); +%! num_exp = [1, 1]; +%! den_exp = [1, 0]; +%!assert(num, num_exp); +%!assert(den, den_exp); Added: trunk/octave-forge/main/control/inst/sysparallel.m =================================================================== --- trunk/octave-forge/main/control/inst/sysparallel.m (rev 0) +++ trunk/octave-forge/main/control/inst/sysparallel.m 2009-08-25 15:15:49 UTC (rev 6136) @@ -0,0 +1,72 @@ +## Copyright (C) 1996, 2000, 2002, 2004, 2005, 2006, 2007 +## Auburn University. All rights reserved. +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{ksys} =} sysparallel (@var{asys}, @var{bsys}) +## Forms the parallel connection of two systems. +## +## @example +## @group +## -------------------- +## | -------- | +## u ----->|----> | asys |--->|----> y1 +## | | -------- | +## | | -------- | +## |--->|----> | bsys |--->|----> y2 +## | -------- | +## -------------------- +## ksys +## @end group +## @end example +## @end deftypefn + +## Author: David Clem +## Created: August 15, 1994 +## completely rewritten Oct 1996 a s hodel +## SYS_INTERNAL accesses members of system structure + +function sysp = sysparallel (Asys, Bsys) + + if(nargin != 2) + print_usage (); + endif + if (! isstruct(Asys) ) + error ("1st input argument is not a system data structure"); + elseif (! isstruct(Bsys) ) + error ("2nd input argument is not a system data structure"); + endif + [Ann, Anz, mA] = sysdimensions(Asys); + [Bnn, Bnz, mB] = sysdimensions(Bsys); + if (mA != mB) + error ("Asys has %d inputs, Bsys has %d inputs", mA, mB); + endif + + ## save signal names + Ain = sysgetsignals (Asys, "in"); + + ## change signal names to avoid warning messages from sysgroup + Asys = syssetsignals (Asys, "in", __sysdefioname__ (length (Ain), "Ain_u")); + Bsys = syssetsignals (Bsys, "in", __sysdefioname__ (length (Ain), "Bin_u")); + + sysp = sysgroup (Asys, Bsys); + sysD = ss ([], [], [], [eye(mA); eye(mA)]); + + sysp = sysmult (sysp, sysD); + sysp = syssetsignals (sysp, "in", Ain); + +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |