0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % CPSD computes the output theoretical CPSD shape with given inputs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % DESCRIPTION: CPSD computes the output theoretical CPSD shape with given inputs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % Unlike PSD, it returns the total contribution and takes
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % input vectors/square matrices of objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % CALL: [mat_out] = CPSD(sys, pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % INPUTS:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % - sys, (array of) ssm object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % OUTPUTS:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % _ mat_out contains specified returned aos
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'CPSD')">Parameters Description</a>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 % VERSION: $Id: CPSD.m,v 1.11 2011/04/27 17:21:27 adrien Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 function varargout = CPSD(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 %% starting initial checks
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % use the caller is method flag
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 callerIsMethod = utils.helper.callerIsMethod;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 % Check if this is a call for parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 if utils.helper.isinfocall(varargin{:})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 varargout{1} = getInfo(varargin{3});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 % Collect input variable names
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 in_names = cell(size(varargin));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 for ii = 1:nargin,in_names{ii} = inputname(ii);end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 % Collect all SSMs and plists
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 if ~isempty(rest)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 pl = combine(pl, plist(rest{:}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 pl = combine(pl, getDefaultPlist());
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 %%% Internal call: Only one object + don't look for a plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 internal = strcmp(varargin{end}, 'internal');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 %% begin function body
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 %% retrieve system infos
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 if numel(sys)~=1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 error('noisespectrum needs exactly one ssm as an input')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 if ~sys.isnumerical
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 error(['error because system ',sys.name,' is not numerical']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 if ~sys.isStable
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 error('input ssm is not stable!')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 if sys.timestep==0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 timestep = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 timestep = sys.timestep;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 if ~internal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 inhist = sys.hist;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 %% modifying system's ordering
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 if find(pl, 'reorganize')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 sys = reorganize(sys, pl, 'set', 'for cpsd', 'internal', 'internal');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 %% collecting functions i/o data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 aos_in = find(pl, 'aos');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 PZ_in = find(pl, 'PZmodels');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 cov_in = find(pl, 'covariance');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 cpsd_in = find(pl, 'CPSD');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 noise_in = blkdiag(cov_in, cpsd_in/(timestep*2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 [U1,S1,V1] = svd(noise_in.'); %#ok<NASGU>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 noise_mat = U1*sqrt(S1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 %% getting system's i/o sizes
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 inputSizes = sys.inputsizes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 outputSizes = sys.outputsizes; %#ok<NASGU>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 Naos_in = inputSizes(1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 NPZmodels = inputSizes(3);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 %% retrieving frequency vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 if isempty(Naos_in)==0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 f1 = find(pl,'f1');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 f2 = find(pl,'f2');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 NFreqs = find(pl,'nf');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 if isempty(f1) || isempty(f2)|| isempty(NFreqs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 error('### Please specify frequency vector a start and stop frequency .');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 freqs = 10.^linspace(log10(f1), log10(f2), NFreqs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 freqs = aos_in(1).x;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 %% checking frequency vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 for i=2:numel(aos_in)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 if ~isequal(freqs,aos_in(i).x)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 error('there exist different frequency vectors');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 %% reshape pzmodels and aos for input cross-spectra
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 if numel(PZ_in)==NPZmodels
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 PZfull = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 PZdata = zeros(NPZmodels,NFreqs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 for i=1:NPZmodels
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 a = resp(PZ_in(i), freqs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 PZdata(i,:) = reshape(a.y,[1,NFreqs]) ;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 elseif size(PZ_in,1)==NPZmodels && size(PZ_in,2)==NPZmodels
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 PZfull = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 PZdata = zeros(Npzmodels,Npzmodels,NFreqs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 for i=1:NPZmodels
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 for j=1:Npzmodels
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 a = resp(PZ_in(i,j), freqs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 PZdata(i,j,:) = reshape(a.y,[1,NFreqs]) ;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 error('Wrong size for field PZ_in')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 if numel(aos_in)==Naos_in
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 AOfull = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 AOdata = zeros(Naos_in,NFreqs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 for i=1:Naos_in
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 AOdata(i,:) = reshape(aos_in(i).y,[1,NFreqs]) ;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 elseif size(aos_in,1)==Naos_in && size(aos_in,2)==Naos_in
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 AOfull = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 AOdata = zeros(Naos_in,Naos_in,NFreqs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 for i=1:Naos_in
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 for j=1:Naos_in
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 AOdata(i,j,:) = reshape(aos_in(i,j).y,[1,NFreqs]) ;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 error('Wrong size for field aos_in')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 %% SSM Transfer function
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 [a, b, c, d, Ts, InputName, StateName, OutputName,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 inputvarunits, ssvarunits, outputvarunits] = double(sys); %#ok<ASGLU>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 resps = ssm.doBode(a, b, c, d, 2*pi*freqs, Ts);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 Noutputs = numel(OutputName);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 %% power for each frequency with SVD computation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 Result = zeros(Noutputs,Noutputs,NFreqs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 for i_freq=1:NFreqs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 %% contribution from aos, testing positiveness
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 if AOfull
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 PowAO = squeeze(AOdata(:,:,i_freq));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 [U1,S1,V1] = svd(PowAO.'); %#ok<NASGU>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 if (sum(S1<0)>0)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 error('AO covariance matrix is not positive')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 AmpAO = U1*sqrt(S1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 if (sum(AOdata(:,i_freq)<0)>0)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 error('non positive covariance')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 AmpAO = diag(AOdata(:,i_freq).^0.5);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 %% contribution from PZmodels, testing positiveness
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 if PZfull
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 PowPZ = squeeze(PZdata(:,:,i_freq));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 [U1,S1,V1] = svd(PowPZ.'); %#ok<NASGU>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 if (sum(S1<0)>0)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 error('PZmodels covariance matrix is not positive')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 AmpPZ = U1*sqrt(S1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 if (sum(PZdata(:,i_freq)<0)>0)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 error('non positive covariance')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191 AmpPZ = diag(PZdata(:,i_freq).^0.5);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193 %% summing all three contributions sources, computing CPSD
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 Amp = blkdiag(AmpAO, noise_mat, AmpPZ);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 RespLoc = squeeze(resps(:,:,i_freq));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 noise = RespLoc * Amp * (RespLoc*Amp)';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 Result(:,:,i_freq) = real(noise) * (2*timestep); % 2 correction added here
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 %% saving in aos
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 ao_out = ao.initObjectWithSize(Noutputs, Noutputs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203 for io=1:Noutputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 for jo=1:Noutputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205 ao_out(io,jo).setData(fsdata(freqs, squeeze(Result(jo,io,:))));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 if io~=jo
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207 ao_out(io,jo).setName( ['Cross PSD of ', OutputName{jo}, ' and ', OutputName{io}]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 ao_out(io,jo).setName( ['PSD of ' , OutputName{jo}]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 ao_out(io,jo).setXunits('Hz');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 ao_out(io,jo).setYunits(outputvarunits(io)*outputvarunits(jo)/unit('Hz'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213 if io~=jo
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 ao_out(io,jo).setDescription( ['Cross PSD of ', OutputName{jo}, ' and ', OutputName{io}]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216 ao_out(io,jo).setDescription( ['PSD of ' , OutputName{jo}]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221 %% construct output matrix object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222 out = matrix(ao_out);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 if callerIsMethod
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224 % do nothing
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226 myinfo = getInfo('None');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227 out.addHistory(myinfo, pl , ssm_invars(1), inhist );
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 %% Set output depending on nargout
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 if nargout == 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 varargout = {out};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 elseif nargout == 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 iplot(ao_out);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 error('Wrong number of outputs')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 % Get Info Object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 function ii = getInfo(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 if nargin == 1 && strcmpi(varargin{1}, 'None')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 sets = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 pl = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 sets = {'Default'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 pl = getDefaultPlist;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 % Build info object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.op, '$Id: CPSD.m,v 1.11 2011/04/27 17:21:27 adrien Exp $', sets, pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 % Get Default Plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 function pl = getDefaultPlist()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262 pl = ssm.getInfo('reorganize', 'for CPSD').plists;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 pl.remove('set');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265 p = param({'covariance', 'The covariance of this noise between input ports for the <i>time-discrete</i> noise model.'}, []);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268 p = param({'CPSD', 'The one sided cross-psd of the white noise between input ports.'}, []);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271 p = param({'aos', 'An array of input AOs, The power spectrum of this noise between input ports for the <i>time-continuous</i> noise model.'}, ao.initObjectWithSize(1,0));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 p = param({'PZmodels', 'An array of input pzmodels for noise filtering'}, paramValue.DOUBLE_VALUE(zeros(0,1)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277 p = param({'reorganize', 'When set to 0, this means the ssm does not need be modified to match the requested i/o. Faster but dangerous!'}, paramValue.TRUE_FALSE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280 p = param({'f2', 'The maximum frequency. Default is Nyquist or 1Hz.'}, paramValue.EMPTY_DOUBLE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 p = param({'f1', 'The minimum frequency. Default is f2*1e-5.'}, paramValue.EMPTY_DOUBLE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
284 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
285
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
286 p = param({'nf', 'The number of frequency bins. Frequencies are scale logarithmically'}, paramValue.DOUBLE_VALUE(200));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
287 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
288
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
289 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
290
|