


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.1 2007/12/26 19:20:20 hewitson Exp $
The following call returns a parameter list object that contains the
default parameter values:
>> pl = spectrogram(ao, 'Params')
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.1 2007/12/26 19:20:20 hewitson 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 % HISTORY: 12-03-07 M Hewitson 0026 % Creation 0027 % 0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0029 0030 ALGONAME = mfilename; 0031 VERSION = '$Id: spectrogram.m,v 1.1 2007/12/26 19:20:20 hewitson Exp $'; 0032 bs = []; 0033 0034 % Check if this is a call for parameters 0035 if nargin == 2 0036 if isa(varargin{1}, 'ao') && ischar(varargin{2}) 0037 in = char(varargin{2}); 0038 if strcmp(in, 'Params') 0039 varargout{1} = getDefaultPL(); 0040 return 0041 elseif strcmp(in, 'Version') 0042 varargout{1} = VERSION; 0043 return 0044 end 0045 end 0046 end 0047 0048 % Collect input ao's, plist's and ao variable names 0049 in_names = {}; 0050 for ii = 1:nargin 0051 in_names{end+1} = inputname(ii); 0052 end 0053 0054 [as, ps, invars] = collect_inputs(varargin, in_names); 0055 0056 % Process parameters 0057 pl = combine(ps, getDefaultPL); 0058 0059 % Check input analysis object 0060 for j=1:numel(as) 0061 a = as(j); 0062 0063 % Get settings for this AO 0064 nfft = find(pl, 'Nfft'); 0065 if isempty(nfft) || nfft < 0 0066 nfft = a.data.fs; 0067 end 0068 win = find(pl, 'Win'); 0069 if length(win.win) < nfft 0070 switch win.name 0071 case {'Kaiser', 'Flattop'} 0072 win = specwin(win.name, nfft, win.psll); 0073 otherwise 0074 win = specwin(win.name, nfft); 0075 end 0076 disp(sprintf('! Reset window to %s(%d)', strrep(win.name, '_', '\_'), length(win.win))) 0077 end 0078 nolap = find(pl, 'Nolap'); 0079 if isempty(nolap) || nolap < 0 0080 nolap = floor(win.rov*nfft/100); 0081 end 0082 0083 % Process data 0084 [S, F, T, P] = spectrogram(a.data.y, win.win, nolap, nfft, a.data.fs); 0085 0086 % make a new history object 0087 h = history(ALGONAME, VERSION, pl, [a.hist]); 0088 h = set(h, 'invars', cellstr(invars{j})); 0089 0090 % Make output AO 0091 do = xyzdata(T, F, P); 0092 do = set(do, 'xunits', 's'); 0093 do = set(do, 'yunits', 'Hz'); 0094 do = set(do, 'zunits', [a.data.yunits '^2/Hz']); 0095 0096 b = ao(do); 0097 b = setnh(b, 'name', sprintf('specgram(%s)', invars{j})); 0098 0099 % add to output 0100 bs = [bs b]; 0101 end 0102 0103 % Reshape the ouput to the same size of the input 0104 bs = reshape(bs, size(as)); 0105 0106 varargout{1} = bs; 0107 0108 0109 %-------------------------------------------------------------------------- 0110 % Get default params 0111 function plo = getDefaultPL() 0112 0113 w = specwin('Kaiser', 10, 200); 0114 plo = plist('Win', w, 'Nolap', -1, 'Nfft', -1); 0115 0116 % END