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