From: <par...@us...> - 2010-10-08 22:17:26
|
Revision: 7818 http://octave.svn.sourceforge.net/octave/?rev=7818&view=rev Author: paramaniac Date: 2010-10-08 22:17:19 +0000 (Fri, 08 Oct 2010) Log Message: ----------- control: add FRD models in a very early development stage Added Paths: ----------- trunk/octave-forge/main/control/devel/@frd/ trunk/octave-forge/main/control/devel/@frd/display.m trunk/octave-forge/main/control/devel/@frd/frd.m trunk/octave-forge/main/control/devel/__frd_dim__.m trunk/octave-forge/main/control/devel/frd_test.m Added: trunk/octave-forge/main/control/devel/@frd/display.m =================================================================== --- trunk/octave-forge/main/control/devel/@frd/display.m (rev 0) +++ trunk/octave-forge/main/control/devel/@frd/display.m 2010-10-08 22:17:19 UTC (rev 7818) @@ -0,0 +1,49 @@ +## Copyright (C) 2010 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 this program. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## Display routine for SS objects. + +## Author: Lukas Reichlin <luk...@gm...> +## Created: February 2010 +## Version: 0.1 + +function display (sys) + + [inname, outname, tsam] = __lti_data__ (sys.lti); + + [inname, m] = __labels__ (inname, "u"); + [outname, p] = __labels__ (outname, "y"); + + disp (""); + + disp (["Frequency response """, inputname(1), """ from input "]); + + sys.H + sys.w + + display (sys.lti); # display sampling time + + if (tsam == -1) + disp ("Static gain."); + elseif (tsam == 0) + disp ("Continuous-time model."); + else + disp ("Discrete-time model."); + endif + +endfunction Added: trunk/octave-forge/main/control/devel/@frd/frd.m =================================================================== --- trunk/octave-forge/main/control/devel/@frd/frd.m (rev 0) +++ trunk/octave-forge/main/control/devel/@frd/frd.m 2010-10-08 22:17:19 UTC (rev 7818) @@ -0,0 +1,93 @@ +## Copyright (C) 2010 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 this program. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{sys} =} frd (@var{sys}, @var{w}) +## @deftypefnx {Function File} {@var{sys} =} frd (@var{H}, @var{w}) +## @deftypefnx {Function File} {@var{sys} =} frd (@var{H}, @var{w}, @var{tsam}) +## Create or convert to frequency response data. +## @end deftypefn + +## Author: Lukas Reichlin <luk...@gm...> +## Created: February 2010 +## Version: 0.1 + +function sys = frd (H = [], w = [], varargin) + + ## model precedence: frd > ss > zpk > tf > double + superiorto ("ss", "zpk", "tf", "double"); + + argc = 0; + + switch (nargin) + case 0 + tsam = -1; + + case 1 + if (isa (H, "frd")) # already in frd form + sys = H; + return; + else + print_usage (); + endif + + case 2 + if (isa (H, "lti")) # another lti object + [sys, alti] = __sys2frd__ (H, w); + sys.lti = alti; # preserve lti properties + return; + else # sys = frd (H, w) + tsam = 0; + endif + + otherwise # default case + argc = numel (varargin); + + if (issample (varargin{1}, 1)) # sys = frd (H, w, tsam, "prop1, "val1", ...) + tsam = varargin{1}; + argc--; + if (argc > 0) + varargin = varargin(2:end); + endif + else # sys = frd (H, w, "prop1, "val1", ...) + tsam = 0; + endif + + endswitch + + if (ndims (H) != 3 && ! isempty (H)) + H = reshape (H, 1, 1, []); + elseif (isempty (H)) + H = zeros (0, 0, 0); + tsam = -1; + endif + + w = reshape (w, [], 1); + + [p, m] = __frd_dim__ (H, w); + + frdata = struct ("H", H, "w", w); + + ltisys = lti (p, m, tsam); + + sys = class (frdata, "frd", ltisys); + + if (argc > 0) + sys = set (sys, varargin{:}); + endif + +endfunction Added: trunk/octave-forge/main/control/devel/__frd_dim__.m =================================================================== --- trunk/octave-forge/main/control/devel/__frd_dim__.m (rev 0) +++ trunk/octave-forge/main/control/devel/__frd_dim__.m 2010-10-08 22:17:19 UTC (rev 7818) @@ -0,0 +1,49 @@ +## Copyright (C) 2010 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 this program. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## Number of outputs and inputs of transfer function numerator and +## denominator. For internal use only. + +## Author: Lukas Reichlin <luk...@gm...> +## Created: February 2010 +## Version: 0.1 + +function [p, m, l] = __frd_dim__ (H, w) + + if (! isnumeric (H)) # TODO: watch out for __set__ vector case + error ("frd: H must be a 3-dimensional numeric array"); + endif + + if (! isempty (w) && (! is_real_vector (w) || any (w < 0))) + error ("frd: w must be a vector of positive real numbers"); + endif + + if (isempty (H)) + p = m = l = 0; + else + [p, m, l] = size (H); + endif + + lw = length (w); + + if (l != lw) + error ("frd: H (%dx%dx%d) and w (%d) must have equal length", + p, m, l, lw); + endif + +endfunction \ No newline at end of file Added: trunk/octave-forge/main/control/devel/frd_test.m =================================================================== --- trunk/octave-forge/main/control/devel/frd_test.m (rev 0) +++ trunk/octave-forge/main/control/devel/frd_test.m 2010-10-08 22:17:19 UTC (rev 7818) @@ -0,0 +1,9 @@ +sys = frd (1, 1) + +sys = frd (2+5i, 3, 0.1) + +sys = frd (ones (2, 3, 5), 1:5) + +frd + +frd ([], []) \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |