-
Notifications
You must be signed in to change notification settings - Fork 27
/
amp_spec_scaling.m
378 lines (361 loc) · 12.8 KB
/
amp_spec_scaling.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
function amp_spec_scaling
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% amp_spec_scalling.m
%
% adjust plotting parameters - auto or manual values. Also save the current
% values to a txt file or load them from a text file
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global PARAMS HANDLES
%prompt user, open to design changes, just a place holder until then.
button = questdlg('Would you like to change, load or save the current amplitude and spectra levels?', ...
'Amp+Levels', 'Change', 'Load', 'Save', 'Change');
switch button
case 'Change'
build_gui;
case 'Load'
%prompt user for file location
[ fileName, path ] = uigetfile( '.txt' );
if fileName == 0
return; %user hit cancel or the file wasn't found
end
fid = fopen( [ path fileName ] );
if fid == -1
fprintf( 'Matlab counldn''t open %s', fileName );
return;
end
%loop through param file and evaluate the expression
while ~feof( fid )
evalc( fgetl( fid ) );
end
fclose( fid );
%redraw
plot_triton
case 'Save'
%prompt for where user wants to save then gets the fullpath
[ saveFile, savePath ] = uiputfile( '.txt' );
if saveFile == 0
return;%user canceled save.
end
%get the path for fopen
fullPath = fullfile( savePath, saveFile );
%create new file. If file already existed, + flag deletes it
fid = fopen( fullPath, 'w+' );
%write to text file
fprintf( fid, 'PARAMS.auto = 0\n' );%assume no auto scalling if user is saving it
fprintf( fid, 'PARAMS.ts.max = %d\n', PARAMS.ts.max );
fprintf( fid,'PARAMS.ts.min = %d\n', PARAMS.ts.min );
fprintf( fid, 'PARAMS.sp.max = %d\n', PARAMS.sp.max );
fprintf( fid, 'PARAMS.sp.min = %d\n', PARAMS.sp.min );
%open files = badtime.
fclose( fid );
end
function amp_callback( ~, ev)
% Call back for radio button. Sets the editable text boxes to be
% editable or not based on what the radio button is set at
enable = get( ev.NewValue, 'String' );
set( HANDLES.amp.edmin, 'Enable', enable );
set( HANDLES.amp.edmax, 'Enable', enable );
if strcmp( enable, 'On' )
PARAMS.auto.amp = 0; %reverse logic, if manual scalling is on, auto is off
amp_switch([],[]);
else
PARAMS.auto.amp = 1;
plot_triton;
figure( HANDLES.fig.plot )
end
end
function amp_switch(~,~)
[newmax,status1] = str2num( get( HANDLES.amp.edmax, 'String' ) );
[newmin,status2] = str2num( get( HANDLES.amp.edmin, 'String' ) );
if ~status1 || ~status2
disp_msg( 'Counts must be a number' );
set( HANDLES.amp.edmax, 'String', PARAMS.ts.max )
set( HANDLES.amp.edmin, 'String', PARAMS.ts.min )
elseif newmax <= newmin
disp_msg( 'Minimum aplitude can''t be larger than the max, old values will be used' );
set( HANDLES.amp.edmax, 'String', PARAMS.ts.max )
set( HANDLES.amp.edmin, 'String', PARAMS.ts.min )
else
PARAMS.ts.max = newmax;
PARAMS.ts.min = newmin;
plot_triton;
figure( HANDLES.fig.plot )
end
end
function spl_callback( ~, ev )
% Call back for radio button. Sets the editable text boxes to be
% editable or not based on what the radio button is set at
enable = get( ev.NewValue, 'String' );
set( HANDLES.spl.edmin, 'Enable', enable );
set( HANDLES.spl.edmax, 'Enable', enable );
if strcmp( enable, 'On' )
PARAMS.auto.spl = 0; %reverse logic, if manual scalling is on, auto is off
sp_switch([],[]);
else
PARAMS.auto.spl = 1;
plot_triton;
figure( HANDLES.fig.plot )
end
end
function sp_switch(~,~)
[newmax,status1] = str2num( get( HANDLES.spl.edmax, 'String' ) );
[newmin,status2] = str2num( get( HANDLES.spl.edmin, 'String' ) );
if ~status1 || ~status2
disp_msg( 'Spetra levels must be a number' );
set( HANDLES.spl.edmax, 'String', PARAMS.sp.max )
set( HANDLES.spl.edmin, 'String', PARAMS.sp.min )
elseif newmax <= newmin
disp_msg( 'Minimum aplitude can''t be larger than the max, old values will be used' );
set( HANDLES.spl.edmax, 'String', PARAMS.sp.max )
set( HANDLES.spl.edmin, 'String', PARAMS.sp.min )
else
PARAMS.sp.max = newmax;
PARAMS.sp.min = newmin;
plot_triton;
figure( HANDLES.fig.plot )
end
end
function close( ~, ~ )
delete( HANDLES.fig.plot ); %only need it while the window is open
end
%builds the window, put down here to improve readability
function build_gui
%build window
bgColor = [1 1 1]; %white
bgColor2 = [.75 .875 1]; % light blue for XWAV
bw = .25; %button width
bh = .25; %button height
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Figure window
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.fig.plot = figure('NumberTitle', 'off',...
'MenuBar', 'none',...
'Name', 'Amp+Levels',...
'Units', 'normalized',...
'Visible', 'on',...
'Position', [0.45,0.325,0.15,0.12],...
'Color', bgColor2,...
'CloseRequestFcn', @close); %custom close function to hide function not destroy it
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Panel for buttons,allows for a border around the edge
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.fig.panel = uipanel(HANDLES.fig.plot,...
'Units', 'normalized',...
'Visible', 'on',...
'Position', [0 0.03 1 .94],...
'BorderType', 'none',...
'BackgroundColor', bgColor2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Amp label text
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.amp.txt = uicontrol(HANDLES.fig.panel,...
'Style','text',...
'Units','normalized',...
'Position',[0 .25 bw bh],...
'BackgroundColor',bgColor2,...
'String','Amplitude',...
'FontUnits','normalized', ...
'Visible','on');
%***********************************
% Min amp text
%***********************************
HANDLES.amp.lowtxt = uicontrol(HANDLES.fig.panel,...
'Style','text',...
'Units','normalized',...
'Position',[.25 .25 bw bh],...
'BackgroundColor',bgColor2,...
'String','Enter Min [counts]',...
'FontUnits','normalized', ...
'Visible','on');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Min amp edit box
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.amp.edmin = uicontrol(HANDLES.fig.panel,...
'Style','edit',...
'Units','normalized',...
'Position',[ .25 0 bw bh],...
'BackgroundColor',bgColor,...
'String',num2str(PARAMS.ts.min),...
'FontUnits','normalized', ...
'Visible','on',...
'Callback', @amp_switch);
%***********************************
% Max amp text
%***********************************
HANDLES.amp.txthigh = uicontrol(HANDLES.fig.panel,...
'Style','text',...
'Units','normalized',...
'Position',[.5 .25 bw bh],...
'BackgroundColor',bgColor2,...
'String','Enter Max [counts]',...
'FontUnits','normalized', ...
'Visible','on');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Max amp edit box
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.amp.edmax = uicontrol(HANDLES.fig.panel,...
'Style','edit',...
'Units','normalized',...
'Position',[.5 0 bw bh],...
'BackgroundColor',bgColor,...
'String',num2str(PARAMS.ts.max),...
'FontUnits','normalized', ...
'Visible','on',...
'Callback', @amp_switch);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% amp button group for the radio buttons
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
amp_buttons = uibuttongroup(HANDLES.fig.panel,...
'Position', [.75 0 bw .24],...
'Units', 'normalized',...
'BorderType', 'none',...
'SelectionChangeFcn', @amp_callback);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Scalling text
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.amp.Scalling = uicontrol(HANDLES.fig.panel,...
'Style','text',...
'Units','normalized',...
'Position',[.75 .75 bw bh],...
'BackgroundColor',bgColor2,...
'String','Manual Scalling',...
'FontUnits','normalized', ...
'Visible','on');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Toggle manual amp scalling on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.amp.on = uicontrol(amp_buttons,...
'Style','radiobutton',...
'Units','normalized',...
'Position',[0 .5 1 .5],...
'BackgroundColor',bgColor2,...
'String','On',...
'FontUnits','normalized', ...
'Visible','on',...
'Value',0);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Toggle manual amp scalling off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.amp.off = uicontrol(amp_buttons,...
'Style','radiobutton',...
'Units','normalized',...
'Position',[0 0 1 .5],...
'BackgroundColor',bgColor2,...
'String','Off',...
'FontUnits','normalized', ...
'Visible','on',...
'Value',1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Spectrogram levels label
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.spl.txt = uicontrol(HANDLES.fig.panel,...
'Style','text',...
'Units','normalized',...
'Position',[0 .75 bw bh],...
'BackgroundColor',bgColor2,...
'String','SPL',...
'FontUnits','normalized', ...
'Visible','on');
%***********************************
% plot Low Text
%***********************************
HANDLES.spl.txtlow = uicontrol(HANDLES.fig.panel,...
'Style','text',...
'Units','normalized',...
'Position',[.25 .75 bw bh],...
'BackgroundColor',bgColor2,...
'String','Min SPL [dB]',...
'FontUnits','normalized', ...
'Visible','on');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Low end of plot Filter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.spl.edmin = uicontrol(HANDLES.fig.panel,...
'Style','edit',...
'Units','normalized',...
'Position',[ .25 .5 bw bh],...
'BackgroundColor',bgColor,...
'String',num2str(PARAMS.sp.min),...
'FontUnits','normalized', ...
'Visible','on',...
'Callback', @sp_switch );
%***********************************
% plot High Text
%***********************************
HANDLES.spl.txthigh = uicontrol(HANDLES.fig.panel,...
'Style','text',...
'Units','normalized',...
'Position',[.5 .75 bw bh],...
'BackgroundColor',bgColor2,...
'String','Max SPL [dB]',...
'FontUnits','normalized', ...
'Visible','on');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% High end of plot Filter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.spl.edmax = uicontrol(HANDLES.fig.panel,...
'Style','edit',...
'Units','normalized',...
'Position',[.5 .5 bw bh],...
'BackgroundColor',bgColor,...
'String',num2str(PARAMS.sp.max),...
'FontUnits','normalized', ...
'Visible','on',...
'Callback', @sp_switch );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Spectra Levels botton group for radio buttons
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
spl_buttons = uibuttongroup(HANDLES.fig.panel,...
'Position', [.75 .5 bw .24],...
'Units', 'normalized',...
'BorderType', 'none',...'
'SelectionChangeFcn', {@spl_callback});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot Filter toggle ON
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.spl.on = uicontrol(spl_buttons,...
'Style','radiobutton',...
'Units','normalized',...
'Position',[0 .5 1 .5],...
'BackgroundColor',bgColor2,...
'String','On',...
'FontUnits','normalized', ...
'Visible','on',...
'Value',0);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot Filter toggle OFF
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HANDLES.spl.off = uicontrol(spl_buttons,...
'Style','radiobutton',...
'Units','normalized',...
'Position',[0 0 1 .5],...
'BackgroundColor',bgColor2,...
'String','Off',...
'FontUnits','normalized', ...
'Visible','on',...
'Value',1);
%additional logic to determine which radio button should be set.
if( PARAMS.auto.spl == 0 )%auto scalling is off
set( HANDLES.spl.on, 'Value',1 );
enable = 'On';
else
set( HANDLES.spl.off, 'Value',1 );
enable = 'Off';
end
%Set the text to editable
set( HANDLES.spl.edmin, 'Enable', enable );
set( HANDLES.spl.edmax, 'Enable', enable );
if( PARAMS.auto.amp == 0 )%auto scalling is off
set( HANDLES.amp.on, 'Value', 1 );
enable = 'On';
else
set( HANDLES.amp.off, 'Value', 1 );
enable = 'Off';
end
%Set the text to editable
set( HANDLES.amp.edmin, 'Enable', enable );
set( HANDLES.amp.edmax, 'Enable', enable );
end
end