


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.37 2008/03/24 23:51:38 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.37 2008/03/24 23:51:38 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.37 2008/03/24 23:51:38 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 0276 % do constructor from window name 0277 switch wname 0278 case 'Kaiser' 0279 w = specwin(wname, find(pl, 'N'), find(pl, 'PSLL')); 0280 otherwise 0281 w = specwin(wname, find(pl, 'N')); 0282 end 0283 w.plist = pl; 0284 0285 elseif ~isempty(ipl) 0286 %----------------------------------------------------- 0287 %--- Construct from plist 0288 %----------------------------------------------------- 0289 0290 % if the plist is empty, we return an empty SPECWIN 0291 if nparams(ipl) == 0 0292 w = init(VERSION); 0293 else 0294 % do plist constructor 0295 w = specwin(ipl); 0296 end 0297 0298 else 0299 %----------------------------------------------------- 0300 %--- ERROR 0301 %----------------------------------------------------- 0302 0303 %% is the plist is empty then return an empty SPECWIN 0304 if nparams(pl) == 0 0305 w = init(VERSION); 0306 else 0307 error('### Unknown SPECWIN constructor method.'); 0308 end 0309 end 0310 0311 elseif ischar(varargin{1}) 0312 0313 if strcmp(varargin{1}, 'Types') 0314 %%%%%%%%%% spw = specwin('Types') %%%%%%%%%% 0315 % return list of windows 0316 w = {... 0317 'Rectangular', 'Welch', 'Bartlett', 'Hanning', 'Hamming',... 0318 'Nuttall3', 'Nuttall4', 'Nuttall3a', 'Nuttall3b', 'Nuttall4a',... 0319 'Nuttall4b', 'Nuttall4c', 'BH92', 'SFT3F', 'SFT3M', 'FTNI', 'SFT4F', 'SFT5F',... 0320 'SFT4M', 'FTHP', 'HFT70', 'FTSRS', 'SFT5M', 'HFT90D', 'HFT95', 'HFT116D',... 0321 'HFT144D', 'HFT169D', 'HFT196D', 'HFT223D', 'HFT248D'... 0322 }; 0323 0324 else 0325 %%%%%%%%%% spw = specwin('foo.xml') %%%%%%%%%% 0326 %%%%%%%%%% spw = specwin('foo.mat') %%%%%%%%%% 0327 % from filename: XML, MAT 0328 0329 filename = varargin{1}; 0330 [path, name, ext, vers] = fileparts(filename); 0331 switch ext 0332 case '.mat' 0333 w = load(filename); 0334 w = w.a; 0335 case '.xml' 0336 root_node = xmlread(filename); 0337 w = ltpda_xmlread(root_node, 'specwin'); 0338 otherwise 0339 error('### Unknown file type.'); 0340 end 0341 end 0342 0343 else 0344 error('### unknown constructor type for specwin object.'); 0345 end 0346 0347 case 2 0348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0349 %%% Two Parameter %%% 0350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0351 0352 if isa(varargin{1}, 'specwin') 0353 w = varargin{1}; 0354 %%%%%%%%%% spw = specwin(specwin, ...) %%%%%%%%%% 0355 %%%%%%%%%% copy specwin %%%%%%%%%% 0356 0357 elseif isa(varargin{1}, 'database') 0358 %%%%%%%%%% spw = specwin(database, IDs) %%%%%%%%%% 0359 % From DATABASE 0360 0361 w = retrieve(varargin{1}, varargin{2:end}); 0362 0363 elseif ischar(varargin{1}) 0364 %%%%%%%%%% spw = specwin('Win_type', N) %%%%%%%%%% 0365 %%%%%%%%%% create a particular type %%%%%%%%%% 0366 0367 w = init(VERSION); 0368 w = get_window(w, varargin{1}, varargin{2}); 0369 0370 else 0371 error('### unknown constructor for specwin object.') 0372 end 0373 0374 case 3 0375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0376 %%% Three Parameter %%% 0377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0378 0379 %%%%%%%%%% spw = specwin('Kaiser', N, psll) %%%%%%%%%% 0380 %%%%%%%%%% create a Kaiser window %%%%%%%%%% 0381 0382 w = init(VERSION); 0383 w = get_window(w, varargin{1}, varargin{2}, varargin{3}); 0384 0385 otherwise 0386 error('### Unknown number of constructor arguments.'); 0387 end 0388 0389 end % function w = specwin(varargin) 0390 0391 0392 %% Helper functions 0393 0394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0395 % 0396 % FUNCTION: specwinFromRepository 0397 % 0398 % DESCRIPTION: construct a specwin from a repository 0399 % 0400 % CALL: fs = specwinFromRepository(pli, version, algoname) 0401 % 0402 % PARAMETER: pli: Parameter list object 0403 % version: cvs version string 0404 % algoname: The m-file name (use the mfilename command) 0405 % 0406 % HISTORY: 22-03-2008 M Hewitson 0407 % Creation 0408 % 0409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0410 0411 function fs = specwinFromRepository(pli, version, algoname) 0412 0413 % Add default values 0414 pl = combine(pli, getDefaultPlist('From Repository')); 0415 0416 % Get parameters 0417 conn = find(pl, 'conn'); 0418 hostname = find(pl, 'hostname'); 0419 database = find(pl, 'database'); 0420 ids = find(pl, 'id'); 0421 0422 % do we have a connection? 0423 closeConn = 0; 0424 if isempty(conn) 0425 closeConn = 1; 0426 % Connect to repository 0427 conn = mysql_connect(hostname, database); 0428 end 0429 if ~isa(conn, 'database') 0430 error('### connection failed.'); 0431 end 0432 % Get each ID 0433 Nids = length(ids); 0434 fs = []; 0435 for kk=1:Nids 0436 0437 %---- This id 0438 id = ids(kk); 0439 disp(sprintf(' - retrieving ID %d', id)); 0440 0441 %---- check ID object type 0442 tt = mysql_getObjType(conn, id); 0443 %---- If this is a specwin 0444 if strcmp(tt, mfilename) 0445 %---- call database constructor 0446 a = ltpda_obj_retrieve(conn, id); 0447 %---- Add history 0448 %---- Add to output array 0449 fs = [fs a]; 0450 else 0451 warning(' !skipping ID %d, type %s', id, tt); 0452 end 0453 0454 end 0455 0456 % close connection 0457 if closeConn 0458 close(conn); 0459 end 0460 0461 end % function fs = specwinFromRepository(pli, version, algoname) 0462 0463 0464 %%%%%%%%%%%%%%%%%%%% define parameter properties list %%%%%%%%%%%%%%%%%%%%% 0465 0466 function w = init(version) 0467 w.name = 'None'; 0468 w.alpha = -1; 0469 w.psll = -1; 0470 w.rov = -1; 0471 w.nenbw = -1; 0472 w.w3db = -1; 0473 w.flatness = -1; 0474 w.ws = -1; 0475 w.ws2 = -1; 0476 w.win = -1; 0477 w.plist = ''; 0478 w.created = '1970-01-01 00:00:00'; 0479 w.version = version; 0480 w = class(w, 'specwin'); 0481 end % function w = init(version) 0482 0483 0484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0485 % 0486 % FUNCTION: getDefaultPlist 0487 % 0488 % DESCRIPTION: Default Parameter Lists 0489 % 0490 % CALL: out = getDefaultPlist(set-string) 0491 % 0492 % PARAMETER: set-string: A string which defines the default parameter list. 0493 % 0494 % HISTORY: 11-02-2008 M Hueller 0495 % Creation 0496 % 0497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0498 0499 function out = getDefaultPlist(varargin) 0500 0501 % list of available parameter sets 0502 sets = {'From XML File', 'From MAT File', ... 0503 'From Repository', ... 0504 'From Window Definition',... 0505 'From Plist'}; 0506 0507 if nargin == 0 0508 out = sets; 0509 return 0510 end 0511 0512 set = varargin{1}; 0513 switch set 0514 %------------------------------------------ 0515 %--- Repository constructor 0516 %------------------------------------------ 0517 case 'From Repository' 0518 out = plist('hostname', 'localhost', 'database', 'ltpda', 'ID', []); 0519 0520 %------------------------------------------ 0521 %--- Read from XML file 0522 %------------------------------------------ 0523 case 'From XML File' 0524 out = plist('filename', ''); 0525 0526 %------------------------------------------ 0527 %--- Read from MAT file 0528 %------------------------------------------ 0529 case 'From MAT File' 0530 out = plist('filename', ''); 0531 0532 %------------------------------------------ 0533 %--- Create from window definition 0534 %------------------------------------------ 0535 case 'From Window Definition' 0536 out = plist('Name', 'Kaiser', 'N', 10, 'PSLL', 150); 0537 0538 %------------------------------------------ 0539 %--- Create from a plist 0540 %------------------------------------------ 0541 case 'From Plist' 0542 out = plist('Plist', []); 0543 0544 otherwise 0545 out = plist(); 0546 0547 end 0548 0549 0550 end % function out = getDefaultPlist(varargin) 0551 0552 0553