-
Notifications
You must be signed in to change notification settings - Fork 0
/
smac_synth_frf.m
386 lines (306 loc) · 11 KB
/
smac_synth_frf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
function h=smac_synth_frf(h,frfsyn,frfexp,rootlist,freqrange,mode,haveresiduals)
% SMAC_SYNTH_FRF Synthesize FRF and plot against experimental data
%
% H=SMAC_SYNTH_FRF(H,FRFSYN,FRFEXP,ROOTLIST,FREQRANGE,XL,MODE,HAVERESIDUALS)
%
% SMAC_SYNTH_FRF will overlay the FRF from the supplied analytical curve-
% fit FRF in the imat_fn FRFSYN and the experimental data in the imat_fn
% FRFEXP. H is a figure handle for the previous FRF plot. If the handle
% exists and is valid, SMAC_SYNTH_FRF will delete the figure, create the
% new one, and set the figure position to the old one. Otherwise it will
% simply create a new figure. ROOTLIST is an Nx2 vector. Column 1 contains
% the root numbers, and column 2 contains the root frequencies of all of the
% roots used to synthesize the FRF. XL is a 1x2 vector containing the X axis
% range over which to display the FRF. MODE specifies whether the fit is
% real or complex (1=real, 2=complex). HAVERESIDUALS is a logical that
% specifies whether residual terms are included in the analytical FRF. If
% MODE specifies real, the imaginary portion of the FRF will be the default
% view on the plot. If residual terms are included, both the real and
% imaginary portions of the FRF will be displayed. If complex, the modulus
% and phase are displayed.
%
% H is the imat_fnplot handle of the created figure.
%==========================================================================
%
% ********************************************************************
% *** Copyright (C) 2008 Sandia Corporation. ***
% *** ***
% *** Under the terms of Contract DE-AC04-94AL85000 with Sandia ***
% *** Corporation, the U.S. Government retains certain rights in ***
% *** this software. ***
% ********************************************************************
%
% The contents of this file are subject to the Mozilla Public License
% Version 1.1 (the "License"); you may not use this file except in
% compliance with the License. You may obtain a copy of the License at
%
% http://www.mozilla.org/MPL/
%
% Software distributed under the License is distributed on an "AS IS"
% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
% License for the specific language governing rights and limitations under
% the License.
%
% The Original Code is SMAC.
%
% The Initial Developer of the Original Code is Randy Mayes.
% All Rights Reserved.
%
% Contributor(s): Dan Hensley / ATA Engineering.
%==========================================================================
% HISTORY
% 13-May-2004 / ATA Engineering / Dan Hensley
% o Initial release
%
% 15-Oct-2004 / ATA Engineering / Dan Hensley
% o Put filename in figure title
%
% 02-Nov-2004 / ATA Engineering / Dan Hensley
% o Make sure title appears above uppermost graph
%
% 17-Feb-2005 / ATA Engineering / Dan Hensley
% o Fix bug where experimental and analytical plots got swapped after
% hitting Prev or Next
%
% 15-Jun-2005 / ATA Engineering / Dan Hensley
% o Only display the roots on the plot if they were supplied
%
% 27-Jul-2005 / ATA Engineering / Dan Hensley
% o When uiselecting FRF, preselect the currently displayed FRF
%
% 10-Aug-2005 / ATA Engineering / Dan Hensley
% o When fitting real modes with residual terms, plot both real and
% imaginary of FRF
%
% 11-Sep-2006 / ATA Engineering / Dan Hensley
% o Update to use IMAT v2.0 new plot handling capabilities
%
%==========================================================================
% Argument checking
narginchk(7,7);
if ~isa(frfsyn,'imat_fn');
error('Synthesized FRF input must be an imat_fn');
end
if ~isa(frfexp,'imat_fn');
error('Experimental FRF input must be an imat_fn');
end
if ~isempty(freqrange) && (~isnumeric(freqrange) || numel(freqrange)~=2),
error('Frequency range must be a 1x2 numeric vector');
end
freqrange=sort(freqrange);
%--------------------------------------------------------------------------
% Build the plot
% If the figure exists, remember the old position and delete the figure
pos=[];
if ~isempty(h) && ishandle(h.hf),
set(h.hf,'Units','normalized');
pos=get(h.hf,'Position');
delete(h.hf);
end
% Build the plot
ind=1;
% Build the root list plot
fa=frfsyn(ind).abscissa;
indr=zeros(size(rootlist,1),1);
tt=cell(size(indr));
for k=1:length(indr),
[~,indr(k)]=min(abs(fa-rootlist(k,2)));
tt{k}=sprintf('%d',rootlist(k,1));
end
% Set the frequency range if it's empty
if isempty(freqrange)
freqrange=fa([1 end]);
end
if ~isempty(rootlist)
froot=frfsyn(ind);
froot.responsecoord='1root';
froot.abscissa=rootlist(:,2);
froot.ordinate=frfsyn(ind).ordinate(indr);
else
froot=imat_fn([]);
end
% Get the default display type depending on type of fit
if mode==1,
ctype='i'; % Imaginary for real normal modes with no residual terms
if haveresiduals
ctype='ri'; % Real and imaginary if residual terms are included
end
yscale={'yscale' 'lin'};
else
ctype='m'; % Magnitude for complex modes
yscale={};
end
h=plot(frfexp(ind),frfsyn(ind),froot,'xwin',freqrange,'complex',ctype,yscale{:});
% Put FRF data, current plot into appdata
setappdata(h.hf,'FRF_Synthesized',frfsyn);
setappdata(h.hf,'FRF_Experimental',frfexp);
setappdata(h.hf,'FRF_Index',ind);
setappdata(h.hf,'FRF_Roots',froot);
setappdata(h.hf,'FRF_Roots_Ind',indr);
setappdata(h.hf,'FRF_Roots_Text',tt);
% Update the root plot format
smac_frf_fig_format_root_plot(h);
% Put buttons and uimenus on
setappdata(h.hf,'Plot',h);
% setappdata(h.hf,'FigPrevHandle',@smac_frf_fig_prev);
% setappdata(h.hf,'FigNextHandle',@smac_frf_fig_next);
% setappdata(h.hf,'FigSelectHandle',@smac_frf_fig_select);
setappdata(h.hf,'FigPlotHandle',@smac_frf_fig_update_plot);
setappdata(h.hf,'FigUpdateHandle',@smac_frf_fig_update_labels);
setappdata(h.hf,'FigFormatRootsHandle',@smac_frf_fig_format_root_plot);
% Add Next and Previous uimenus
uimenu(h.hf, ...
'Label','<<', ...
'Callback',@smac_frf_fig_prev);
uimenu(h.hf, ...
'Label','?', ...
'Callback',@smac_frf_fig_select);
uimenu(h.hf, ...
'Label','>>', ...
'Callback',@smac_frf_fig_next);
% Add Next and Previous buttons
un=get(h.hf,'Units');
uicontrol(double(h.hf), ...
'Units','normalized', ...
'Position',[.01 .01 .05 .05], ...
'String','<<', ...
'TooltipString','Overlay the previous FRF', ...
'Callback',@smac_frf_fig_prev);
uicontrol(double(h.hf), ...
'Units','normalized', ...
'Position',[.07 .01 .05 .05], ...
'String','?', ...
'TooltipString','Select the FRF to display from the list', ...
'Callback',@smac_frf_fig_select);
uicontrol(double(h.hf), ...
'Units','normalized', ...
'Position',[.13 .01 .05 .05], ...
'String','>>', ...
'TooltipString','Overlay the next FRF', ...
'Callback',@smac_frf_fig_next);
set(h.hf,'Units',un);
% Put on display information
smac_frf_fig_update_labels(h);
% Remember the position of the old figure if necessary
if ~isempty(pos),
set(h.hf,'Units','normalized','Position',pos);
else
set(h.hf,'Units','Normalized', ...
'Position',[0.01 0.52 0.45 0.43]);
end
%==========================================================================
%% _____ CALLBACKS ________________________________________________________
%==========================================================================
%% smac_frf_fig_prev
function smac_frf_fig_prev(varargin)
h = getappdata(gcbf,'Plot');
hf = h.hf;
frf=getappdata(hf,'FRF_Synthesized');
ind=getappdata(hf,'FRF_Index');
% Decrement the index by 1
ind=ind-1;
if ind<1,
ind=prod(size(frf));
end
setappdata(hf,'FRF_Index',ind);
% Update the plot and labels
feval(getappdata(hf,'FigPlotHandle'),h);
feval(getappdata(hf,'FigUpdateHandle'),h);
%--------------------------------------------------------------------------
%% smac_frf_fig_next
function smac_frf_fig_next(varargin)
h = getappdata(gcbf,'Plot');
hf = h.hf;
frf=getappdata(hf,'FRF_Synthesized');
ind=getappdata(hf,'FRF_Index');
% Increment the index by 1
ind=ind+1;
if ind>prod(size(frf)),
ind=1;
end
setappdata(hf,'FRF_Index',ind);
% Update the plot and labels
feval(getappdata(hf,'FigPlotHandle'),h);
feval(getappdata(hf,'FigUpdateHandle'),h);
%--------------------------------------------------------------------------
%% smac_frf_fig_select
function smac_frf_fig_select(varargin)
h = getappdata(gcbf,'Plot');
hf = h.hf;
frf=getappdata(hf,'FRF_Synthesized');
% Prompt user
ind=getappdata(hf,'FRF_Index');
notdone=true;
while notdone,
[f,ind]=uiselect(frf,ind);
if isempty(ind), return; end
notdone=false;
if length(ind)>1,
uiwait(errordlg('You may only select one from the list'));
notdone=true;
ind=ind(1);
end
end
% Store the selected index
setappdata(hf,'FRF_Index',ind);
% Update the plot and labels
feval(getappdata(hf,'FigPlotHandle'),h);
feval(getappdata(hf,'FigUpdateHandle'),h);
%--------------------------------------------------------------------------
%% smac_frf_fig_update_labels
function smac_frf_fig_update_labels(h)
% Update the title and legend
frf=getappdata(h.hf,'FRF_Synthesized');
ind=getappdata(h.hf,'FRF_Index');
refc = frf(ind).referencecoord;
if ~iscell(refc), refc = {refc}; end
resc = frf(ind).responsecoord;
if ~iscell(resc), resc = {resc}; end
id1 = frf(ind).idline1;
if ~iscell(id1), id1 = {id1}; end
h.title(sprintf('%d: (%s,%s) "%s"',ind,refc{:},resc{:},id1{:}),'interpreter','none');
h.legend('Experimental Data','Analytical Fit',0)
h.xlabel('Frequency (Hz)');
%--------------------------------------------------------------------------
%% smac_frf_fig_update_plot
function smac_frf_fig_update_plot(h)
% Update the plot
frfsyn=getappdata(h.hf,'FRF_Synthesized');
frfexp=getappdata(h.hf,'FRF_Experimental');
froot=getappdata(h.hf,'FRF_Roots');
indr=getappdata(h.hf,'FRF_Roots_Ind');
ind=getappdata(h.hf,'FRF_Index');
% Update the root plot information
if ~isempty(froot)
froot.ordinate=frfsyn(ind).ordinate(indr);
end
setappdata(h.hf,'FRF_Roots',froot);
% Replace the functions on the plot
h.replace([frfexp(ind); frfsyn(ind); froot]);
feval(getappdata(h.hf,'FigFormatRootsHandle'),h);
%--------------------------------------------------------------------------
%% smac_frf_fig_format_root_plot
function smac_frf_fig_format_root_plot(h)
% Update the plot
global ss;
if length(h.f) > 2
h.style('Marker','*','LineStyle','none',3)
end
fname='';
if ~isempty(ss.filename), fname=[' (' ss.filename ')']; end
set(h.hf,'Name',['FRF' fname]);
% Draw the root number text--figure out the Y values from the plot
tt=getappdata(h.hf,'FRF_Roots_Text');
froot=getappdata(h.hf,'FRF_Roots');
ht=getappdata(h.hf,'HandleRootText');
if ~isempty(froot)
% ha = get(h.hf,'CurrentAxes');
% my=max(abs(diff(get(ha,'YLim'))));
% if strcmpi(get(ha,'YScale'),'log'), my=log10(my); end
fo=h.f(end).ordinate;
fo=fo(1:length(tt));
fo=fo+0.2*abs(fo);
delete(ht(ishandle(ht)));
ht = text(froot.abscissa,fo,tt);
setappdata(h.hf,'HandleRootText',ht);
end