Home > classes > @miir > miir.m

miir

PURPOSE ^

MIIR IIR filter object class constructor.

SYNOPSIS ^

function f = miir(varargin)

DESCRIPTION ^

 MIIR IIR filter object class constructor.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: MIIR IIR filter object class constructor.
              Create a miir object.

 CONSTRUCTOR: f = miir()
                  creates an empty miir object.

              f = miir(fi)
                  creates a copy of the input miir object, fi.

              f = miir(a,b,fs)
                  creates a miir object from the coefficient vectors 'a' and 'b' **.
                  The sample rate for which the filter is designed should
                  be specified as well.

              f = miir('foo_iir.fil')
                  create a miir object from a LISO IIR .fil file.

              f = miir('foo_iir.xml')
                  create a miir object loading the miir object from disk.

              f = miir('foo_iir.mat')
                  create a miir object loading the miir object from disk

              f = miir(pl)
                  create a miir object from the description
                  given in the parameter list.

 Parameter sets for plist constructor (in order of priority):

 From XML File
 -------------

   Construct an MIIR by loading it from an XML file.

   'filename' - construct an MIIR from a filename.
                Example: plist('filename', 'm1.xml')
                [default: empty string]


 From MAT File
 -------------

   Construct an MIIR by loading it from a MAT file.

   'filename' - construct an MIIR from a filename.
                Example: plist('filename', 'm1.mat')
                [default: empty string]


 From LISO File
 --------------

   Construct an MIIR by loading it from a LISO file.

   'filename' - construct an MIIR from a filename.
                Example: plist('filename', 'm1.fil')
                [default: empty string]


 From Repository
 ---------------

   Construct an MIIR by retrieving it from an LTPDA repository.

   'Hostname' - the repository hostname. Only those objects which
                are MIIRs are returned.
                [default: 'localhost'];

                Additional parameters:

                'Database'   - The database name [default: 'ltpda']
                'ID'         - A vector of object IDs. [default: []]


 From Standard Type
 ------------------

   Construct an MIIR of a standard type.

   'type'    - one of the types: 'highpass', 'lowpass',
               'bandpass', 'bandreject'            [default: 'lowpass']

                You can also specify optional parameters:
                   'gain'   - the gain of the filter [default: 1]
                   'fc'     - the roll-off frequency    [default: 0.1 Hz]
                   'fs'     - the sampling frequency to design for [default: 1 Hz]
                   'order'  - the filter order [default: 1]
                   'ripple' - pass/stop-band ripple for bandpass
                              and bandreject filters [default: 0.5]


 From Pzmodel
 ------------

   Construct an MIIR from a pzmodel.

   'pzmodel'    - a pzmodel object to construct the filter from [default: empty pzmodel]


 From Plist
 ----------

   'Plist'    - construct from a plist. The value passed should be a plist
                object.
                [default: empty plist]



 EXAMPLE 1:   Create an order 1 highpass filter with high frequency gain 2.
              Filter is designed for 10 Hz sampled data and has a cut-off
              frequency of 0.2 Hz.

              >> pl = plist('type', 'highpass', ...
                            'order', 1,         ...
                            'gain',  2.0,       ...
                            'fs',    10,        ...
                            'fc',    0.2);
              >> f = miir(pl)

 NOTES:
         ** The convention used here for naming the filter coefficients is
            the opposite to MATLAB's convention. The recursion formula
            for this convention is

               b(1)*y(n) = a(1)*x(n) + a(2)*x(n-1) + ... + a(na+1)*x(n-na)
                           - b(2)*y(n-1) - ... - b(nb+1)*y(n-nb)


 VERSION:     $Id: miir.m,v 1.42 2008/03/24 23:51:38 mauro Exp $

 HISTORY:     09-02-2007 M Hewitson
                 Creation
              11-02-2008 M Hueller
                 Help fixed
                 Default parameter list defined

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = miir(miir,'Params')

 The following call returns a string that contains the routine CVS version:

 >> version = miir(miir,'Version')

 The following call returns a string that contains the routine category:

 >> category = miir(miir,'Category')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function f = miir(varargin)
0002 % MIIR IIR filter object class constructor.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: MIIR IIR filter object class constructor.
0007 %              Create a miir object.
0008 %
0009 % CONSTRUCTOR: f = miir()
0010 %                  creates an empty miir object.
0011 %
0012 %              f = miir(fi)
0013 %                  creates a copy of the input miir object, fi.
0014 %
0015 %              f = miir(a,b,fs)
0016 %                  creates a miir object from the coefficient vectors 'a' and 'b' **.
0017 %                  The sample rate for which the filter is designed should
0018 %                  be specified as well.
0019 %
0020 %              f = miir('foo_iir.fil')
0021 %                  create a miir object from a LISO IIR .fil file.
0022 %
0023 %              f = miir('foo_iir.xml')
0024 %                  create a miir object loading the miir object from disk.
0025 %
0026 %              f = miir('foo_iir.mat')
0027 %                  create a miir object loading the miir object from disk
0028 %
0029 %              f = miir(pl)
0030 %                  create a miir object from the description
0031 %                  given in the parameter list.
0032 %
0033 % Parameter sets for plist constructor (in order of priority):
0034 %
0035 % From XML File
0036 % -------------
0037 %
0038 %   Construct an MIIR by loading it from an XML file.
0039 %
0040 %   'filename' - construct an MIIR from a filename.
0041 %                Example: plist('filename', 'm1.xml')
0042 %                [default: empty string]
0043 %
0044 %
0045 % From MAT File
0046 % -------------
0047 %
0048 %   Construct an MIIR by loading it from a MAT file.
0049 %
0050 %   'filename' - construct an MIIR from a filename.
0051 %                Example: plist('filename', 'm1.mat')
0052 %                [default: empty string]
0053 %
0054 %
0055 % From LISO File
0056 % --------------
0057 %
0058 %   Construct an MIIR by loading it from a LISO file.
0059 %
0060 %   'filename' - construct an MIIR from a filename.
0061 %                Example: plist('filename', 'm1.fil')
0062 %                [default: empty string]
0063 %
0064 %
0065 % From Repository
0066 % ---------------
0067 %
0068 %   Construct an MIIR by retrieving it from an LTPDA repository.
0069 %
0070 %   'Hostname' - the repository hostname. Only those objects which
0071 %                are MIIRs are returned.
0072 %                [default: 'localhost'];
0073 %
0074 %                Additional parameters:
0075 %
0076 %                'Database'   - The database name [default: 'ltpda']
0077 %                'ID'         - A vector of object IDs. [default: []]
0078 %
0079 %
0080 % From Standard Type
0081 % ------------------
0082 %
0083 %   Construct an MIIR of a standard type.
0084 %
0085 %   'type'    - one of the types: 'highpass', 'lowpass',
0086 %               'bandpass', 'bandreject'            [default: 'lowpass']
0087 %
0088 %                You can also specify optional parameters:
0089 %                   'gain'   - the gain of the filter [default: 1]
0090 %                   'fc'     - the roll-off frequency    [default: 0.1 Hz]
0091 %                   'fs'     - the sampling frequency to design for [default: 1 Hz]
0092 %                   'order'  - the filter order [default: 1]
0093 %                   'ripple' - pass/stop-band ripple for bandpass
0094 %                              and bandreject filters [default: 0.5]
0095 %
0096 %
0097 % From Pzmodel
0098 % ------------
0099 %
0100 %   Construct an MIIR from a pzmodel.
0101 %
0102 %   'pzmodel'    - a pzmodel object to construct the filter from [default: empty pzmodel]
0103 %
0104 %
0105 % From Plist
0106 % ----------
0107 %
0108 %   'Plist'    - construct from a plist. The value passed should be a plist
0109 %                object.
0110 %                [default: empty plist]
0111 %
0112 %
0113 %
0114 % EXAMPLE 1:   Create an order 1 highpass filter with high frequency gain 2.
0115 %              Filter is designed for 10 Hz sampled data and has a cut-off
0116 %              frequency of 0.2 Hz.
0117 %
0118 %              >> pl = plist('type', 'highpass', ...
0119 %                            'order', 1,         ...
0120 %                            'gain',  2.0,       ...
0121 %                            'fs',    10,        ...
0122 %                            'fc',    0.2);
0123 %              >> f = miir(pl)
0124 %
0125 % NOTES:
0126 %         ** The convention used here for naming the filter coefficients is
0127 %            the opposite to MATLAB's convention. The recursion formula
0128 %            for this convention is
0129 %
0130 %               b(1)*y(n) = a(1)*x(n) + a(2)*x(n-1) + ... + a(na+1)*x(n-na)
0131 %                           - b(2)*y(n-1) - ... - b(nb+1)*y(n-nb)
0132 %
0133 %
0134 % VERSION:     $Id: miir.m,v 1.42 2008/03/24 23:51:38 mauro Exp $
0135 %
0136 % HISTORY:     09-02-2007 M Hewitson
0137 %                 Creation
0138 %              11-02-2008 M Hueller
0139 %                 Help fixed
0140 %                 Default parameter list defined
0141 %
0142 % The following call returns a parameter list object that contains the
0143 % default parameter values:
0144 %
0145 % >> pl = miir(miir,'Params')
0146 %
0147 % The following call returns a string that contains the routine CVS version:
0148 %
0149 % >> version = miir(miir,'Version')
0150 %
0151 % The following call returns a string that contains the routine category:
0152 %
0153 % >> category = miir(miir,'Category')
0154 %
0155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0156 
0157 ALGONAME = mfilename;
0158 VERSION  = '$Id: miir.m,v 1.42 2008/03/24 23:51:38 mauro Exp $';
0159 CATEGORY = 'Constructor';
0160 
0161 %% Check if this is a special call:
0162 % default parameter list, cvs-version, category
0163 if (nargin == 2 || nargin == 3) && isa(varargin{1}, 'miir') && ischar(varargin{2})
0164   if strcmpi(varargin{2}, 'Params')
0165     if nargin == 2
0166       f = getDefaultPlist();
0167     else
0168       f = getDefaultPlist(varargin{3});
0169     end
0170     return
0171   elseif strcmpi(varargin{2}, 'Version')
0172     f = VERSION;
0173     return
0174   elseif strcmpi(varargin{2}, 'Category')
0175     f = CATEGORY;
0176     return
0177   end
0178 end
0179 
0180 %% process input arguments
0181 args = [];
0182 k = 0;
0183 pls = [];
0184 for j=1:nargin
0185   if ~isempty(varargin{j})
0186     k = k + 1;
0187     if isa(varargin{j}, 'plist')
0188       pls = [pls varargin{j}];
0189     else
0190       args(k).val = varargin{j};
0191       args(k).n   = j;
0192     end
0193   end
0194 end
0195 
0196 %% We could have multiple input plist objects. Combine them here.
0197 if isa(pls, 'plist')
0198   pl = combine(pls);
0199 else
0200   pl = [];
0201 end
0202 
0203 Nargs = length(args);
0204 if ~isempty(pl)
0205   args(Nargs+1).val = pl;
0206   args(Nargs+1).n   = j+1;
0207   Nargs = length(args);
0208 end
0209 
0210 
0211 %% %%%%%%%%%%%%%%%%%%%   Create miir object  %%%%%%%%%%%%%%%%%%%
0212 
0213 switch nargin
0214 
0215   case 0
0216     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0217     %%%                              No Parameters                              %%%
0218     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0219 
0220     %%%%%%%%%%  f = miir()   %%%%%%%%%%
0221     % create empty miir object
0222 
0223     f = init(VERSION);
0224 
0225   case 1
0226     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0227     %%%                              One Parameter                              %%%
0228     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0229 
0230     if ischar(varargin{1})
0231       %%%%%%%%%%   f = miir('foo.xml')   %%%%%%%%%%
0232       %%%%%%%%%%   f = miir('foo.mat')   %%%%%%%%%%
0233       %%%%%%%%%%   f = miir('foo.fil')   %%%%%%%%%%
0234       % from filename: XML, MAT, LISO
0235 
0236       filename = varargin{1};
0237       [path, name, ext, vers] = fileparts(filename);
0238       switch ext
0239         case '.mat'
0240           f = load(filename);
0241           f = f.a;
0242         case '.xml'
0243           root_node = xmlread(filename);
0244           f = ltpda_xmlread(root_node, 'miir');
0245         case '.fil'          
0246           filt       = filload(filename);
0247           f = init(VERSION);
0248           f.name     = filt.name;
0249           f.fs       = filt.fs;
0250           f.ntaps    = filt.ntaps;
0251           f.a        = filt.a;
0252           f.b        = filt.b;
0253           f.gain     = filt.gain;
0254           f.histin   = filt.histin;
0255           f.histout  = filt.histout;
0256           f.infile   = filename;
0257         case '.filt'
0258           error('### .filt files are no longer supported.');
0259         otherwise
0260           error('### Unknown file type.');
0261       end
0262 
0263     elseif isa(varargin{1}, 'miir')
0264       %%%%%%%%%%  f = miir(miir)   %%%%%%%%%%
0265       % copy existing miir
0266       f = varargin{1};
0267       f.version = VERSION;
0268 
0269     elseif isstruct(varargin{1})
0270       %%%%%%%%%%  f = miir(struct)   %%%%%%%%%%
0271       % struct
0272       f = init(VERSION);
0273 
0274       fields = fieldnames(varargin{1});
0275       for ii = 1:length(fields)
0276         field = fields{ii};
0277 
0278         if strcmp(field, 'plist')
0279           %%% plist -> plist-object
0280           if isstruct(varargin{1}.(field))
0281             f.(field) = plist(varargin{1}.(field));
0282           else
0283             f.(field) = varargin{1}.(field);
0284           end
0285         elseif strcmp(field, 'created')
0286           %%% created -> time-object
0287           created = varargin{1}.created;
0288           if isstruct(created)
0289             created = time(created);
0290           end
0291           f.created     = created;
0292         else
0293           %%% All other
0294           try
0295             f.(field) = varargin{1}.(field);
0296           catch
0297             error('### The field ''%s'' in the struct is not a miir property.', field)
0298           end
0299         end
0300       end
0301 
0302     elseif isa(varargin{1}, 'plist')
0303       %%%%%%%%%%  f = miir(plist)   %%%%%%%%%%
0304       % Parameter list
0305 
0306       pl   = varargin{1};
0307 
0308       filename = find(pl, 'filename');
0309       hostname = find(pl, 'hostname');
0310       type = find(pl, 'type');
0311       pzm  = find(pl, 'pzmodel');
0312       ipl = find(pl, 'plist');
0313 
0314       % Selection of construction method
0315       if ~isempty(filename)
0316 
0317         %-----------------------------------------------------
0318         %--- Construct from file
0319         %-----------------------------------------------------
0320         
0321         [path, name, ext, vers] = fileparts(filename);
0322         switch ext
0323           case '.mat'
0324             % Do a filename constructor
0325             f = load(filename);
0326             f = f.a;
0327             f.plist = pl;
0328           case '.xml'
0329             % Do a filename constructor
0330             root_node = xmlread(filename);
0331             f = ltpda_xmlread(root_node, 'miir');
0332             f.plist = pl;
0333           case '.fil'
0334             % Do a filename constructor
0335             filt       = filload(filename);
0336             f = init(VERSION);
0337             f.name     = filt.name;
0338             f.fs       = filt.fs;
0339             f.ntaps    = filt.ntaps;
0340             f.a        = filt.a;
0341             f.b        = filt.b;
0342             f.gain     = filt.gain;
0343             f.histin   = filt.histin;
0344             f.histout  = filt.histout;
0345             f.infile   = filename;
0346             f.plist = pl;
0347           otherwise
0348             error('### Unknown file type.');
0349         end
0350 
0351       elseif ~isempty(hostname)
0352 
0353         %-----------------------------------------------------
0354         %--- Construct from repository
0355         %-----------------------------------------------------
0356         
0357         % do hostname constructor
0358         f = miirFromRepository(pl, VERSION, ALGONAME);
0359         f.plist = remove(pl, 'conn');
0360 
0361       elseif ~isempty(type)
0362 
0363         %-----------------------------------------------------
0364         %--- Construct from standard type
0365         %-----------------------------------------------------
0366         
0367         % Construct from standard type
0368         f = miirFromStandardType(type, pl, VERSION, ALGONAME);        
0369         
0370       elseif ~isempty(pzm)
0371 
0372         %-----------------------------------------------------
0373         %--- Construct from pzmodel
0374         %-----------------------------------------------------
0375 
0376         f = miirFromPzmodel(pzm, pl, VERSION, ALGONAME);
0377         
0378       elseif ~isempty(ipl)
0379 
0380         %-----------------------------------------------------
0381         %--- Construct from plist
0382         %-----------------------------------------------------
0383 
0384         % if the plist is empty, we return an empty MIIR
0385         if nparams(ipl) == 0
0386           f = init(VERSION);
0387         else
0388           % do plist constructor
0389           f = miir(ipl);
0390         end
0391 
0392       else
0393         %-----------------------------------------------------
0394         %--- ERROR
0395         %-----------------------------------------------------
0396 
0397         %% is the plist is empty then return an empty MIIR
0398         if nparams(pl) == 0
0399           f = init(VERSION);
0400         else
0401           error('### Unknown MIIR constructor method.');
0402         end
0403       end
0404 
0405     else
0406       error('### Unknown MIIR constructor method.');
0407     end
0408 
0409 
0410   case 2
0411     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0412     %%%                              Two Parameter                              %%%
0413     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0414 
0415     %%%%%%%%%%  f = miir(database, IDs)   %%%%%%%%%%
0416     % From DATABASE
0417     if isa(varargin{1}, 'database')
0418       f = retrieve(varargin{1}, varargin{2:end});
0419 
0420     else
0421       %%%%%%%%%%  f = miir(pzmodel, plist)   %%%%%%%%%%
0422       % pzmodel followed by plist
0423       pzm = varargin{1};
0424 
0425       if isa(varargin{2}, 'plist')
0426         pl = combine(varargin{2}, getDefaultPlist('From Pzmodel'));
0427       else
0428         pl = getDefaultPlist('From Pzmodel');
0429       end
0430 
0431       f = miirFromPzmodel(pzm, pl, ALGONAME, VERSION);
0432     end
0433 
0434 
0435   case 3
0436     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0437     %%%                              Three Parameter                            %%%
0438     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0439 
0440     %%%%%%%%%%  f = miir(a, b, fs)   %%%%%%%%%%
0441 
0442     % 3 numeric inputs for a and b coefficients and fs
0443     a  = varargin{1};
0444     b  = varargin{2};
0445     fs = varargin{3};
0446 
0447     if ~isnumeric(a) || ~isnumeric(b) || ~isnumeric(fs)
0448       error('### unknown constructor type for miir.');
0449     end
0450 
0451     % Checking the coefficients are listed in rows
0452     if size(a,1)~=1
0453       a = a';
0454     end
0455     if size(b,1)~=1
0456       b = b';
0457     end
0458 
0459     f         = init(VERSION);
0460     f.name    = 'AB';
0461     f.fs      = fs;
0462     f.ntaps   = length(a);
0463     f.a       = a;
0464     f.b       = b;
0465     f.gain    = 1;
0466     f.histin  = zeros(1,f.ntaps-1);       % initialise input history
0467     f.histout = zeros(1,f.ntaps-1);       % initialise output history
0468 
0469   otherwise
0470     error('### incorrect input arguments for miir constructor.');
0471 end
0472 
0473 end % function f = miir(varargin)
0474 
0475 
0476 %% Helper functions
0477 
0478 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0479 %
0480 % FUNCTION:    miirFromRepository
0481 %
0482 % DESCRIPTION: Construct an miir from a repository
0483 %
0484 % CALL:        f = miirFromRepository(pli, version, algoname)
0485 %
0486 % PARAMETER:   pli:      Parameter list object
0487 %              version:  cvs version string
0488 %              algoname: The m-file name (use the mfilename command)
0489 %
0490 % HISTORY:     22-03-2008 M Hewitson
0491 %              Creation
0492 %
0493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0494 function fs = miirFromRepository(pli, version, algoname)
0495 
0496 % Add default values
0497 pl = combine(pli, getDefaultPlist('From Repository'));
0498 
0499 % Get parameters
0500 conn = find(pl, 'conn');
0501 hostname = find(pl, 'hostname');
0502 database = find(pl, 'database');
0503 ids      = find(pl, 'id');
0504 
0505 % do we have a connection?
0506 closeConn = 0;
0507 if isempty(conn)
0508   closeConn = 1;
0509   % Connect to repository
0510   conn = mysql_connect(hostname, database);
0511 end
0512 if ~isa(conn, 'database')
0513   error('### connection failed.');
0514 end
0515 % Get each ID
0516 Nids = length(ids);
0517 fs  = [];
0518 for kk=1:Nids
0519 
0520   %---- This id
0521   id = ids(kk);
0522   disp(sprintf('  - retrieving ID %d', id));
0523 
0524   %---- check ID object type
0525   tt = mysql_getObjType(conn, id);
0526   %---- If this is an miir
0527   if strcmp(tt, mfilename)
0528     %---- call database constructor
0529     a = ltpda_obj_retrieve(conn, id);
0530     %---- Add history
0531     %---- Add to output array
0532     fs = [fs a];
0533   else
0534     warning('    !skipping ID %d, type %s', id, tt);
0535   end
0536 
0537 end
0538 
0539 % close connection
0540 if closeConn
0541   close(conn);
0542 end
0543 
0544 end % function f = miirFromRepository(pli, version, algoname)
0545 
0546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0547 %
0548 % FUNCTION:    miirFromStandardType
0549 %
0550 % DESCRIPTION: Construct an miir from a standard types
0551 %
0552 % CALL:        f = miirFromRepository(type, pli, version, algoname)
0553 %
0554 % PARAMETER:   type:     String with filter type description
0555 %              pli:       Parameter list object
0556 %              version:  cvs version string
0557 %              algoname: The m-file name (use the mfilename command)
0558 %
0559 % HISTORY:     22-03-2008 M Hueller
0560 %              Creation
0561 %
0562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0563 function f = miirFromStandardType(type, pli, version, algoname)
0564 
0565 % Add default values
0566 pl = combine(pli, getDefaultPlist('From Standard Type'));
0567 
0568 f = init(version);
0569 
0570 % check and fill parameter list
0571 plo = parseFilterParams(pl);
0572 switch type
0573   case 'lowpass'
0574     f = mklowpass(f, plo);
0575   case 'highpass'
0576     f = mkhighpass(f, plo);
0577   case 'bandpass'
0578     f = mkbandpass(f, plo);
0579   case 'bandreject'
0580     f = mkbandreject(f, plo);
0581   otherwise
0582     error('### unknown standard filter type in miir constructor.');
0583 end
0584 f.infile  = '';
0585 f.plist = pli;
0586 
0587 end % function f = miirFromStandardType(type, pli, version, algoname)
0588 
0589 
0590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0591 %
0592 % FUNCTION:    miirFromPzmodel
0593 %
0594 % DESCRIPTION: Construct an miir from a pzmodel
0595 %
0596 % CALL:        f = miirFromPzmodel(pzm, pli, version, algoname)
0597 %
0598 % PARAMETER:   pzm:      Pzmodel object
0599 %              pli:      Parameter list object
0600 %              version:  cvs version string
0601 %              algoname: The m-file name (use the mfilename command)
0602 %
0603 % HISTORY:     22-03-2008 M Hueller
0604 %              Creation
0605 %
0606 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0607 function f = miirFromPzmodel(pzm, pli, version, algoname)
0608 
0609 % Add default values
0610 pl = combine(pli, getDefaultPlist('From Pzmodel'));
0611 
0612 fs = find(pl, 'fs');
0613 if isempty(fs)
0614   % get max freq in pzmodel
0615   fs = 8*getupperFreq(pzm);
0616   warning([sprintf('!!! no sample rate specified. Designing for fs=%2.2f Hz.', fs)...
0617     sprintf('\nThe filter will be redesigned later when used.')]);
0618 end
0619 % make MIIR filter
0620 f = tomiir(pzm, fs);
0621 f.name = pzm.name;
0622 f.plist = pli;
0623         
0624 end % function f = miirFromPzmodel(pzm, pli, version, algoname)
0625 
0626 
0627 %%%%%%%%%%%%%%%%%%%%%%%%   define miir properties   %%%%%%%%%%%%%%%%%%%%%%%%%
0628 
0629 function f = init(version)
0630 f.name    = 'None';
0631 f.fs      = 0;
0632 f.ntaps   = 0;
0633 f.a       = [];
0634 f.b       = [];
0635 f.gain    = 0;
0636 f.histin  = [];
0637 f.histout = [];
0638 f.infile  = '';
0639 f.plist   = plist();
0640 f.created = time;
0641 f.version = version;
0642 f = class(f, 'miir');
0643 end % function f = init(version)
0644 
0645 
0646 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0647 %
0648 % FUNCTION:    getDefaultPlist
0649 %
0650 % DESCRIPTION: Default Parameter Lists
0651 %
0652 % CALL:        out = getDefaultPlist(set-string)
0653 %
0654 % PARAMETER:   set-string: A string which defines the default parameter list.
0655 %
0656 % HISTORY:     07-05-2007 Hewitson
0657 %              Creation
0658 %
0659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0660 function out = getDefaultPlist(varargin)
0661 
0662 
0663 % list of available parameter sets
0664 sets = {'From XML File', 'From MAT File','From LISO File', ...
0665   'From Repository', ...
0666   'From Standard Type', 'From Pzmodel', ...
0667   'From Plist'};
0668 
0669 if nargin == 0
0670   out = sets;
0671   return
0672 end
0673 
0674 set = varargin{1};
0675 
0676 switch set
0677 
0678   %------------------------------------------
0679   %--- Repository constructor
0680   %------------------------------------------
0681   case 'From Repository'
0682     out = plist('hostname', 'localhost', 'database', 'ltpda', 'ID', []);
0683 
0684     %------------------------------------------
0685     %--- Create from description
0686     %------------------------------------------
0687   case 'From Standard Type'
0688     out = plist('type','lowpass',...
0689       'fc', 0.1, ...
0690       'gain',  1.0, ...
0691       'fs', 1.0, ...
0692       'order', 1, ...
0693       'ripple', 0.5);
0694 
0695     %------------------------------------------
0696     %--- Create from a pzmodel
0697     %------------------------------------------
0698   case 'From Pzmodel'
0699     out = plist('pzmodel', pzmodel());
0700 
0701     %------------------------------------------
0702     %--- Read from XML file
0703     %------------------------------------------
0704   case 'From XML File'
0705     out = plist('filename', '');
0706 
0707     %------------------------------------------
0708     %--- Read from MAT file
0709     %------------------------------------------
0710   case 'From MAT File'
0711     out = plist('filename', '');
0712 
0713     %------------------------------------------
0714     %--- Create from LISO file
0715     %------------------------------------------
0716   case 'From LISO File'
0717     out = plist('filename', '');
0718 
0719     %------------------------------------------
0720     %--- Create from a plist
0721     %------------------------------------------
0722   case 'From Plist'
0723     out = plist('Plist', []);
0724 
0725   otherwise
0726     out = plist();
0727 end
0728 
0729 
0730 end % function out = getDefaultPlist(varargin)
0731

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003