0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 function plotWindow(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 if nargin == 2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 mainfig = varargin{end-1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 plotType = varargin{end};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 ax = getappdata(mainfig.handle, 'axes');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 elseif nargin == 3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 ax = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 mainfig = varargin{2};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 plotType = varargin{3};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 info = findobj(mainfig.handle, 'Tag', 'InfoDisplay');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % get window type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 winTxt = findobj(mainfig.handle, 'Tag', 'WindowSelect');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 wins = get(winTxt, 'String');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 win = wins{get(winTxt, 'Value')};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % Get window size
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 sizeTxt = findobj(mainfig.handle, 'Tag', 'WindowSize');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 winlen = str2num(get(sizeTxt, 'String'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 if strcmpi(win, 'Kaiser')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % get psll
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 psllTxt = findobj(mainfig.handle, 'Tag', 'WindowPSLL');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 psll = str2num(get(psllTxt, 'String'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 w = specwin(win, winlen, psll);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 cstr = sprintf('specwin(''%s'', %d, %f)', win, winlen, psll);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 w = specwin(win, winlen);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 cstr = sprintf('specwin(''%s'', %d)', win, winlen);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 consTxt = findobj(mainfig.handle, 'Tag', 'ConstructorDisplay');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 set(consTxt, 'String', cstr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 titleStr = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 legendStr = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 switch plotType
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 case 'Time-domain'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 hl = plot(ax, 1:length(w.win), w.win);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 xlabel('sample');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 ylabel('amplitude');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 case 'Freq-domain'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 % Freq response
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 f = linspace(-30,30,1000);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 r = zeros(size(f));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 N = length(w.win);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 % do dft
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 for j=1:length(f)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 k = [0:N-1].';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 r(j) = (w.win * exp(-2*pi*1i*f(j)*k/N) )./w.ws;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 % convert to dB
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 dbr = 20*log10(abs(r)); hl = plot(ax, f, dbr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 xlabel('bin');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 ylabel('amplitude [dB]');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 col = [0.8 0.1 0.1];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 set(hl, 'Color', col);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 titleStr = [titleStr, utils.plottools.label(w.type), ', '];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 titleStr = titleStr(1:end-2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 title(sprintf('Window: %s', titleStr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 axis tight
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 grid on
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 % Info string
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 lstr = [sprintf('alpha = %g\n', w.alpha)...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 sprintf('psll = %g\n', w.psll)...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 sprintf('rov = %g\n', w.rov)...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 sprintf('nenbw = %g\n', w.nenbw)...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 sprintf('w3db = %g\n', w.w3db)...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 sprintf('flatness = %g\n', w.flatness)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 legendStr = [legendStr cellstr(lstr)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 set(info, 'String', legendStr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 end
|