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] VERSION: $Id: spectrogram.m,v 1.2 2008/02/12 10:11:13 mauro Exp $ The following call returns a parameter list object that contains the default parameter values: >> pl = spectrogram(ao, 'Params') The following call returns a string that contains the routine CVS version: >> version = spectrogram(ao,'Version') The following call returns a string that contains the routine category: >> category = spectrogram(ao,'Category') HISTORY: 12-03-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function varargout = spectrogram(varargin) 0002 % SPECTROGRAM computes a spectrogram of the given ao/tsdata. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: SPECTROGRAM computes a spectrogram of the given ao/tsdata 0007 % using MATLAB's spectrogram function. 0008 % 0009 % CALL: b = spectrogram(a, pl) 0010 % 0011 % PARAMETERS: 0012 % 0013 % 'Win' - a specwin object [default: Kaiser -200dB psll] 0014 % 'Nolap' - segment overlap [default: taken from window function] 0015 % 'Nfft' - number of samples in each short fourier transform 0016 % [default: sample rate of data] 0017 % 0018 % VERSION: $Id: spectrogram.m,v 1.2 2008/02/12 10:11:13 mauro Exp $ 0019 % 0020 % The following call returns a parameter list object that contains the 0021 % default parameter values: 0022 % 0023 % >> pl = spectrogram(ao, 'Params') 0024 % 0025 % The following call returns a string that contains the routine CVS version: 0026 % 0027 % >> version = spectrogram(ao,'Version') 0028 % 0029 % The following call returns a string that contains the routine category: 0030 % 0031 % >> category = spectrogram(ao,'Category') 0032 % 0033 % HISTORY: 12-03-07 M Hewitson 0034 % Creation 0035 % 0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0037 0038 ALGONAME = mfilename; 0039 VERSION = '$Id: spectrogram.m,v 1.2 2008/02/12 10:11:13 mauro Exp $'; 0040 CATEGORY = 'Signal Processing'; 0041 0042 bs = []; 0043 0044 % Check if this is a call for parameters 0045 if nargin == 2 0046 if isa(varargin{1}, 'ao') && ischar(varargin{2}) 0047 in = char(varargin{2}); 0048 if strcmp(in, 'Params') 0049 varargout{1} = getDefaultPL(); 0050 return 0051 elseif strcmp(in, 'Version') 0052 varargout{1} = VERSION; 0053 return 0054 elseif strcmp(in, 'Category') 0055 varargout{1} = CATEGORY; 0056 return 0057 end 0058 end 0059 end 0060 0061 % Collect input ao's, plist's and ao variable names 0062 in_names = {}; 0063 for ii = 1:nargin 0064 in_names{end+1} = inputname(ii); 0065 end 0066 0067 [as, ps, invars] = collect_inputs(varargin, in_names); 0068 0069 % Process parameters 0070 pl = combine(ps, getDefaultPL); 0071 0072 % Check input analysis object 0073 for j=1:numel(as) 0074 a = as(j); 0075 0076 % Get settings for this AO 0077 nfft = find(pl, 'Nfft'); 0078 if isempty(nfft) || nfft < 0 0079 nfft = a.data.fs; 0080 end 0081 win = find(pl, 'Win'); 0082 if length(win.win) < nfft 0083 switch win.name 0084 case {'Kaiser', 'Flattop'} 0085 win = specwin(win.name, nfft, win.psll); 0086 otherwise 0087 win = specwin(win.name, nfft); 0088 end 0089 disp(sprintf('! Reset window to %s(%d)', strrep(win.name, '_', '\_'), length(win.win))) 0090 end 0091 nolap = find(pl, 'Nolap'); 0092 if isempty(nolap) || nolap < 0 0093 nolap = floor(win.rov*nfft/100); 0094 end 0095 0096 % Process data 0097 [S, F, T, P] = spectrogram(a.data.y, win.win, nolap, nfft, a.data.fs); 0098 0099 % make a new history object 0100 h = history(ALGONAME, VERSION, pl, [a.hist]); 0101 h = set(h, 'invars', cellstr(invars{j})); 0102 0103 % Make output AO 0104 do = xyzdata(T, F, P); 0105 do = set(do, 'xunits', 's'); 0106 do = set(do, 'yunits', 'Hz'); 0107 do = set(do, 'zunits', [a.data.yunits '^2/Hz']); 0108 0109 b = ao(do); 0110 b = setnh(b, 'name', sprintf('specgram(%s)', invars{j})); 0111 0112 % add to output 0113 bs = [bs b]; 0114 end 0115 0116 % Reshape the ouput to the same size of the input 0117 bs = reshape(bs, size(as)); 0118 0119 varargout{1} = bs; 0120 0121 0122 %-------------------------------------------------------------------------- 0123 % Get default params 0124 function plo = getDefaultPL() 0125 0126 w = specwin('Kaiser', 10, 200); 0127 plo = plist('Win', w, 'Nolap', -1, 'Nfft', -1); 0128 0129 % END