SPECTROGRAM computes a spectrogram of the given ao/tsdata. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: SPECTROGRAM computes a spectrogram of the given ao/tsdata using MATLAB's spectrogram function. CALL: b = spectrogram(a, pl) PARAMETERS: 'Win' - a specwin object [default: Kaiser -200dB psll] 'Nolap' - segment overlap [default: taken from window function] 'Nfft' - number of samples in each short fourier transform [default: sample rate of data] M-FILE INFO: Get information about this methods by calling >> ao.getInfo('spectrogram') Get information about a specified set-plist by calling: >> ao.getInfo('spectrogram', 'set') VERSION: $Id: spectrogram.m,v 1.10 2008/09/05 14:15:40 hewitson Exp $ HISTORY: 12-03-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % SPECTROGRAM computes a spectrogram of the given ao/tsdata. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: SPECTROGRAM computes a spectrogram of the given ao/tsdata 0005 % using MATLAB's spectrogram function. 0006 % 0007 % CALL: b = spectrogram(a, pl) 0008 % 0009 % PARAMETERS: 0010 % 0011 % 'Win' - a specwin object [default: Kaiser -200dB psll] 0012 % 'Nolap' - segment overlap [default: taken from window function] 0013 % 'Nfft' - number of samples in each short fourier transform 0014 % [default: sample rate of data] 0015 % 0016 % M-FILE INFO: Get information about this methods by calling 0017 % >> ao.getInfo('spectrogram') 0018 % 0019 % Get information about a specified set-plist by calling: 0020 % >> ao.getInfo('spectrogram', 'set') 0021 % 0022 % VERSION: $Id: spectrogram.m,v 1.10 2008/09/05 14:15:40 hewitson Exp $ 0023 % 0024 % HISTORY: 12-03-07 M Hewitson 0025 % Creation 0026 % 0027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0028 0029 function varargout = spectrogram(varargin) 0030 0031 bs = []; 0032 0033 %%% Check if this is a call for parameters 0034 if utils.helper.isinfocall(varargin{:}) 0035 varargout{1} = getInfo(varargin{3}); 0036 return 0037 end 0038 0039 import utils.const.* 0040 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0041 0042 if nargout == 0 0043 error('### spectrogram cannot be used as a modifier. Please give an output variable.'); 0044 end 0045 0046 % Collect input variable names 0047 in_names = cell(size(varargin)); 0048 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0049 0050 % Collect all AOs 0051 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0052 [ps, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names); 0053 0054 % Process parameters 0055 pl = combine(ps, getDefaultPlist); 0056 0057 % Check input analysis object 0058 for j=1:numel(as) 0059 a = as(j); 0060 0061 % Get settings for this AO 0062 nfft = find(pl, 'Nfft'); 0063 if isempty(nfft) || nfft < 0 0064 nfft = a.data.fs; 0065 end 0066 win = find(pl, 'Win'); 0067 if length(win.win) < nfft 0068 switch win.type 0069 case {'Kaiser', 'Flattop'} 0070 win = specwin(win.type, nfft, win.psll); 0071 otherwise 0072 win = specwin(win.type, nfft); 0073 end 0074 utils.helper.msg(msg.PROC1, 'reset window to %s(%d)', strrep(win.type, '_', '\_'), length(win.win)); 0075 end 0076 nolap = find(pl, 'Nolap'); 0077 if isempty(nolap) || nolap < 0 0078 nolap = floor(win.rov*nfft/100); 0079 end 0080 0081 % Process data 0082 [S, F, T, P] = spectrogram(a.data.y, win.win, nolap, nfft, a.data.fs); 0083 0084 % Make output AO 0085 do = xyzdata(T, F, P); 0086 do.setXunits('s'); 0087 do.setYunits('Hz'); 0088 do.setZunits(a.data.yunits^2 / unit('Hz')); 0089 0090 b = ao(do); 0091 b.setName(sprintf('specgram(%s)', ao_invars{j}), 'internal'); 0092 b.addHistory(getInfo(), pl, cellstr(ao_invars{j}), a.hist); 0093 0094 % add to output 0095 bs = [bs b]; 0096 end 0097 0098 % Reshape the ouput to the same size of the input 0099 bs = reshape(bs, size(as)); 0100 0101 varargout{1} = bs; 0102 end 0103 0104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0105 % Local Functions % 0106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0107 0108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0109 % 0110 % FUNCTION: getInfo 0111 % 0112 % DESCRIPTION: Get Info Object 0113 % 0114 % HISTORY: 11-07-07 M Hewitson 0115 % Creation. 0116 % 0117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0118 0119 function ii = getInfo(varargin) 0120 if nargin == 1 && strcmpi(varargin{1}, 'None') 0121 sets = {}; 0122 pl = []; 0123 else 0124 sets = {'Default'}; 0125 pl = getDefaultPlist; 0126 end 0127 % Build info object 0128 ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: spectrogram.m,v 1.10 2008/09/05 14:15:40 hewitson Exp $', sets, pl); 0129 end 0130 0131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0132 % 0133 % FUNCTION: getDefaultPlist 0134 % 0135 % DESCRIPTION: Get Default Plist 0136 % 0137 % HISTORY: 11-07-07 M Hewitson 0138 % Creation. 0139 % 0140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0141 0142 function plo = getDefaultPlist() 0143 plo = plist('Win', getappdata(0, 'ltpda_default_spectral_window'), 'Nolap', -1, 'Nfft', -1); 0144 end 0145