Mercurial > hg > ltpda
comparison m-toolbox/classes/@pzmodel/fngen.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 % FNGEN creates an arbitrarily long time-series based on the input pzmodel. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: FNGEN creates an arbitrarily long time-series based on the | |
5 % input pzmodel. | |
6 % | |
7 % CALL: b = fngen(pzm, pl) | |
8 % | |
9 % PARAMETERS: 'Nsecs' - The number of seconds to produce | |
10 % [default: inverse of PSD length] | |
11 % 'Win' - The spectral window to use for blending segments | |
12 % [default: Kaiser -150dB] | |
13 % | |
14 % <a href="matlab:utils.helper.displayMethodInfo('pzmodel', 'fngen')">Parameters Description</a> | |
15 % | |
16 % VERSION: $Id: fngen.m,v 1.21 2011/04/08 08:56:33 hewitson Exp $ | |
17 % | |
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
19 | |
20 function varargout = fngen(varargin) | |
21 | |
22 %%% Check if this is a call for parameters | |
23 if utils.helper.isinfocall(varargin{:}) | |
24 varargout{1} = getInfo(varargin{3}); | |
25 return | |
26 end | |
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 and plists | |
33 [pzms, pzm_invars] = utils.helper.collect_objects(varargin(:), 'pzmodel', in_names); | |
34 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); | |
35 | |
36 % combine plists | |
37 pl = combine(pl, getDefaultPlist()); | |
38 | |
39 % Loop over input pzms | |
40 bs(1:numel(pzms)) = ao(); | |
41 for j=1:numel(pzms) | |
42 % get sample rate to specify Nyquist | |
43 fs = find(pl, 'fs'); | |
44 if isempty(fs) | |
45 fs = round(getupperFreq(pzms(j)) * 10); | |
46 end | |
47 if fs < 1 | |
48 fs = 1; | |
49 end | |
50 | |
51 % Compute the frequency vector | |
52 Nf = 10001; | |
53 f1 = 0; | |
54 f2 = fs/2; | |
55 f = linspace(f1,f2,Nf); | |
56 N = 2*(Nf-1); | |
57 % Compute model response | |
58 w = ao(plist('tsfcn', 'sqrt(fs/2).*randn(size(t))', 'fs', fs, 'Nsecs', N)); | |
59 wxx = pwelch(w, plist('Nfft', N, 'win', specwin('Rectangular', N))); | |
60 axx = resp(pzms(j), plist('f', f)); | |
61 | |
62 % Compute desired PSD | |
63 wxx.data.setY(wxx.y .* (abs(axx.y).^2)); | |
64 | |
65 % Call ao/fngen | |
66 b = fngen(wxx, pl); | |
67 b.data.setXunits('s'); | |
68 b.data.setYunits(''); | |
69 | |
70 % Add history | |
71 b.addHistory(getInfo('None'), pl, pzm_invars(j), pzms(j).hist); | |
72 | |
73 % Add to outputs | |
74 bs(j) = b; | |
75 end | |
76 | |
77 % Set outputs | |
78 varargout{1} = bs; | |
79 end | |
80 | |
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
82 % Local Functions % | |
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
84 | |
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
86 % | |
87 % FUNCTION: getInfo | |
88 % | |
89 % DESCRIPTION: Get Info Object | |
90 % | |
91 % HISTORY: 11-07-07 M Hewitson | |
92 % Creation. | |
93 % | |
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
95 | |
96 function ii = getInfo(varargin) | |
97 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
98 sets = {}; | |
99 pl = []; | |
100 else | |
101 sets = {'Default'}; | |
102 pl = getDefaultPlist; | |
103 end | |
104 % Build info object | |
105 ii = minfo(mfilename, 'pzmodel', 'ltpda', utils.const.categories.sigproc, '$Id: fngen.m,v 1.21 2011/04/08 08:56:33 hewitson Exp $', sets, pl); | |
106 ii.setModifier(false); | |
107 end | |
108 | |
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
110 % | |
111 % FUNCTION: getDefaultPlist | |
112 % | |
113 % DESCRIPTION: Get Default Plist | |
114 % | |
115 % HISTORY: 11-07-07 M Hewitson | |
116 % Creation. | |
117 % | |
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
119 | |
120 function plout = getDefaultPlist() | |
121 persistent pl; | |
122 if exist('pl', 'var')==0 || isempty(pl) | |
123 pl = buildplist(); | |
124 end | |
125 plout = pl; | |
126 end | |
127 | |
128 function pl = buildplist() | |
129 pl = plist(); | |
130 | |
131 % Nsecs | |
132 p = param({'Nsecs', 'The length of the time-series in seconds.'}, paramValue.DOUBLE_VALUE(-1)); | |
133 pl.append(p); | |
134 | |
135 % Win | |
136 p = param({'Win', 'The window to use in the blending of consecutive segments.'}, paramValue.WINDOW); | |
137 pl.append(p); | |
138 | |
139 end | |
140 |