comparison m-toolbox/classes/@pzmodel/tomiir.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % TOMIIR converts a pzmodel to an IIR filter using a bilinear transform.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: TOMIIR converts a pzmodel to an IIR filter using a bilinear
5 % transform.
6 %
7 % CALL: f = tomiir(pzm, fs); % construct for this sample frequency fs
8 % f = tomiir(pzm, pl); % construct from plist
9 %
10 % <a href="matlab:utils.helper.displayMethodInfo('pzmodel', 'tomiir')">Parameters Description</a>
11 %
12 % VERSION: $Id: tomiir.m,v 1.18 2011/04/08 08:56:32 hewitson Exp $
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16 function varargout = tomiir(varargin)
17
18 %%% Check if this is a call for parameters
19 if utils.helper.isinfocall(varargin{:})
20 varargout{1} = getInfo(varargin{3});
21 return
22 end
23
24 % Check output arguments number
25 if nargout == 0
26 error('### pzmodel/tomiir cannot be used as a modifier. Please give an output variable.');
27 end
28
29 % Collect input variable names
30 in_names = cell(size(varargin));
31 for ii = 1:nargin,in_names{ii} = inputname(ii);end
32
33 % Collect all AOs
34 [pzms, pzm_invars] = utils.helper.collect_objects(varargin(:), 'pzmodel', in_names);
35 pls = utils.helper.collect_objects(varargin(:), 'plist');
36
37 % Store inhists to suppress intermediate history steps
38 inhists = [pzms(:).hist];
39
40 % Get default parameters
41 pl = parse(pls, getDefaultPlist);
42
43 % Decide on a deep copy or a modify
44 pzms = copy(pzms, nargout);
45
46 % Get fs
47 fs = pl.find('fs');
48 if nargin == 2
49 if isnumeric(varargin{2})
50 fs = varargin{2};
51 end
52 end
53
54 si = size(pzms);
55 f(si(1), si(2)) = miir();
56 for kk = 1:numel(pzms)
57
58 % get a and b coefficients
59 [a,b] = pzm2ab(pzms(kk), fs);
60
61 % throws a warning if the model has a delay
62 if(pzms(kk).delay~=0)
63 disp('!!! PZmodel delay is not used in the discretization')
64 end
65 % make MIIR filter
66 f(kk) = miir(a,b,fs);
67 f(kk).addHistory(getInfo, pl, pzm_invars(kk), inhists(kk));
68 end
69
70 % Set output
71 if nargout == numel(f)
72 % List of outputs
73 for ii = 1:numel(f)
74 varargout{ii} = f(ii);
75 end
76 else
77 % Single output
78 varargout{1} = f;
79 end
80
81 end
82
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 % Local Functions %
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 %
89 % FUNCTION: getInfo
90 %
91 % DESCRIPTION: Get Info Object
92 %
93 % HISTORY: 11-07-07 M Hewitson
94 % Creation.
95 %
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97
98 function ii = getInfo(varargin)
99 if nargin == 1 && strcmpi(varargin{1}, 'None')
100 sets = {};
101 pl = [];
102 else
103 sets = {'Default'};
104 pl = getDefaultPlist;
105 end
106 % Build info object
107 ii = minfo(mfilename, 'pzmodel', 'ltpda', utils.const.categories.op, '$Id: tomiir.m,v 1.18 2011/04/08 08:56:32 hewitson Exp $', sets, pl);
108 ii.setModifier(false);
109 end
110
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 %
113 % FUNCTION: getDefaultPlist
114 %
115 % DESCRIPTION: Get Default Plist
116 %
117 % HISTORY: 11-07-07 M Hewitson
118 % Creation.
119 %
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121
122 function plout = getDefaultPlist()
123 persistent pl;
124 if exist('pl', 'var')==0 || isempty(pl)
125 pl = buildplist();
126 end
127 plout = pl;
128 end
129
130 function plo = buildplist()
131 plo = plist();
132
133 % FS
134 p = param({'fs', 'Frequency of the iir filter.'}, paramValue.DOUBLE_VALUE(1));
135 plo.append(p);
136
137 end
138