Home > classes > @mfir > parseFilterParams.m

parseFilterParams

PURPOSE ^

PARSEFILTERPARAMS parses the input plist and returns a full plist for designing a standard FIR filter.

SYNOPSIS ^

function plo = parseFilterParams(pl)

DESCRIPTION ^

 PARSEFILTERPARAMS parses the input plist and returns a full plist for designing a standard FIR filter.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: PARSEFILTERPARAMS parses the input plist and returns a full
              plist for designing a standard FIR filter. Defaults are used
              for those parameters missing from the input plist.

 CALL:        plo = parseFilterParams(pl)

 INPUT:       'type'  - one of 'highpass', 'lowpass', 'bandpass', 'bandreject'.
               [default: 'lowpass']
              'gain'  - gain of filter [default: 1.0]
              'fs'    - sample frequency to design for [default: 1 Hz]
              'order' - order of filter [default: 64]
              'fc'    - corner frequencies. This is a two element vector for
                        bandpass and bandreject filters. [default: 0.1 or [0.1 0.25] Hz]
              'Win'   - a window object to use in the design. [default: Hamming]

 VERSION:     $Id: parseFilterParams.m,v 1.4 2008/08/08 14:52:24 hewitson Exp $

 HISTORY:     11-02-2008 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % PARSEFILTERPARAMS parses the input plist and returns a full plist for designing a standard FIR filter.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: PARSEFILTERPARAMS parses the input plist and returns a full
0005 %              plist for designing a standard FIR filter. Defaults are used
0006 %              for those parameters missing from the input plist.
0007 %
0008 % CALL:        plo = parseFilterParams(pl)
0009 %
0010 % INPUT:       'type'  - one of 'highpass', 'lowpass', 'bandpass', 'bandreject'.
0011 %               [default: 'lowpass']
0012 %              'gain'  - gain of filter [default: 1.0]
0013 %              'fs'    - sample frequency to design for [default: 1 Hz]
0014 %              'order' - order of filter [default: 64]
0015 %              'fc'    - corner frequencies. This is a two element vector for
0016 %                        bandpass and bandreject filters. [default: 0.1 or [0.1 0.25] Hz]
0017 %              'Win'   - a window object to use in the design. [default: Hamming]
0018 %
0019 % VERSION:     $Id: parseFilterParams.m,v 1.4 2008/08/08 14:52:24 hewitson Exp $
0020 %
0021 % HISTORY:     11-02-2008 M Hewitson
0022 %                 Creation
0023 %
0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 
0026 function plo = parseFilterParams(pl)
0027 
0028   plo = plist();
0029 
0030   % type
0031   type = find(pl, 'type');
0032   if isempty(type)
0033     type = 'lowpass';
0034     utils.helper.msg(msg.OPROC2, 'using default type ''lowpass''');
0035   end
0036   plo = append(plo, 'type', type);
0037 
0038   % gain
0039   gain = find(pl, 'gain');
0040   if isempty(gain)
0041     gain = 1.0;
0042     utils.helper.msg(msg.OPROC2, ['using default gain ' num2str(gain)]);
0043   end
0044   plo = append(plo, 'gain', gain);
0045 
0046   % order
0047   order = find(pl, 'order');
0048   if isempty(order)
0049     order = 64;
0050     utils.helper.msg(msg.OPROC2, ['- using default order ' num2str(order)]);
0051   end
0052   if mod(order,2) == 1
0053     warning('!!! reseting filter order to even number (+1)')
0054     order = order + 1;
0055   end
0056   plo = append(plo, 'order', order);
0057 
0058   % fc
0059   fc = find(pl, 'fc');
0060   if isempty(fc)
0061     if strcmp(type, 'bandreject') || strcmp(type, 'bandpass')
0062       fc = [0.1 0.25];
0063     else
0064       fc = 0.1;
0065     end
0066     utils.helper.msg(msg.OPROC2, ['- using default fc ' num2str(fc)]);
0067   end
0068   plo = append(plo, 'fc', fc);
0069 
0070   % fs
0071   fs = find(pl, 'fs');
0072   if isempty(fs)
0073     fs = 10*max(fc);
0074     warning([sprintf('!!! no sample rate specified. Designing for fs=%2.2fHz.', fs)...
0075       sprintf('\nThe filter will be redesigned later when used.')]);
0076   end
0077   plo = append(plo, 'fs', fs);
0078 
0079   % win
0080   win = find(pl, 'Win');
0081   if isempty(win)
0082     % then we use the default window
0083     win = specwin('Hamming', order+1);
0084   end
0085   if length(win.win) ~= order + 1
0086     warning('!!! setting window length to filter order !!!');
0087     switch win.type
0088       case {'Kaiser', 'Flattop'}
0089         win = specwin(win.type, order + 1, win.psll);
0090       otherwise
0091         win = specwin(win.type, order + 1);
0092     end
0093   end
0094   plo = append(plo, 'Win', win);
0095 end
0096 
0097

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003