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) CONSTRUCTOR: 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('foo.xml') create a specwin by loading the specwin object from disk w = specwin('foo.mat'); create a specwin by loading the specwin object from disk 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 w = specwin(pl); create a pzmodel object from the description given in the parameter list. Parameter sets for plist constructor (in order of priority): From XML File ------------- Construct a SPECWIN by loading it from an XML file. 'filename' - construct a SPECWIN from a filename. Example: plist('filename', 'w1.xml') [default: empty string] From MAT File ------------- Construct a SPECWIN by loading it from a MAT file. 'filename' - construct a SPECWIN from a filename. Example: plist('filename', 'w1.mat') [default: empty string] From Repository --------------- Construct a SPECWIN by retrieving it from an LTPDA repository. 'Hostname' - the repository hostname. Only those objects which are SPECWINs are returned. [default: 'localhost']; Additional parameters: 'Database' - The database name [default: 'ltpda'] 'ID' - A vector of object IDs. [default: []] From Window Definition ---------------------- Construct a SPECWIN from its definion. 'Name' - spectral window name [default: 'Kaiser'] 'N' - spectral window length [default: 10] 'PSLLs' - peak sidelobe length (only for Kaiser type) [default: 150] Example: plist('Name', 'Kaiser', 'N', 1000, 'PSLL', 75); From Plist --------------- 'Plist' - construct from a plist. The value passed should be a plist object. [default: empty plist] EXAMPLE 1: Still to be written ... VERSION: $Id: specwin.m,v 1.38 2008/03/30 23:12:10 mauro Exp $ HISTORY: 30-01-07 M Hewitson Creation The following call returns a parameter list object that contains the default parameter values: >> pl = specwin(specwin,'Params') The following call returns a string that contains the routine CVS version: >> version = specwin(specwin,'Version') The following call returns a string that contains the routine category: >> category = specwin(specwin,'Category') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 % CONSTRUCTOR: 0023 % 0024 % w = specwin() 0025 % creates an empty object 0026 % 0027 % w = specwin(w) 0028 % copies a specwin object 0029 % 0030 % w = specwin('name', N) 0031 % creates a specwin object of a particular type and length. 0032 % (see below for supported types.) 0033 % 0034 % w = specwin('Kaiser', N, psll) 0035 % create a specwin Kaiser window with the prescribed psll. 0036 % 0037 % w = specwin('foo.xml') 0038 % create a specwin by loading the specwin object from disk 0039 % 0040 % w = specwin('foo.mat'); 0041 % create a specwin by loading the specwin object from disk 0042 % 0043 % w = specwin('Types') 0044 % return a list of all possible standard windows 0045 % 0046 % 'name' should be one of the following standard windows: 0047 % 0048 % Rectangular, Welch, Bartlett, Hanning, Hamming, 0049 % Nuttall3, Nuttall4, Nuttall3a, Nuttall3b, Nuttall4a 0050 % Nuttall4b, Nuttall4c, BH92, SFT3F, SFT3M, FTNI, SFT4F, SFT5F 0051 % SFT4M, FTHP, HFT70, FTSRS, SFT5M, HFT90D, HFT95, HFT116D 0052 % HFT144D, HFT169D, HFT196D, HFT223D, HFT248D 0053 % 0054 % w = specwin(pl); 0055 % create a pzmodel object from the description given 0056 % in the parameter list. 0057 % 0058 % 0059 % Parameter sets for plist constructor (in order of priority): 0060 % 0061 % From XML File 0062 % ------------- 0063 % 0064 % Construct a SPECWIN by loading it from an XML file. 0065 % 0066 % 'filename' - construct a SPECWIN from a filename. 0067 % Example: plist('filename', 'w1.xml') 0068 % [default: empty string] 0069 % 0070 % 0071 % From MAT File 0072 % ------------- 0073 % 0074 % Construct a SPECWIN by loading it from a MAT file. 0075 % 0076 % 'filename' - construct a SPECWIN from a filename. 0077 % Example: plist('filename', 'w1.mat') 0078 % [default: empty string] 0079 % 0080 % 0081 % From Repository 0082 % --------------- 0083 % 0084 % Construct a SPECWIN by retrieving it from an LTPDA repository. 0085 % 0086 % 'Hostname' - the repository hostname. Only those objects which 0087 % are SPECWINs are returned. 0088 % [default: 'localhost']; 0089 % 0090 % Additional parameters: 0091 % 0092 % 'Database' - The database name [default: 'ltpda'] 0093 % 'ID' - A vector of object IDs. [default: []] 0094 % 0095 % 0096 % From Window Definition 0097 % ---------------------- 0098 % 0099 % Construct a SPECWIN from its definion. 0100 % 0101 % 'Name' - spectral window name [default: 'Kaiser'] 0102 % 'N' - spectral window length [default: 10] 0103 % 'PSLLs' - peak sidelobe length (only for Kaiser type) [default: 150] 0104 % 0105 % Example: plist('Name', 'Kaiser', 'N', 1000, 'PSLL', 75); 0106 % 0107 % 0108 % From Plist 0109 % --------------- 0110 % 0111 % 'Plist' - construct from a plist. The value passed should be a plist 0112 % object. 0113 % [default: empty plist] 0114 % 0115 % 0116 % EXAMPLE 1: Still to be written ... 0117 % 0118 % 0119 % VERSION: $Id: specwin.m,v 1.38 2008/03/30 23:12:10 mauro Exp $ 0120 % 0121 % HISTORY: 30-01-07 M Hewitson 0122 % Creation 0123 % 0124 % The following call returns a parameter list object that contains the 0125 % default parameter values: 0126 % 0127 % >> pl = specwin(specwin,'Params') 0128 % 0129 % The following call returns a string that contains the routine CVS version: 0130 % 0131 % >> version = specwin(specwin,'Version') 0132 % 0133 % The following call returns a string that contains the routine category: 0134 % 0135 % >> category = specwin(specwin,'Category') 0136 % 0137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0138 0139 % w = specwin('Flattop', N, psll) - create a specwin Flattop window 0140 % with the prescribed psll. 0141 0142 ALGONAME = mfilename; 0143 VERSION = '$Id: specwin.m,v 1.38 2008/03/30 23:12:10 mauro Exp $'; 0144 CATEGORY = 'Constructor'; 0145 0146 %% Check if this is a special call: 0147 % default parameter list, cvs-version, category 0148 if (nargin == 2 || nargin == 3) && isa(varargin{1}, 'specwin') && ischar(varargin{2}) 0149 in = char(varargin{2}); 0150 if strcmp(in, 'Params') 0151 if nargin == 2 0152 w = getDefaultPlist(); 0153 else 0154 w = getDefaultPlist(varargin{3}); 0155 end 0156 return 0157 elseif strcmp(in, 'Version') 0158 w = VERSION; 0159 return 0160 elseif strcmp(in, 'Category') 0161 w = CATEGORY; 0162 return 0163 end 0164 end 0165 0166 0167 %% process input arguments 0168 args = []; 0169 k = 0; 0170 pls = []; 0171 for j=1:nargin 0172 if ~isempty(varargin{j}) 0173 k = k + 1; 0174 if isa(varargin{j}, 'plist') 0175 pls = [pls varargin{j}]; 0176 else 0177 args(k).val = varargin{j}; 0178 args(k).n = j; 0179 end 0180 end 0181 end 0182 0183 %% We could have multiple input plist objects. Combine them here. 0184 if isa(pls, 'plist') 0185 pl = combine(pls); 0186 else 0187 pl = []; 0188 end 0189 0190 Nargs = length(args); 0191 if ~isempty(pl) 0192 args(Nargs+1).val = pl; 0193 args(Nargs+1).n = j+1; 0194 Nargs = length(args); 0195 end 0196 0197 0198 %% %%%%%%%%%%%%%%%%%% Create specwin object %%%%%%%%%%%%%%%%%%%%%% 0199 0200 switch nargin 0201 0202 case 0 0203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0204 %%% No Parameters %%% 0205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0206 0207 %%%%%%%%%% spw = specwin() %%%%%%%%%% 0208 % create empty specwin object 0209 0210 w = init(VERSION); 0211 0212 case 1 0213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0214 %%% One Parameter %%% 0215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0216 0217 if isa(varargin{1}, 'specwin') 0218 %%%%%%%%%% spw = specwin(specwin) %%%%%%%%%% 0219 % copy existing specwin 0220 0221 w = varargin{1}; 0222 0223 %%%%%%%%%% spw = specwin(struct) %%%%%%%%%% 0224 elseif isstruct(varargin{1}) 0225 0226 w = class(varargin{1}, 'specwin'); 0227 0228 elseif isa(varargin{1}, 'plist') 0229 %%%%%%%%%% spw = specwin(plist) %%%%%%%%%% 0230 % Parameter list 0231 0232 pl = varargin{1}; 0233 0234 filename = find(pl, 'filename'); 0235 hostname = find(pl, 'hostname'); 0236 wname = find(pl, 'Name'); 0237 ipl = find(pl, 'plist'); 0238 0239 % Selection of construction method 0240 if ~isempty(filename) 0241 0242 %----------------------------------------------------- 0243 %--- Construct from file 0244 %----------------------------------------------------- 0245 [path, name, ext, vers] = fileparts(filename); 0246 switch ext 0247 case '.mat' 0248 % Do a filename constructor 0249 w = load(filename); 0250 w = w.a; 0251 w.plist = pl; 0252 case '.xml' 0253 % Do a filename constructor 0254 root_node = xmlread(filename); 0255 w = ltpda_xmlread(root_node, 'specwin'); 0256 w.plist = pl; 0257 otherwise 0258 error('### Unknown file type.'); 0259 end 0260 0261 elseif ~isempty(hostname) 0262 0263 %----------------------------------------------------- 0264 %--- Construct from repository 0265 %----------------------------------------------------- 0266 0267 % do hostname constructor 0268 w = specwinFromRepository(pl, VERSION, ALGONAME); 0269 w.plist = remove(pl, 'conn'); 0270 0271 elseif ~isempty(wname) 0272 %----------------------------------------------------- 0273 %--- Construct from window descritpion 0274 %----------------------------------------------------- 0275 plw = combine(pl, getDefaultPlist('From Window Definition')); 0276 0277 % do constructor from window name 0278 switch wname 0279 case 'Kaiser' 0280 w = specwin(wname, find(plw, 'N'), find(plw, 'PSLL')); 0281 otherwise 0282 w = specwin(wname, find(plw, 'N')); 0283 end 0284 w.plist = pl; 0285 0286 elseif ~isempty(ipl) 0287 %----------------------------------------------------- 0288 %--- Construct from plist 0289 %----------------------------------------------------- 0290 0291 % if the plist is empty, we return an empty SPECWIN 0292 if nparams(ipl) == 0 0293 w = init(VERSION); 0294 else 0295 % do plist constructor 0296 w = specwin(ipl); 0297 end 0298 0299 else 0300 %----------------------------------------------------- 0301 %--- ERROR 0302 %----------------------------------------------------- 0303 0304 %% is the plist is empty then return an empty SPECWIN 0305 if nparams(pl) == 0 0306 w = init(VERSION); 0307 else 0308 error('### Unknown SPECWIN constructor method.'); 0309 end 0310 end 0311 0312 elseif ischar(varargin{1}) 0313 0314 if strcmp(varargin{1}, 'Types') 0315 %%%%%%%%%% spw = specwin('Types') %%%%%%%%%% 0316 % return list of windows 0317 w = {... 0318 'Rectangular', 'Welch', 'Bartlett', 'Hanning', 'Hamming',... 0319 'Nuttall3', 'Nuttall4', 'Nuttall3a', 'Nuttall3b', 'Nuttall4a',... 0320 'Nuttall4b', 'Nuttall4c', 'BH92', 'SFT3F', 'SFT3M', 'FTNI', 'SFT4F', 'SFT5F',... 0321 'SFT4M', 'FTHP', 'HFT70', 'FTSRS', 'SFT5M', 'HFT90D', 'HFT95', 'HFT116D',... 0322 'HFT144D', 'HFT169D', 'HFT196D', 'HFT223D', 'HFT248D'... 0323 }; 0324 0325 else 0326 %%%%%%%%%% spw = specwin('foo.xml') %%%%%%%%%% 0327 %%%%%%%%%% spw = specwin('foo.mat') %%%%%%%%%% 0328 % from filename: XML, MAT 0329 0330 filename = varargin{1}; 0331 [path, name, ext, vers] = fileparts(filename); 0332 switch ext 0333 case '.mat' 0334 w = load(filename); 0335 w = w.a; 0336 case '.xml' 0337 root_node = xmlread(filename); 0338 w = ltpda_xmlread(root_node, 'specwin'); 0339 otherwise 0340 error('### Unknown file type.'); 0341 end 0342 end 0343 0344 else 0345 error('### unknown constructor type for specwin object.'); 0346 end 0347 0348 case 2 0349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0350 %%% Two Parameter %%% 0351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0352 0353 if isa(varargin{1}, 'specwin') 0354 w = varargin{1}; 0355 %%%%%%%%%% spw = specwin(specwin, ...) %%%%%%%%%% 0356 %%%%%%%%%% copy specwin %%%%%%%%%% 0357 0358 elseif isa(varargin{1}, 'database') 0359 %%%%%%%%%% spw = specwin(database, IDs) %%%%%%%%%% 0360 % From DATABASE 0361 0362 w = retrieve(varargin{1}, varargin{2:end}); 0363 0364 elseif ischar(varargin{1}) 0365 %%%%%%%%%% spw = specwin('Win_type', N) %%%%%%%%%% 0366 %%%%%%%%%% create a particular type %%%%%%%%%% 0367 0368 w = init(VERSION); 0369 w = get_window(w, varargin{1}, varargin{2}); 0370 0371 else 0372 error('### unknown constructor for specwin object.') 0373 end 0374 0375 case 3 0376 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0377 %%% Three Parameter %%% 0378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0379 0380 %%%%%%%%%% spw = specwin('Kaiser', N, psll) %%%%%%%%%% 0381 %%%%%%%%%% create a Kaiser window %%%%%%%%%% 0382 0383 w = init(VERSION); 0384 w = get_window(w, varargin{1}, varargin{2}, varargin{3}); 0385 0386 otherwise 0387 error('### Unknown number of constructor arguments.'); 0388 end 0389 0390 end % function w = specwin(varargin) 0391 0392 0393 %% Helper functions 0394 0395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0396 % 0397 % FUNCTION: specwinFromRepository 0398 % 0399 % DESCRIPTION: construct a specwin from a repository 0400 % 0401 % CALL: fs = specwinFromRepository(pli, version, algoname) 0402 % 0403 % PARAMETER: pli: Parameter list object 0404 % version: cvs version string 0405 % algoname: The m-file name (use the mfilename command) 0406 % 0407 % HISTORY: 22-03-2008 M Hewitson 0408 % Creation 0409 % 0410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0411 0412 function fs = specwinFromRepository(pli, version, algoname) 0413 0414 % Add default values 0415 pl = combine(pli, getDefaultPlist('From Repository')); 0416 0417 % Get parameters 0418 conn = find(pl, 'conn'); 0419 hostname = find(pl, 'hostname'); 0420 database = find(pl, 'database'); 0421 ids = find(pl, 'id'); 0422 0423 % do we have a connection? 0424 closeConn = 0; 0425 if isempty(conn) 0426 closeConn = 1; 0427 % Connect to repository 0428 conn = mysql_connect(hostname, database); 0429 end 0430 if ~isa(conn, 'database') 0431 error('### connection failed.'); 0432 end 0433 % Get each ID 0434 Nids = length(ids); 0435 fs = []; 0436 for kk=1:Nids 0437 0438 %---- This id 0439 id = ids(kk); 0440 disp(sprintf(' - retrieving ID %d', id)); 0441 0442 %---- check ID object type 0443 tt = mysql_getObjType(conn, id); 0444 %---- If this is a specwin 0445 if strcmp(tt, mfilename) 0446 %---- call database constructor 0447 a = ltpda_obj_retrieve(conn, id); 0448 %---- Add history 0449 %---- Add to output array 0450 fs = [fs a]; 0451 else 0452 warning(' !skipping ID %d, type %s', id, tt); 0453 end 0454 0455 end 0456 0457 % close connection 0458 if closeConn 0459 close(conn); 0460 end 0461 0462 end % function fs = specwinFromRepository(pli, version, algoname) 0463 0464 0465 %%%%%%%%%%%%%%%%%%%% define parameter properties list %%%%%%%%%%%%%%%%%%%%% 0466 0467 function w = init(version) 0468 w.name = 'None'; 0469 w.alpha = -1; 0470 w.psll = -1; 0471 w.rov = -1; 0472 w.nenbw = -1; 0473 w.w3db = -1; 0474 w.flatness = -1; 0475 w.ws = -1; 0476 w.ws2 = -1; 0477 w.win = -1; 0478 w.plist = ''; 0479 w.created = '1970-01-01 00:00:00'; 0480 w.version = version; 0481 w = class(w, 'specwin'); 0482 end % function w = init(version) 0483 0484 0485 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0486 % 0487 % FUNCTION: getDefaultPlist 0488 % 0489 % DESCRIPTION: Default Parameter Lists 0490 % 0491 % CALL: out = getDefaultPlist(set-string) 0492 % 0493 % PARAMETER: set-string: A string which defines the default parameter list. 0494 % 0495 % HISTORY: 11-02-2008 M Hueller 0496 % Creation 0497 % 0498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0499 0500 function out = getDefaultPlist(varargin) 0501 0502 % list of available parameter sets 0503 sets = {'From XML File', 'From MAT File', ... 0504 'From Repository', ... 0505 'From Window Definition',... 0506 'From Plist'}; 0507 0508 if nargin == 0 0509 out = sets; 0510 return 0511 end 0512 0513 set = varargin{1}; 0514 switch set 0515 %------------------------------------------ 0516 %--- Repository constructor 0517 %------------------------------------------ 0518 case 'From Repository' 0519 out = plist('hostname', 'localhost', 'database', 'ltpda', 'ID', []); 0520 0521 %------------------------------------------ 0522 %--- Read from XML file 0523 %------------------------------------------ 0524 case 'From XML File' 0525 out = plist('filename', ''); 0526 0527 %------------------------------------------ 0528 %--- Read from MAT file 0529 %------------------------------------------ 0530 case 'From MAT File' 0531 out = plist('filename', ''); 0532 0533 %------------------------------------------ 0534 %--- Create from window definition 0535 %------------------------------------------ 0536 case 'From Window Definition' 0537 out = plist('Name', 'Kaiser', 'N', 10, 'PSLL', 150); 0538 0539 %------------------------------------------ 0540 %--- Create from a plist 0541 %------------------------------------------ 0542 case 'From Plist' 0543 out = plist('Plist', []); 0544 0545 otherwise 0546 out = plist(); 0547 0548 end 0549 0550 0551 end % function out = getDefaultPlist(varargin) 0552 0553 0554