


LINEDETECT find spectral lines in the ao/fsdata objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION: LINEDETECT find spectral lines in the ao/fsdata objects.
CALL: b = linedetect(a, pl)
PARAMETERS: N - max number of lines to return [default: 10]
fsearch - freqeuncy search interval [default: all]
thresh - a threshold to test normalised amplitude spectrum against
[default: 2]
bw - bandwidth over which to compute median [default: 20 samples]
hc - percent of outliers to exclude from median estimation (0-1)
[default: 0.8]
M-FILE INFO: Get information about this methods by calling
>> ao.getInfo('linedetect')
Get information about a specified set-plist by calling:
>> ao.getInfo('linedetect', 'None')
VERSION: $Id: linedetect.m,v 1.1 2008/08/10 20:08:33 hewitson Exp $
HISTORY: 14-05-2007 M Hewitson
Creation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


0001 % LINEDETECT find spectral lines in the ao/fsdata objects. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: LINEDETECT find spectral lines in the ao/fsdata objects. 0005 % 0006 % CALL: b = linedetect(a, pl) 0007 % 0008 % PARAMETERS: N - max number of lines to return [default: 10] 0009 % fsearch - freqeuncy search interval [default: all] 0010 % thresh - a threshold to test normalised amplitude spectrum against 0011 % [default: 2] 0012 % bw - bandwidth over which to compute median [default: 20 samples] 0013 % hc - percent of outliers to exclude from median estimation (0-1) 0014 % [default: 0.8] 0015 % 0016 % M-FILE INFO: Get information about this methods by calling 0017 % >> ao.getInfo('linedetect') 0018 % 0019 % Get information about a specified set-plist by calling: 0020 % >> ao.getInfo('linedetect', 'None') 0021 % 0022 % VERSION: $Id: linedetect.m,v 1.1 2008/08/10 20:08:33 hewitson Exp $ 0023 % 0024 % HISTORY: 14-05-2007 M Hewitson 0025 % Creation 0026 % 0027 % 0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0029 0030 function varargout = linedetect(varargin) 0031 0032 % Check if this is a call for parameters 0033 if utils.helper.isinfocall(varargin{:}) 0034 varargout{1} = getInfo(varargin{3}); 0035 return 0036 end 0037 0038 if nargout == 0 0039 error('### cat cannot be used as a modifier. Please give an output variable.'); 0040 end 0041 0042 % Collect input variable names 0043 in_names = cell(size(varargin)); 0044 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0045 0046 % Collect all AOs 0047 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0048 [pli, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names); 0049 0050 % Decide on a deep copy or a modify 0051 bs = copy(as, nargout); 0052 0053 Na = numel(bs); 0054 if isempty(bs) 0055 error('### Please input at least one AO.'); 0056 end 0057 0058 % Combine plists 0059 if ~isempty(pli) 0060 pl = combine(pli, getDefaultPlist()); 0061 else 0062 pl = getDefaultPlist(); 0063 end 0064 0065 % Get parameters from plist 0066 N = find(pl, 'N'); 0067 fsearch = find(pl, 'fsearch'); 0068 thresh = find(pl, 'thresh'); 0069 0070 % Loop over input AOs 0071 for j=1:Na 0072 if isa(bs(j).data, 'fsdata') 0073 0074 % Make noise-floor estimate 0075 nf = smoother(bs(j), pl); 0076 0077 % Make ratio 0078 r = bs(j)./nf; 0079 0080 % find lines 0081 lines = findLines(bs(j).data.y, r.data.getX, r.data.y, thresh, N, fsearch); 0082 0083 % Make output data 0084 fs = fsdata([lines(:).f], [lines(:).a], bs(j).data.fs); 0085 0086 else 0087 error('### I can only find lines in frequency-series AOs.'); 0088 end 0089 0090 %------- Make output AO 0091 0092 % make output analysis object 0093 bs(j).data = fs; 0094 0095 bs(j).setName(sprintf('lines(%s)', ao_invars{1})); 0096 bs(j).addHistory(getInfo('None'), pli, ao_invars(j), bs(j).hist); 0097 end 0098 0099 % return output 0100 varargout{1} = bs; 0101 end 0102 0103 %-------------------------------------------------------------------------- 0104 % find spectral lines 0105 function lines = findLines(ay, f, nay, thresh, N, fsearch) 0106 0107 % look for spectral lines 0108 l = 0; 0109 pmax = 0; 0110 pmaxi = 0; 0111 line = []; 0112 idx = find( f>=fsearch(1) & f<=fsearch(2) ); 0113 for j=1:length(idx) 0114 v = nay(idx(j)); 0115 if v > thresh 0116 if v > pmax 0117 pmax = v; 0118 pmaxi = idx(j); 0119 end 0120 else 0121 if pmax > 0 0122 % find index when we have pmax 0123 fidx = pmaxi; %(find(nay(1:idx(j))==pmax)); 0124 l = l+1; 0125 line(l).idx = fidx; 0126 line(l).f = f(fidx); 0127 line(l).a = ay(fidx); 0128 end 0129 pmax = 0; 0130 end 0131 end 0132 0133 % Select largest peaks 0134 lines = []; 0135 if ~isempty(line) 0136 [bl, lidx] = sort([line.a], 'descend'); 0137 lidxs = lidx(1:min([N length(lidx)])); 0138 lines = line(lidxs); 0139 disp(sprintf(' + found %d lines.', length([lines.f]))); 0140 else 0141 disp(' + found 0 lines.'); 0142 end 0143 end 0144 0145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0146 % Local Functions % 0147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0148 0149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0150 % 0151 % FUNCTION: getInfo 0152 % 0153 % DESCRIPTION: Get Info Object 0154 % 0155 % HISTORY: 11-07-07 M Hewitson 0156 % Creation. 0157 % 0158 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0159 0160 function ii = getInfo(varargin) 0161 if nargin == 1 && strcmpi(varargin{1}, 'None') 0162 sets = {}; 0163 pl = []; 0164 else 0165 sets = {'Default'}; 0166 pl = getDefaultPlist; 0167 end 0168 % Build info object 0169 ii = minfo(mfilename, 'm', '', 'Signal Processing', '$Id: linedetect.m,v 1.1 2008/08/10 20:08:33 hewitson Exp $', sets, pl); 0170 end 0171 0172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0173 % 0174 % FUNCTION: getDefaultPlist 0175 % 0176 % DESCRIPTION: Get Default Plist 0177 % 0178 % HISTORY: 11-07-07 M Hewitson 0179 % Creation. 0180 % 0181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0182 0183 function plo = getDefaultPlist() 0184 plo = plist('N', 10, 'fsearch', [0 1e10], 'thresh', 2, 'bw', 20, 'hc', 0.8); 0185 end 0186