comparison m-toolbox/classes/@ao/spectrogram.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % SPECTROGRAM computes a spectrogram of the given ao/tsdata.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SPECTROGRAM computes a spectrogram of the given ao/tsdata
5 % using MATLAB's spectrogram function.
6 %
7 % CALL: b = spectrogram(a, pl)
8 %
9 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'spectrogram')">Parameters Description</a>
10 %
11 % VERSION: $Id: spectrogram.m,v 1.30 2011/04/08 08:56:18 hewitson Exp $
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15 function varargout = spectrogram(varargin)
16
17 bs = [];
18
19 %%% Check if this is a call for parameters
20 if utils.helper.isinfocall(varargin{:})
21 varargout{1} = getInfo(varargin{3});
22 return
23 end
24
25 import utils.const.*
26 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
27
28 % Collect input variable names
29 in_names = cell(size(varargin));
30 for ii = 1:nargin,in_names{ii} = inputname(ii);end
31
32 % Collect all AOs
33 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
34 [ps, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
35
36 % Process parameters
37 pl = parse(ps, getDefaultPlist);
38
39 as = copy(as, nargout);
40
41 % Check input analysis object
42 for j=1:numel(as)
43 a = as(j);
44
45 if isa(a.data, 'tsdata')
46 % Get settings for this AO
47 nfft = find(pl, 'Nfft');
48 if isempty(nfft) || nfft < 0
49 nfft = length(a.data.y)/2;
50 end
51 win = find(pl, 'Win');
52 if ischar(win)
53 win = specwin(win);
54 end
55 if length(win.win) < nfft
56 switch lower(win.type)
57 case 'kaiser'
58 win = specwin(win.type, nfft, win.psll);
59 otherwise
60 win = specwin(win.type, nfft);
61 end
62 utils.helper.msg(msg.PROC1, 'reset window to %s(%d)', strrep(win.type, '_', '\_'), length(win.win));
63 end
64 nolap = find(pl, 'Nolap');
65 if isempty(nolap) || nolap < 0
66 nolap = floor(win.rov*nfft/100);
67 end
68
69 % Process data
70 [S, F, T, P] = spectrogram(a.data.y, win.win, nolap, nfft, a.data.fs);
71
72 % Make output AO
73 do = xyzdata(T, F, P);
74 do.setXunits('s');
75 do.setYunits('Hz');
76 do.setZunits(a.data.yunits^2 / unit('Hz'));
77
78 a.data = do;
79 a.name = sprintf('spectrogram(%s)', ao_invars{j});
80 a.addHistory(getInfo('None'), pl, cellstr(ao_invars{j}), a.hist);
81
82 % add to output
83 bs = [bs a];
84 else
85 warning('!!! Skipping input AO [%s] - it is not a time-series', a.name);
86 % add to output
87 bs = [bs a];
88 end
89 end
90
91 % Set output
92 if nargout == numel(bs)
93 % List of outputs
94 for ii = 1:numel(bs)
95 varargout{ii} = bs(ii);
96 end
97 else
98 % Single output
99 varargout{1} = bs;
100 end
101
102 end
103
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 % Local Functions %
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 %
110 % FUNCTION: getInfo
111 %
112 % DESCRIPTION: Get Info Object
113 %
114 % HISTORY: 11-07-07 M Hewitson
115 % Creation.
116 %
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118
119 function ii = getInfo(varargin)
120 if nargin == 1 && strcmpi(varargin{1}, 'None')
121 sets = {};
122 pl = [];
123 else
124 sets = {'Default'};
125 pl = getDefaultPlist;
126 end
127 % Build info object
128 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: spectrogram.m,v 1.30 2011/04/08 08:56:18 hewitson Exp $', sets, pl);
129 end
130
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 %
133 % FUNCTION: getDefaultPlist
134 %
135 % DESCRIPTION: Get Default Plist
136 %
137 % HISTORY: 11-07-07 M Hewitson
138 % Creation.
139 %
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141
142 function plout = getDefaultPlist()
143 persistent pl;
144 if exist('pl', 'var')==0 || isempty(pl)
145 pl = buildplist();
146 end
147 plout = pl;
148 end
149
150 function pl = buildplist()
151
152 pl = plist();
153
154 % Win
155 p = param({'Win', 'The spectral window to apply to the data.'}, paramValue.WINDOW);
156 pl.append(p);
157
158 % Nolap
159 p = param({'Nolap', 'The segment overlap (%).'}, {1, {-1}, paramValue.OPTIONAL});
160 pl.append(p);
161
162 % Nfft
163 p = param({'Nfft', 'The number of samples in each short fft.'}, {1, {-1}, paramValue.OPTIONAL});
164 pl.append(p);
165
166 end
167
168 % PARAMETERS:
169 %
170 % 'Win' - a specwin object [default: Kaiser -200dB psll]
171 % 'Nolap' - segment overlap [default: taken from window function]
172 % 'Nfft' - number of samples in each short fourier transform
173 % [default: sample rate of data]
174 %