From: <par...@us...> - 2010-10-09 13:42:22
|
Revision: 7829 http://octave.svn.sourceforge.net/octave/?rev=7829&view=rev Author: paramaniac Date: 2010-10-09 13:42:15 +0000 (Sat, 09 Oct 2010) Log Message: ----------- control: fix __set__ for frd models Modified Paths: -------------- trunk/octave-forge/main/control/devel/@frd/__set__.m trunk/octave-forge/main/control/devel/@frd/frd.m Added Paths: ----------- trunk/octave-forge/main/control/devel/__adjust_frd_data__.m Modified: trunk/octave-forge/main/control/devel/@frd/__set__.m =================================================================== --- trunk/octave-forge/main/control/devel/@frd/__set__.m 2010-10-09 13:09:17 UTC (rev 7828) +++ trunk/octave-forge/main/control/devel/@frd/__set__.m 2010-10-09 13:42:15 UTC (rev 7829) @@ -24,18 +24,14 @@ function sys = __set__ (sys, prop, val) - switch (prop) # {<internal name>, <user name>} + switch (prop) # {<internal name>, <user name>} case {"h", "r", "resp", "response"} - if (ndims (val) != 3 && ! isempty (val)) # TODO: share code with @frd/frd.m - val = reshape (val, 1, 1, []); - elseif (isempty (val)) - val = zeros (0, 0, 0); - endif + val = __adjust_frd_data__ (val, sys.w, 0); __frd_dim__ (val, sys.w); sys.H = val; case {"w", "f", "freq", "frequency"} - val = reshape (val, [], 1); + [jnk, val] = __adjust_frd_data__ (sys.H, val, 0); ## TODO: use [~, val] for octave 3.4 __frd_dim__ (sys.H, val); sys.w = val; Modified: trunk/octave-forge/main/control/devel/@frd/frd.m =================================================================== --- trunk/octave-forge/main/control/devel/@frd/frd.m 2010-10-09 13:09:17 UTC (rev 7828) +++ trunk/octave-forge/main/control/devel/@frd/frd.m 2010-10-09 13:42:15 UTC (rev 7829) @@ -73,31 +73,8 @@ endswitch - ## TODO: create separate function - if (ndims (H) != 3 && ! isempty (H)) - if (is_real_scalar (H)) # static gain (H is a scalar) - H = reshape (H, 1, 1, []); - tsam = -1; - elseif (isvector (H)) # SISO system (H is a vector) - H = reshape (H, 1, 1, []); - else # static gain (H is a matrix) - if (! is_real_matrix (H)) - error ("frd: static gain matrix must be real"); - endif - H = reshape (H, rows (H), []); - lw = length (w); - if (lw > 1) - H = repmat (H, [1, 1, lw]); # needed for "frd1 + matrix2" or "matrix1 * frd2) - endif - tsam = -1; - endif - elseif (isempty (H)) - H = zeros (0, 0, 0); - tsam = -1; - endif + [H, w, tsam] = __adjust_frd_data__ (H, w, tsam); - w = reshape (w, [], 1); - [p, m] = __frd_dim__ (H, w); frdata = struct ("H", H, "w", w); Added: trunk/octave-forge/main/control/devel/__adjust_frd_data__.m =================================================================== --- trunk/octave-forge/main/control/devel/__adjust_frd_data__.m (rev 0) +++ trunk/octave-forge/main/control/devel/__adjust_frd_data__.m 2010-10-09 13:42:15 UTC (rev 7829) @@ -0,0 +1,51 @@ +## 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 -*- +## Common code for adjusting FRD model data. +## Used by @frd/frd.m and @frd/__set__.m + +## Author: Lukas Reichlin <luk...@gm...> +## Created: October 2010 +## Version: 0.1 + +function [H, w, tsam] = __adjust_frd_data__ (H, w, tsam); + + if (ndims (H) != 3 && ! isempty (H)) + if (is_real_scalar (H)) # static gain (H is a real scalar) + H = reshape (H, 1, 1, []); + tsam = -1; + elseif (isvector (H)) # SISO system (H is a complex vector) + H = reshape (H, 1, 1, []); + elseif (is_real_matrix (H)) # static gain (H is a real matrix) + H = reshape (H, rows (H), []); + lw = length (w); + if (lw > 1) + H = repmat (H, [1, 1, lw]); # needed for "frd1 + matrix2" or "matrix1 * frd2) + endif + tsam = -1; + else + error ("frd: static gain matrix must be real"); + endif + elseif (isempty (H)) + H = zeros (0, 0, 0); + tsam = -1; + endif + + w = reshape (w, [], 1); + +endfunction \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |