diff m-toolbox/classes/@pzmodel/fromPolesAndZeros.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/fromPolesAndZeros.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,63 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% FUNCTION:    fromPolesAndZeros
+%
+% DESCRIPTION: Construct a pzmodel from poles and zeros
+%
+% CALL:        pzm = fromPolesAndZeros(a, pl)
+%
+% PARAMETER:   pl   - plist
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function pzm = fromPolesAndZeros(pzm, pli)
+
+  VERSION = '$Id: fromPolesAndZeros.m,v 1.20 2011/08/15 10:10:33 hewitson Exp $';
+
+
+  % get pzmodel info
+  ii = pzmodel.getInfo('pzmodel', 'From Poles/Zeros');
+
+  % Set the method version string in the minfo object
+  ii.setMversion([VERSION '-->' ii.mversion]);
+
+  % Combine input plist with default values
+  pl = applyDefaults(ii.plists, pli);
+
+  % Set fields
+  pzm.gain = find(pl, 'gain');
+  ps       = find(pl, 'poles');
+  zs       = find(pl, 'zeros');
+
+  % If the poles/zeros in the plist are no pz-objects then convert them
+  if ~isa(ps, 'pz') && ~isempty(ps)
+    ps = pz(ps);
+  end
+  if ~isa(zs, 'pz') && ~isempty(zs)
+    zs = pz(zs);
+  end
+
+  % Add only valid poles
+  poles = [];
+  for kk = 1:numel(ps)
+    if ~isnan(ps(kk).f)
+      poles = [poles ps(kk)];
+    end
+  end
+  pl.pset('poles', poles);
+
+  % Add only valid zeros
+  zeros = [];
+  for kk = 1:numel(zs)
+    if ~isnan(zs(kk).f)
+      zeros = [zeros zs(kk)];
+    end
+  end
+  pl.pset('zeros', zeros);  
+  
+  % Set object properties from input plist
+  pzm.setObjectProperties(pl);
+
+  % Add history
+  pzm.addHistory(ii, pl, [], []);
+
+end