From: <par...@us...> - 2012-05-06 19:37:01
|
Revision: 10368 http://octave.svn.sourceforge.net/octave/?rev=10368&view=rev Author: paramaniac Date: 2012-05-06 19:36:54 +0000 (Sun, 06 May 2012) Log Message: ----------- control: support transfer function variable z^-1 Modified Paths: -------------- trunk/octave-forge/main/control/inst/@tf/__set__.m trunk/octave-forge/main/control/inst/@tf/__sys_group__.m trunk/octave-forge/main/control/inst/@tf/display.m trunk/octave-forge/main/control/inst/@tf/tf.m trunk/octave-forge/main/control/inst/filt.m Added Paths: ----------- trunk/octave-forge/main/control/inst/tfpoly2str.m Modified: trunk/octave-forge/main/control/inst/@tf/__set__.m =================================================================== --- trunk/octave-forge/main/control/inst/@tf/__set__.m 2012-05-06 15:53:35 UTC (rev 10367) +++ trunk/octave-forge/main/control/inst/@tf/__set__.m 2012-05-06 19:36:54 UTC (rev 10368) @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Lukas F. Reichlin +## Copyright (C) 2009, 2012 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -20,7 +20,7 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: October 2009 -## Version: 0.1 +## Version: 0.2 function sys = __set__ (sys, prop, val) @@ -42,6 +42,13 @@ error ("tf: set: invalid transfer function variable"); endif + case "inv" + if (islogical (val)) + sys.inv = logical (val); + else + error ("tf: set: property 'inv' must be a logical"); + endif + otherwise error ("tf: set: invalid property name"); Modified: trunk/octave-forge/main/control/inst/@tf/__sys_group__.m =================================================================== --- trunk/octave-forge/main/control/inst/@tf/__sys_group__.m 2012-05-06 15:53:35 UTC (rev 10367) +++ trunk/octave-forge/main/control/inst/@tf/__sys_group__.m 2012-05-06 19:36:54 UTC (rev 10368) @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Lukas F. Reichlin +## Copyright (C) 2009, 2012 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -22,7 +22,7 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: September 2009 -## Version: 0.1 +## Version: 0.2 function retsys = __sys_group__ (sys1, sys2) @@ -61,4 +61,8 @@ retsys.tfvar = sys1.tfvar; endif -endfunction \ No newline at end of file + if (sys1.inv && sys2.inv) + retsys.inv = true; + endif + +endfunction Modified: trunk/octave-forge/main/control/inst/@tf/display.m =================================================================== --- trunk/octave-forge/main/control/inst/@tf/display.m 2012-05-06 15:53:35 UTC (rev 10367) +++ trunk/octave-forge/main/control/inst/@tf/display.m 2012-05-06 19:36:54 UTC (rev 10368) @@ -1,4 +1,4 @@ -## Copyright (C) 2009, 2010, 2011 Lukas F. Reichlin +## Copyright (C) 2009, 2010, 2011, 2012 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -20,7 +20,7 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: September 2009 -## Version: 0.3 +## Version: 0.4 function display (sys) @@ -31,12 +31,19 @@ [outname, p] = __labels__ (outname, "y"); disp (""); + + if (sys.inv) + [num, den] = filtdata (sys); + else + num = sys.num; + den = sys.den; + endif for nu = 1 : m disp (["Transfer function '", sysname, "' from input '", inname{nu}, "' to output ..."]); disp (""); for ny = 1 : p - __disp_frac__ (sys.num{ny, nu}, sys.den{ny, nu}, sys.tfvar, outname{ny}); + __disp_frac__ (num{ny, nu}, den{ny, nu}, sys.tfvar, outname{ny}); endfor endfor @@ -56,10 +63,12 @@ function __disp_frac__ (num, den, tfvar, name) MAX_LEN = 12; # max length of output name + + tfp = isa (num, "tfpoly"); - if (num == 0) + if (tfp && num == 0) str = [" ", name, ": 0"]; - elseif (den == 1) + elseif (tfp && den == 1) str = [" ", name, ": "]; numstr = tfpoly2str (num, tfvar); str = [str, numstr]; Modified: trunk/octave-forge/main/control/inst/@tf/tf.m =================================================================== --- trunk/octave-forge/main/control/inst/@tf/tf.m 2012-05-06 15:53:35 UTC (rev 10367) +++ trunk/octave-forge/main/control/inst/@tf/tf.m 2012-05-06 19:36:54 UTC (rev 10368) @@ -1,4 +1,4 @@ -## Copyright (C) 2009, 2010, 2011 Lukas F. Reichlin +## Copyright (C) 2009, 2010, 2011, 2012 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -119,7 +119,7 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: September 2009 -## Version: 0.2.1 +## Version: 0.3 function sys = tf (num = {}, den = {}, varargin) @@ -196,7 +196,8 @@ tfdata = struct ("num", {num}, "den", {den}, - "tfvar", tfvar); # struct for tf-specific data + "tfvar", tfvar, + "inv", false); # struct for tf-specific data ltisys = lti (p, m, tsam); # parent class for general lti data Modified: trunk/octave-forge/main/control/inst/filt.m =================================================================== --- trunk/octave-forge/main/control/inst/filt.m 2012-05-06 15:53:35 UTC (rev 10367) +++ trunk/octave-forge/main/control/inst/filt.m 2012-05-06 19:36:54 UTC (rev 10368) @@ -116,7 +116,7 @@ ## use standard tf constructor ## sys is stored and displayed in standard z form, not z^-1 - sys = tf (num, den, tsam, varargin{:}); + sys = tf (num, den, tsam, "inv", true, varargin{:}); endswitch endfunction Added: trunk/octave-forge/main/control/inst/tfpoly2str.m =================================================================== --- trunk/octave-forge/main/control/inst/tfpoly2str.m (rev 0) +++ trunk/octave-forge/main/control/inst/tfpoly2str.m 2012-05-06 19:36:54 UTC (rev 10368) @@ -0,0 +1,89 @@ +## Copyright (C) 2012 Lukas F. Reichlin +## +## This file is part of LTI Syncope. +## +## LTI Syncope 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. +## +## LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{str} =} tfpoly2str (@var{p}) +## @deftypefnx {Function File} {@var{str} =} tfpoly2str (@var{p}, @var{tfvar}) +## Return the string of a polynomial with string @var{tfvar} as variable. +## @end deftypefn + +## Author: Lukas Reichlin <luk...@gm...> +## Created: May 2012 +## Version: 0.1 + +function str = tfpoly2str (p, tfvar = "x") + + str = ""; + + lp = numel (p); + + if (lp > 0) + ## first element (lowest order 0) + a = p(1); + + if (a < 0) + cs = "-"; + else + cs = ""; + endif + + str = [cs, num2str(abs (a), 4)]; + + if (lp > 1) + ## remaining elements of higher order + for k = 2 : lp + a = p(k); + + if (a != 0) + if (a < 0) + cs = " - "; + else + cs = " + "; + endif + + if (abs (a) == 1) + str = [str, cs, __variable__(tfvar, k-1)]; + else + str = [str, cs, __coefficient__(a), " ", __variable__(tfvar, k-1)]; + endif + endif + endfor + + endif + endif + +endfunction + + +function str = __coefficient__ (a) + + b = abs (a); + + if (b == 1) + str = ""; + else + str = num2str (b, 4); + endif + +endfunction + + +function str = __variable__ (tfvar, n) + + str = [tfvar, "^-", num2str(n)]; + +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |