0001 function f = miir(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 VERSION = '$Id: miir.m,v 1.17 2007/10/24 10:55:11 ingo Exp $';
0067
0068
0069
0070 function f = init()
0071 f.name = 'None';
0072 f.fs = 0;
0073 f.ntaps = 0;
0074 f.a = [];
0075 f.b = [];
0076 f.gain = 0;
0077 f.histin = [];
0078 f.histout = [];
0079 f.infile = '';
0080 f.plist = plist();
0081 f.created = time;
0082 f.version = VERSION;
0083 f = class(f, 'miir');
0084 end
0085
0086
0087
0088 switch nargin
0089
0090
0091
0092 case 0
0093 f = init();
0094
0095
0096 case 1
0097
0098
0099 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl')
0100 f = fromxml(varargin{1});
0101
0102 elseif ischar(varargin{1})
0103
0104 f = init();
0105 filename = varargin{1};
0106 [path, name, ext, vers] = fileparts(filename);
0107 switch ext
0108 case '.mat'
0109 f = load(filename);
0110 case '.xml'
0111 f = xmlparse(miir, filename);
0112 case '.filt'
0113 filt = mfiltload(filename);
0114 f.name = filt.name;
0115 f.fs = filt.fs;
0116 f.ntaps = filt.ntaps;
0117 f.a = filt.a;
0118 f.b = filt.b;
0119 f.gain = filt.gain;
0120 f.histin = filt.histin;
0121 f.histout = filt.histout;
0122 f.infile = filename;
0123 case '.fil'
0124 filt = filload(filename);
0125 f.name = filt.name;
0126 f.fs = filt.fs;
0127 f.ntaps = filt.ntaps;
0128 f.a = filt.a;
0129 f.b = filt.b;
0130 f.gain = filt.g;
0131 f.histin = filt.histin;
0132 f.histout = filt.histout;
0133 f.infile = filename;
0134 otherwise
0135 error('### Unknown file type.');
0136 end
0137
0138
0139
0140 elseif isa(varargin{1}, 'miir')
0141 f = varargin{1};
0142 f.version = VERSION;
0143
0144
0145
0146 elseif isstruct(varargin{1})
0147
0148 f = init();
0149
0150 fields = fieldnames(varargin{1});
0151 for ii = 1:length(fields)
0152 field = fields{ii};
0153
0154
0155 if strcmp(field, 'plist')
0156 if isstruct(varargin{1}.(field))
0157 f.(field) = plist(varargin{1}.(field));
0158 else
0159 f.(field) = varargin{1}.(field);
0160 end
0161
0162 elseif strcmp(field, 'created')
0163 created = varargin{1}.created;
0164 if isstruct(created)
0165 created = time(created);
0166 end
0167 f.created = created;
0168
0169 else
0170 try
0171 f.(field) = varargin{1}.(field);
0172 catch
0173 error('### The field ''%s'' in the struct is not a mfir property.', field)
0174 end
0175 end
0176 end
0177
0178
0179
0180
0181 elseif isa(varargin{1}, 'plist')
0182
0183 pl = varargin{1};
0184 type = find(pl, 'type');
0185 pzm = find(pl, 'pzmodel');
0186
0187 f = init();
0188
0189
0190 if isempty(type) && isempty(pzm)
0191 type = 'lowpass';
0192 end
0193
0194 if ~isempty(type)
0195
0196 plo = parseFilterParams(pl);
0197 switch type
0198 case 'lowpass'
0199 f = mklowpass(f, plo);
0200 case 'highpass'
0201 f = mkhighpass(f, plo);
0202 case 'bandpass'
0203 f = mkbandpass(f, plo);
0204 case 'bandreject'
0205 f = mkbandreject(f, plo);
0206 otherwise
0207 error('### unknown standard filter type in miir constructor.');
0208 end
0209 f.infile = '';
0210 f.plist = plo;
0211
0212 elseif ~isempty(pzm)
0213
0214 f = init();
0215
0216 fs = find(pl, 'fs');
0217 if isempty(fs)
0218
0219 fs = 8*getupperFreq(pzm);
0220 warning([sprintf('!!! no sample rate specified. Designing for fs=%2.2fHz.', fs)...
0221 sprintf('\nThe filter will be redesigned later when used.')]);
0222
0223 end
0224
0225 f = tomiir(pzm, fs);
0226 f = set(f, 'name', get(pzm, 'name'));
0227 f = set(f, 'plist', pl);
0228
0229 else
0230 error('### unknown constructor type for miir.');
0231 end
0232 else
0233 error('### unknown constructor type for miir.');
0234 end
0235
0236
0237 case 2
0238
0239
0240 if isa(varargin{1}, 'database')
0241 f = retrieve(varargin{1}, varargin{2:end});
0242 else
0243 pzm = varargin{1};
0244 if ~isa(pzm, 'pzmodel')
0245 error('### unknown constructor type for miir.');
0246 end
0247 pl = varargin{2};
0248 if ~isa(pl, 'plist')
0249 error('### unknown constructor type for miir.');
0250 end
0251
0252 pl = append(pl, param('pzmodel', pzm));
0253
0254 f = miir(pl);
0255 end
0256
0257
0258 case 3
0259
0260
0261 a = varargin{1};
0262 b = varargin{2};
0263 fs = varargin{3};
0264 if ~isnumeric(a) || ~isnumeric(b) || ~isnumeric(fs)
0265 error('### unknown constructor type for miir.');
0266 end
0267
0268 f = init();
0269 f.name = 'AB';
0270 f.fs = fs;
0271 f.ntaps = length(a);
0272 f.a = a;
0273 f.b = b;
0274 f.gain = 1;
0275 f.histin = zeros(1,f.ntaps-1);
0276 f.histout = zeros(1,f.ntaps-1);
0277
0278 otherwise
0279 error('### incorrect input arguments for miir constructor.');
0280 end
0281
0282 end
0283