Home > classes > @specwin > specwin.m

specwin

PURPOSE ^

SPECWIN spectral window object class constructor.

SYNOPSIS ^

function w = specwin(varargin)

DESCRIPTION ^

 SPECWIN spectral window object class constructor.

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

 DESCRIPTION: SPECWIN spectral window object class constructor.
              Create a spectral window from libSpecWin.

  PROPERTIES:
       name     - name of window object
       alpha    - alpha parameter for various window functions
       psll     - peak sidelobe level
       rov      - recommended overlap
       nenbw    - normalised equivalent noise bandwidth
       w3db     - 3 dB bandwidth in bins
       flatness - window flatness
       ws       - sum of window values
       ws2      - sum of squares of window values
       nfft     - window length
       win      - window samples (column vector)

  CONSTRUCTORS:

       w = specwin()                  - creates an empty object
       w = specwin(w)                 - copies a specwin object
       w = specwin('name', N)         - creates a specwin object of a
                                        particular type and length.
                                        (see below for supported types.)
       w = specwin('Kaiser', N, psll) - create a specwin Kaiser window
                                        with the prescribed psll.
       w = specwin('Types')           - return a list of all possible
                                        standard windows

 'name' should be one of the following standard windows:

    Rectangular, Welch, Bartlett, Hanning, Hamming,
    Nuttall3, Nuttall4, Nuttall3a, Nuttall3b, Nuttall4a
    Nuttall4b, Nuttall4c, BH92, SFT3F, SFT3M, FTNI, SFT4F, SFT5F
    SFT4M, FTHP, HFT70, FTSRS, SFT5M, HFT90D, HFT95, HFT116D
    HFT144D, HFT169D, HFT196D, HFT223D, HFT248D

 VERSION:     $Id: specwin.m,v 1.26 2008/02/24 10:15:55 hewitson Exp $

 HISTORY:     30-01-07 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function w = specwin(varargin)
0002 % SPECWIN spectral window object class constructor.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SPECWIN spectral window object class constructor.
0007 %              Create a spectral window from libSpecWin.
0008 %
0009 %  PROPERTIES:
0010 %       name     - name of window object
0011 %       alpha    - alpha parameter for various window functions
0012 %       psll     - peak sidelobe level
0013 %       rov      - recommended overlap
0014 %       nenbw    - normalised equivalent noise bandwidth
0015 %       w3db     - 3 dB bandwidth in bins
0016 %       flatness - window flatness
0017 %       ws       - sum of window values
0018 %       ws2      - sum of squares of window values
0019 %       nfft     - window length
0020 %       win      - window samples (column vector)
0021 %
0022 %  CONSTRUCTORS:
0023 %
0024 %       w = specwin()                  - creates an empty object
0025 %       w = specwin(w)                 - copies a specwin object
0026 %       w = specwin('name', N)         - creates a specwin object of a
0027 %                                        particular type and length.
0028 %                                        (see below for supported types.)
0029 %       w = specwin('Kaiser', N, psll) - create a specwin Kaiser window
0030 %                                        with the prescribed psll.
0031 %       w = specwin('Types')           - return a list of all possible
0032 %                                        standard windows
0033 %
0034 % 'name' should be one of the following standard windows:
0035 %
0036 %    Rectangular, Welch, Bartlett, Hanning, Hamming,
0037 %    Nuttall3, Nuttall4, Nuttall3a, Nuttall3b, Nuttall4a
0038 %    Nuttall4b, Nuttall4c, BH92, SFT3F, SFT3M, FTNI, SFT4F, SFT5F
0039 %    SFT4M, FTHP, HFT70, FTSRS, SFT5M, HFT90D, HFT95, HFT116D
0040 %    HFT144D, HFT169D, HFT196D, HFT223D, HFT248D
0041 %
0042 % VERSION:     $Id: specwin.m,v 1.26 2008/02/24 10:15:55 hewitson Exp $
0043 %
0044 % HISTORY:     30-01-07 M Hewitson
0045 %                 Creation
0046 %
0047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0048 
0049 %       w = specwin('Flattop', N, psll) - create a specwin Flattop window
0050 %                                         with the prescribed psll.
0051 
0052 ALGONAME = mfilename;
0053 VERSION  = '$Id: specwin.m,v 1.26 2008/02/24 10:15:55 hewitson Exp $';
0054 CATEGORY = 'Constructor';
0055 
0056 % Check if this is a call for parameters
0057 if (nargin == 2 || nargin == 3)
0058   if isa(varargin{1}, 'specwin') && ischar(varargin{2})
0059     in = char(varargin{2});
0060     if strcmp(in, 'Params')
0061       if nargin == 2
0062         w = getDefaultPlist();
0063       else
0064         w = getDefaultPlist(varargin{3});
0065       end
0066       return
0067     elseif strcmp(in, 'Version')
0068       w = VERSION;
0069       return
0070     elseif strcmp(in, 'Category')
0071       w = CATEGORY;
0072       return
0073     end
0074   end
0075 end
0076 
0077 %%%%%%%%%%%%%%%%%%%%   define parameter properties list   %%%%%%%%%%%%%%%%%%%%%
0078 
0079   function w = init()
0080     w.name     = 'no window';
0081     w.alpha    = -1;
0082     w.psll     = -1;
0083     w.rov      = -1;
0084     w.nenbw    = -1;
0085     w.w3db     = -1;
0086     w.flatness = -1;
0087     w.ws       = -1;
0088     w.ws2      = -1;
0089     w.win      = -1;
0090     w.plist    = '';
0091     w.created  = '1970-01-01 00:00:00';
0092     w.version  = VERSION;
0093     w = class(w, 'specwin');
0094   end
0095 
0096 %%%%%%%%%%   spw = specwin()   %%%%%%%%%%
0097 if nargin == 0
0098 
0099   w = init();
0100 
0101 elseif nargin == 1
0102   %%%%%%%%%%   spw = specwin(specwin)   %%%%%%%%%%
0103   if isa(varargin{1}, 'specwin')
0104     w = varargin{1};
0105 
0106   %%%%%%%%%%   spw = specwin(struct)   %%%%%%%%%%
0107   elseif isstruct(varargin{1})
0108 
0109     w = class(varargin{1}, 'specwin');
0110     return
0111 
0112   %%%%%%%%%%   spw = specwin(plist)   %%%%%%%%%%
0113   elseif isa(varargin{1}, 'plist')
0114 
0115     pl    = varargin{1};
0116     wname = find(pl, 'Name');
0117     N     = find(pl, 'N');
0118     psll  = find(pl, 'PSLL');
0119     hostname = find(pl, 'hostname');
0120     
0121     if ~isempty(hostname)
0122       w = specwinFromRepository(pl, VERSION, ALGONAME);      
0123     else
0124       switch wname
0125         case 'Kaiser'
0126           w = specwin(wname, N, psll);
0127         otherwise
0128           w = specwin(wname, N);
0129       end
0130     end
0131     
0132     w.plist = remove(varargin{1}, 'conn');
0133 
0134   elseif ischar(varargin{1})
0135 
0136     %%%%%%%%%%   spw = specwin('Types')   %%%%%%%%%%
0137     if strcmp(varargin{1}, 'Types')
0138 
0139       % return list of windows
0140       w = {...
0141         'Rectangular', 'Welch', 'Bartlett', 'Hanning', 'Hamming',...
0142         'Nuttall3', 'Nuttall4', 'Nuttall3a', 'Nuttall3b', 'Nuttall4a',...
0143         'Nuttall4b', 'Nuttall4c', 'BH92', 'SFT3F', 'SFT3M', 'FTNI', 'SFT4F', 'SFT5F',...
0144         'SFT4M', 'FTHP', 'HFT70', 'FTSRS', 'SFT5M', 'HFT90D', 'HFT95', 'HFT116D',...
0145         'HFT144D', 'HFT169D', 'HFT196D', 'HFT223D', 'HFT248D'...
0146         };
0147 
0148     %%%%%%%%%%   spw = specwin('foo.xml')   %%%%%%%%%%
0149     else
0150 
0151       filename = varargin{1};
0152       [path, name, ext, vers] = fileparts(filename);
0153       switch ext
0154         case '.mat'
0155           w = load(filename);
0156           w = w.a;
0157         case '.xml'
0158           root_node = xmlread(filename);
0159           w = ltpda_xmlread(root_node, 'specwin');
0160         otherwise
0161           error('### Unknown file type.');
0162       end
0163     end
0164 
0165   else
0166     error('### unknown constructor type for specwin object.');
0167   end
0168 
0169 elseif nargin == 2
0170 
0171   %%%%%%%%%%   copy specwin   %%%%%%%%%%
0172   %%%%%%%%%%   spw = specwin(specwin, ...)   %%%%%%%%%%
0173   if isa(varargin{1}, 'specwin')
0174     w = varargin{1};
0175 
0176   %%%%%%%%%%   spw = specwin(database, ...)   %%%%%%%%%%
0177   elseif isa(varargin{1}, 'database')
0178 
0179     w = retrieve(varargin{1}, varargin{2:end});
0180 
0181   %%%%%%%%%%   create a particular type   %%%%%%%%%%
0182   %%%%%%%%%%   spw = specwin('Win_type', N)   %%%%%%%%%%
0183   elseif ischar(varargin{1})
0184 
0185     w = init();
0186     w = get_window(w, varargin{1}, varargin{2});
0187 
0188   else
0189     error('### unknown constructor for specwin object.')
0190   end
0191 
0192 %%%%%%%%%%   create a Kaiser window   %%%%%%%%%%
0193 %%%%%%%%%%   spw = specwin('Kaiser', N, psll)   %%%%%%%%%%
0194 elseif nargin == 3
0195 
0196   w = init();
0197   w = get_window(w, varargin{1}, varargin{2}, varargin{3});
0198 
0199 else
0200   error('### Unknown number of constructor arguments.');
0201 end
0202 
0203 
0204 
0205 %--------------------------------------------------------------------------
0206 % construct an ao from a repository
0207 %
0208   function fs = specwinFromRepository(pl, VERSION, ALGONAME)
0209 
0210     dpl = getDefaultPlist('From Repository');
0211     pl  = combine(pl, dpl);
0212 
0213     % Get parameters
0214     conn = find(pl, 'conn');
0215     hostname = find(pl, 'hostname');
0216     database = find(pl, 'database');
0217     ids      = find(pl, 'id');
0218 
0219     % do we have a connection?
0220     closeConn = 0;
0221     if isempty(conn)
0222       closeConn = 1;
0223       % Connect to repository
0224       conn = mysql_connect(hostname, database);
0225     end
0226     if ~isa(conn, 'database')
0227       error('### connection failed.');
0228     end
0229     % Get each ID
0230     Nids = length(ids);
0231     fs  = [];
0232     for kk=1:Nids
0233 
0234       %---- This id
0235       id = ids(kk);
0236       disp(sprintf('  - retrieving ID %d', id));
0237 
0238       %---- check ID object type
0239       tt = mysql_getObjType(conn, id);
0240       %---- If this is a specwin
0241       if strcmp(tt, mfilename)
0242         %---- call database constructor
0243         a = ltpda_obj_retrieve(conn, id);
0244         %---- Add history
0245         %---- Add to output array
0246         fs = [fs a];
0247       else
0248         warning('    !skipping ID %d, type %s', id, tt);
0249       end
0250 
0251     end
0252 
0253     % close connection
0254     if closeConn
0255       close(conn);
0256     end
0257 
0258   end
0259 
0260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0261 %
0262 % FUNCTION:    getDefaultPL
0263 %
0264 % DESCRIPTION: Get default params
0265 %
0266 % HISTORY:     11-02-2008 M Hueller
0267 %                 Creation
0268 %
0269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0270   function out = getDefaultPlist(varargin)
0271 
0272     % list of available parameter sets
0273     sets = {'From Window Definition', 'From Repository'};
0274 
0275     if nargin == 0
0276       out = sets;
0277       return
0278     end
0279 
0280     set = varargin{1};
0281     switch set
0282       case 'From Repository'
0283         out = plist('hostname', 'localhost', 'database', 'ltpda', 'ID', []);
0284       case 'From Window Definition'
0285         out = plist('Name', 'Kaiser', 'N', 10, 'PSLL', 150);
0286       otherwise
0287         out = plist();
0288     end
0289 
0290   end
0291 
0292 end
0293

Generated on Fri 07-Mar-2008 15:46:43 by m2html © 2003