diff m-toolbox/classes/@pzmodel/times.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/@pzmodel/times.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,145 @@
+% TIMES overloads the multiplication operator for pzmodels.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION: TIMES overloads the multiplication operator for pzmodels.
+%
+% CALL:        pzm = times(pzm1, pzm2);
+%              pzm = pzm1.*pzm2;
+%
+% <a href="matlab:utils.helper.displayMethodInfo('pzmodel', 'times')">Parameters Description</a>
+%
+% VERSION:     $Id: times.m,v 1.13 2011/04/08 08:56:32 hewitson Exp $
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function varargout = times(varargin)
+
+  %%% Check if this is a call for parameters
+  if utils.helper.isinfocall(varargin{:})
+    varargout{1} = getInfo(varargin{3});
+    return
+  end
+
+  %%% Input objects checks
+  if nargin < 1
+    error('### incorrect number of inputs.')
+  end
+
+  % Collect input pzmodels, plists and input variable names
+  in_names = cell(size(varargin));
+  for ii = 1:nargin
+    in_names{end+1} = inputname(ii);
+  end
+  args = utils.helper.collect_values(varargin);
+  [pzms, invars, rest] = utils.helper.collect_objects(args, 'pzmodel', in_names);
+  pl              = utils.helper.collect_objects(args, 'plist');
+  
+  % Combine with default plist
+  pl = combine(pl, getDefaultPlist('Default'));
+  
+  % Decide on a deep copy or a modify
+  cpzms = copy(pzms, nargout);
+  
+  % Loop over pzmodels and modify the first
+  pzmout = cpzms(1);
+  hists  = pzmout.hist;
+  name   = pzmout.name;
+  for pp=2:numel(cpzms)
+
+    % process this pzmodel
+    pzm = cpzms(pp);
+    
+    % Combine the poles and zeros
+    pzmout.poles = [pzmout.poles pzm.poles];
+    pzmout.zeros = [pzmout.zeros pzm.zeros];
+    pzmout.gain  = pzmout.gain .* pzm.gain;
+    pzmout.delay  = pzmout.delay + pzm.delay;
+    
+    % Multiply the units
+    if ~isempty(pzm.iunits.strs) && ~isempty(pzmout.ounits.strs)
+      if pzmout.ounits ~= pzm.iunits
+        error('### Input units of model %s %s must match the output units of model %s %s', ...
+          pzm.name, char(pzm.iunits), pzmout.name, char(pzmout.ounits));
+      end
+    end
+    if ~isempty(pzm.ounits.strs)
+      pzmout.ounits = pzm.ounits;
+    end  
+    if isempty(pzmout.iunits.strs)
+      pzmout.iunits = pzm.iunits;
+    end
+    
+    % compute the new name
+    name = ['(' name '.*' pzm.name ')'];
+
+    hists = [hists pzm.hist];
+    
+  end
+  
+  % set name
+  pzmout.name = name;
+  % Add history
+  pzmout.addHistory(getInfo('None'), pl, invars, hists);
+
+  % Outputs
+  varargout{1} = pzmout;
+
+end
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                               Local Functions                               %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% FUNCTION:    getInfo
+%
+% DESCRIPTION: Get Info Object
+%
+% HISTORY:     11-07-07 M Hewitson
+%                Creation.
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function ii = getInfo(varargin)
+  if nargin == 1 && strcmpi(varargin{1}, 'None')
+    sets = {};
+    pls   = [];
+  elseif nargin == 1&& ~isempty(varargin{1}) && ischar(varargin{1})
+    sets{1} = varargin{1};
+    pls = getDefaultPlist(sets{1});
+  else
+    sets = {'Default'};
+    pls = [];
+    for kk=1:numel(sets)
+      pls = [pls getDefaultPlist(sets{kk})];
+    end
+  end
+  % Build info object
+  ii = minfo(mfilename, 'pzmodel', 'ltpda', utils.const.categories.aop, '$Id: times.m,v 1.13 2011/04/08 08:56:32 hewitson Exp $', sets, pls);
+  ii.setModifier(false);
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% FUNCTION:    getDefaultPlist
+%
+% DESCRIPTION: Get Default Plist
+%
+% HISTORY:     11-07-07 M Hewitson
+%                Creation.
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function plout = getDefaultPlist(set)
+  persistent pl;  
+  if exist('pl', 'var')==0 || isempty(pl)
+    pl = buildplist();
+  end
+  plout = pl;  
+end
+
+function pl = buildplist()
+  pl = plist.EMPTY_PLIST;
+end