comparison Code/Descriptors/Matlab/MPEG7/FromWeb/VoiceSauce/vs_ParameterEstimation.m @ 4:92ca03a8fa99 tip

Update to ICASSP 2013 benchmark
author Dawn Black
date Wed, 13 Feb 2013 11:02:39 +0000
parents
children
comparison
equal deleted inserted replaced
3:e1cfa7765647 4:92ca03a8fa99
1 function varargout = vs_ParameterEstimation(varargin)
2 % VS_PARAMETERESTIMATION M-file for vs_ParameterEstimation.fig
3 % VS_PARAMETERESTIMATION, by itself, creates a new VS_PARAMETERESTIMATION or raises the existing
4 % singleton*.
5 %
6 % H = VS_PARAMETERESTIMATION returns the handle to a new VS_PARAMETERESTIMATION or the handle to
7 % the existing singleton*.
8 %
9 % VS_PARAMETERESTIMATION('CALLBACK',hObject,eventData,handles,...) calls the local
10 % function named CALLBACK in VS_PARAMETERESTIMATION.M with the given input arguments.
11 %
12 % VS_PARAMETERESTIMATION('Property','Value',...) creates a new VS_PARAMETERESTIMATION or raises the
13 % existing singleton*. Starting from the left, property value pairs are
14 % applied to the GUI before vs_ParameterEstimation_OpeningFcn gets called. An
15 % unrecognized property name or invalid value makes property application
16 % stop. All inputs are passed to vs_ParameterEstimation_OpeningFcn via varargin.
17 %
18 % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
19 % instance to run (singleton)".
20 %
21 % See also: GUIDE, GUIDATA, GUIHANDLES
22
23 % Edit the above text to modify the response to help vs_ParameterEstimation
24
25 % Last Modified by GUIDE v2.5 19-Oct-2009 11:55:41
26
27 % Begin initialization code - DO NOT EDIT
28 gui_Singleton = 1;
29 gui_State = struct('gui_Name', mfilename, ...
30 'gui_Singleton', gui_Singleton, ...
31 'gui_OpeningFcn', @vs_ParameterEstimation_OpeningFcn, ...
32 'gui_OutputFcn', @vs_ParameterEstimation_OutputFcn, ...
33 'gui_LayoutFcn', [] , ...
34 'gui_Callback', []);
35 if nargin && ischar(varargin{1})
36 gui_State.gui_Callback = str2func(varargin{1});
37 end
38
39 if nargout
40 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41 else
42 gui_mainfcn(gui_State, varargin{:});
43 end
44 % End initialization code - DO NOT EDIT
45
46
47 % --- Executes just before vs_ParameterEstimation is made visible.
48 function vs_ParameterEstimation_OpeningFcn(hObject, eventdata, handles, varargin)
49 % This function has no output args, see OutputFcn.
50 % hObject handle to figure
51 % eventdata reserved - to be defined in a future version of MATLAB
52 % handles structure with handles and user data (see GUIDATA)
53 % varargin command line arguments to vs_ParameterEstimation (see VARARGIN)
54
55 % Choose default command line output for vs_ParameterEstimation
56 handles.output = hObject;
57
58 % YS: get the settings from the main figure
59 if (~isfield(handles, 'VSHandle'))
60 VSHandle = VoiceSauce;
61 handles.VSHandle = VSHandle;
62 end
63
64 % set up the text fields with default values
65 setGUIVariables(handles);
66
67 set(handles.listbox_filelist, 'KeyPressFcn', @filelist_listbox_KeyPressFcn);
68
69 % Update handles structure
70 guidata(hObject, handles);
71
72 % UIWAIT makes vs_ParameterEstimation wait for user response (see UIRESUME)
73 % uiwait(handles.figure_ParameterEstimation);
74
75
76 function setGUIVariables(handles)
77 VSData = guidata(handles.VSHandle);
78
79 set(handles.edit_inputdirectory, 'String', VSData.vars.wavdir);
80 set(handles.edit_outputdirectory, 'String', VSData.vars.matdir);
81
82 set(handles.checkbox_savematwithwav, 'Value', VSData.vars.PE_savematwithwav);
83 set(handles.checkbox_process16khz, 'Value', VSData.vars.PE_processwith16k);
84 set(handles.checkbox_useTextgrid, 'Value', VSData.vars.PE_useTextgrid);
85 set(handles.checkbox_showwaveform, 'Value', VSData.vars.PE_showwaveforms); % turn this off at startup
86
87
88 if (VSData.vars.recursedir)
89 func_setlistbox(handles.listbox_filelist, VSData.vars.wavdir, 'recurse', VSData.vars, VSData.vars.I_searchstring);
90 else
91 func_setlistbox(handles.listbox_filelist, VSData.vars.wavdir, 'none', VSData.vars, VSData.vars.I_searchstring);
92 end
93
94 if (VSData.vars.PE_savematwithwav == 1)
95 set(handles.edit_outputdirectory, 'Enable', 'Off');
96 set(handles.pushbutton_outputBrowse, 'Enable', 'Off');
97 else
98 set(handles.edit_outputdirectory, 'Enable', 'On');
99 set(handles.pushbutton_outputBrowse, 'Enable', 'On');
100 end
101
102 if (length(VSData.vars.PE_params) == 0)
103 set(handles.edit_parameterselection, 'String', 'None');
104 elseif (length(VSData.vars.PE_params) == length(func_getparameterlist()))
105 set(handles.edit_parameterselection, 'String', 'All');
106 else
107 set(handles.edit_parameterselection, 'String', 'Custom');
108 end
109
110
111
112 function filelist_listbox_KeyPressFcn(hObject, eventdata)
113 handles = guidata(hObject);
114
115 key = double(get(gcbf, 'CurrentCharacter'));
116 if (gcbo == handles.listbox_filelist)
117 if (key == 127) % delete key
118
119 inx = get(handles.listbox_filelist, 'Value');
120 contents = get(handles.listbox_filelist, 'String');
121
122 %nothing to do
123 if (isempty(contents))
124 return;
125 end
126
127 newinx = setxor(inx, [1:length(contents)]);
128
129 newcontents = contents(newinx);
130 set(handles.listbox_filelist, 'String', newcontents);
131
132 if (inx(end) > length(newcontents))
133 set(handles.listbox_filelist, 'Value', length(newcontents));
134 else
135 set(handles.listbox_filelist, 'Value', inx(end));
136 end
137 end
138 end
139
140
141
142 % --- Outputs from this function are returned to the command line.
143 function varargout = vs_ParameterEstimation_OutputFcn(hObject, eventdata, handles)
144 % varargout cell array for returning output args (see VARARGOUT);
145 % hObject handle to figure
146 % eventdata reserved - to be defined in a future version of MATLAB
147 % handles structure with handles and user data (see GUIDATA)
148
149 % Get default command line output from handles structure
150 varargout{1} = handles.output;
151
152
153 % --- Executes on selection change in listbox_filelist.
154 function listbox_filelist_Callback(hObject, eventdata, handles)
155 % hObject handle to listbox_filelist (see GCBO)
156 % eventdata reserved - to be defined in a future version of MATLAB
157 % handles structure with handles and user data (see GUIDATA)
158
159 if (get(handles.checkbox_showwaveform, 'Value') == 1)
160 plotCurrentWav(handles);
161 end
162
163
164 % --- Executes during object creation, after setting all properties.
165 function listbox_filelist_CreateFcn(hObject, eventdata, handles)
166 % hObject handle to listbox_filelist (see GCBO)
167 % eventdata reserved - to be defined in a future version of MATLAB
168 % handles empty - handles not created until after all CreateFcns called
169
170 % Hint: listbox controls usually have a white background on Windows.
171 % See ISPC and COMPUTER.
172 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
173 set(hObject,'BackgroundColor','white');
174 end
175
176
177
178 function edit_inputdirectory_Callback(hObject, eventdata, handles)
179 % hObject handle to edit_inputdirectory (see GCBO)
180 % eventdata reserved - to be defined in a future version of MATLAB
181 % handles structure with handles and user data (see GUIDATA)
182 new_dir = get(handles.edit_inputdirectory, 'String');
183
184 VSData = guidata(handles.VSHandle);
185
186 if (exist(new_dir, 'dir') == 7) % check if new_dir exists
187 VSData.vars.wavdir = new_dir;
188 set(handles.edit_inputdirectory, 'String', new_dir);
189
190 if (get(handles.checkbox_savematwithwav, 'Value') == 1) % change output dir too
191 set(handles.edit_outputdirectory, 'String', new_dir);
192
193 VSData = func_setmatdir('matdir', new_dir, VSData);
194 end
195
196 % update the listbox
197 if (VSData.vars.recursedir == 1)
198 func_setlistbox(handles.listbox_filelist, new_dir, 'recurse', VSData.vars, VSData.vars.I_searchstring);
199 else
200 func_setlistbox(handles.listbox_filelist, new_dir, 'none', VSData.vars, VSData.vars.I_searchstring);
201 end
202
203 VSData = func_setwavdir('wavdir', new_dir, VSData);
204
205 % update the variables
206 guidata(handles.VSHandle, VSData);
207 else
208 msgbox('Error: directory not found.', 'Error', 'error', 'modal');
209 set(hObject, 'String', VSData.vars.wavdir);
210 end
211
212
213 % --- Executes during object creation, after setting all properties.
214 function edit_inputdirectory_CreateFcn(hObject, eventdata, handles)
215 % hObject handle to edit_inputdirectory (see GCBO)
216 % eventdata reserved - to be defined in a future version of MATLAB
217 % handles empty - handles not created until after all CreateFcns called
218
219 % Hint: edit controls usually have a white background on Windows.
220 % See ISPC and COMPUTER.
221 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
222 set(hObject,'BackgroundColor','white');
223 end
224
225
226 % --- Executes on button press in pushbutton_inputBrowse.
227 function pushbutton_inputBrowse_Callback(hObject, eventdata, handles)
228 % hObject handle to pushbutton_inputBrowse (see GCBO)
229 % eventdata reserved - to be defined in a future version of MATLAB
230 % handles structure with handles and user data (see GUIDATA)
231 current_dir = get(handles.edit_inputdirectory, 'String');
232 new_dir = uigetdir(current_dir);
233
234 VSData = guidata(handles.VSHandle);
235
236 if (ischar(new_dir)) % check if a new dir was returned
237 VSData.vars.wavdir = new_dir;
238 set(handles.edit_inputdirectory, 'String', new_dir);
239
240 if (get(handles.checkbox_savematwithwav, 'Value') == 1) % change output dir too
241 set(handles.edit_outputdirectory, 'String', new_dir);
242
243 VSData = func_setmatdir('matdir', new_dir, VSData);
244 end
245
246 % update the listbox
247 if (VSData.vars.recursedir == 1)
248 func_setlistbox(handles.listbox_filelist, new_dir, 'recurse', VSData.vars, VSData.vars.I_searchstring);
249 else
250 func_setlistbox(handles.listbox_filelist, new_dir, 'none', VSData.vars, VSData.vars.I_searchstring);
251 end
252
253 VSData = func_setwavdir('wavdir', new_dir, VSData);
254
255 % update the variables
256 guidata(handles.VSHandle, VSData);
257 end
258
259
260
261 function edit_outputdirectory_Callback(hObject, eventdata, handles)
262 % hObject handle to edit_outputdirectory (see GCBO)
263 % eventdata reserved - to be defined in a future version of MATLAB
264 % handles structure with handles and user data (see GUIDATA)
265
266 VSData = guidata(handles.VSHandle);
267
268 if (strcmp(get(hObject, 'Enable'), 'on'))
269 new_dir = get(handles.edit_outputdirectory, 'String');
270
271 if (exist(new_dir, 'dir') == 7)
272 set(handles.edit_outputdirectory, 'String', new_dir);
273
274 VSData = func_setmatdir('matdir', new_dir, VSData);
275
276 guidata(handles.VSHandle, VSData);
277 else
278 msgbox('Error: Directory not found.', 'Error', 'error', 'modal');
279 set(hObject, 'String', VSData.vars.matdir);
280 end
281 end
282
283 % --- Executes during object creation, after setting all properties.
284 function edit_outputdirectory_CreateFcn(hObject, eventdata, handles)
285 % hObject handle to edit_outputdirectory (see GCBO)
286 % eventdata reserved - to be defined in a future version of MATLAB
287 % handles empty - handles not created until after all CreateFcns called
288
289 % Hint: edit controls usually have a white background on Windows.
290 % See ISPC and COMPUTER.
291 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
292 set(hObject,'BackgroundColor','white');
293 end
294
295
296 % --- Executes on button press in pushbutton_outputBrowse.
297 function pushbutton_outputBrowse_Callback(hObject, eventdata, handles)
298 % hObject handle to pushbutton_outputBrowse (see GCBO)
299 % eventdata reserved - to be defined in a future version of MATLAB
300 % handles structure with handles and user data (see GUIDATA)
301
302 VSData = guidata(handles.VSHandle);
303
304 if (strcmp(get(hObject, 'Enable'), 'on'))
305 curr_dir = get(handles.edit_outputdirectory, 'String');
306 new_dir = uigetdir(curr_dir);
307
308 if (ischar(new_dir))
309 set(handles.edit_outputdirectory, 'String', new_dir);
310
311 VSData = func_setmatdir('matdir', new_dir, VSData);
312
313 guidata(handles.VSHandle, VSData);
314 end
315 end
316
317
318 % --- Executes on button press in checkbox_savematwithwav.
319 function checkbox_savematwithwav_Callback(hObject, eventdata, handles)
320 % hObject handle to checkbox_savematwithwav (see GCBO)
321 % eventdata reserved - to be defined in a future version of MATLAB
322 % handles structure with handles and user data (see GUIDATA)
323
324 VSData = guidata(handles.VSHandle);
325 VSData.vars.PE_savematwithwav = get(hObject, 'Value');
326
327 if (get(hObject, 'Value') == 1) % link input with output directory
328 VSData = func_setmatdir('matdir', VSData.vars.wavdir, VSData);
329
330 set(handles.edit_outputdirectory, 'String', VSData.vars.matdir);
331 set(handles.edit_outputdirectory, 'Enable', 'off');
332 set(handles.pushbutton_outputBrowse, 'Enable', 'off');
333 else
334 %enable user to pick output directory
335 set(handles.edit_outputdirectory, 'Enable', 'on');
336 set(handles.pushbutton_outputBrowse, 'Enable', 'on');
337 end
338
339 guidata(handles.VSHandle, VSData);
340
341
342
343
344
345 % --- Executes on button press in pushbutton_ParameterSelection.
346 function pushbutton_ParameterSelection_Callback(hObject, eventdata, handles)
347 % hObject handle to pushbutton_ParameterSelection (see GCBO)
348 % eventdata reserved - to be defined in a future version of MATLAB
349 % handles structure with handles and user data (see GUIDATA)
350
351 % save the old file list
352 filelist = get(handles.listbox_filelist, 'String');
353 fileinx = get(handles.listbox_filelist, 'Value');
354 vs_SelectParameters();
355 set(handles.listbox_filelist, 'String', filelist, 'Value', fileinx);
356
357
358
359 function edit_parameterselection_Callback(hObject, eventdata, handles)
360 % hObject handle to edit_parameterselection (see GCBO)
361 % eventdata reserved - to be defined in a future version of MATLAB
362 % handles structure with handles and user data (see GUIDATA)
363
364 % Hints: get(hObject,'String') returns contents of edit_parameterselection as text
365 % str2double(get(hObject,'String')) returns contents of edit_parameterselection as a double
366
367
368 % --- Executes during object creation, after setting all properties.
369 function edit_parameterselection_CreateFcn(hObject, eventdata, handles)
370 % hObject handle to edit_parameterselection (see GCBO)
371 % eventdata reserved - to be defined in a future version of MATLAB
372 % handles empty - handles not created until after all CreateFcns called
373
374 % Hint: edit controls usually have a white background on Windows.
375 % See ISPC and COMPUTER.
376 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
377 set(hObject,'BackgroundColor','white');
378 end
379
380
381 % --- Executes on button press in checkbox_process16khz.
382 function checkbox_process16khz_Callback(hObject, eventdata, handles)
383 % hObject handle to checkbox_process16khz (see GCBO)
384 % eventdata reserved - to be defined in a future version of MATLAB
385 % handles structure with handles and user data (see GUIDATA)
386
387 VSData = guidata(handles.VSHandle);
388 VSData.vars.PE_processwith16k = get(hObject, 'Value');
389 guidata(handles.VSHandle, VSData);
390
391
392 % --- Executes on button press in checkbox_useTextgrid.
393 function checkbox_useTextgrid_Callback(hObject, eventdata, handles)
394 % hObject handle to checkbox_useTextgrid (see GCBO)
395 % eventdata reserved - to be defined in a future version of MATLAB
396 % handles structure with handles and user data (see GUIDATA)
397 VSData = guidata(handles.VSHandle);
398 VSData.vars.PE_useTextgrid = get(hObject, 'Value');
399 guidata(handles.VSHandle, VSData);
400
401
402 % --- Executes on button press in checkbox_showwaveform.
403 function checkbox_showwaveform_Callback(hObject, eventdata, handles)
404 % hObject handle to checkbox_showwaveform (see GCBO)
405 % eventdata reserved - to be defined in a future version of MATLAB
406 % handles structure with handles and user data (see GUIDATA)
407 VSData = guidata(handles.VSHandle);
408 VSData.vars.PE_showwaveforms = get(hObject, 'Value');
409 guidata(handles.VSHandle, VSData);
410
411 if (get(hObject, 'Value') == 1)
412 SWfig = vs_ShowWaveform;
413 SWhandle = guidata(SWfig);
414
415 handles.SWfig = SWfig;
416 handles.SWhandle = SWhandle;
417 guidata(hObject, handles);
418
419 plotCurrentWav(handles);
420 else
421 if (isfield(handles, 'SWfig'))
422 delete(handles.SWfig);
423 handles = rmfield(handles, 'SWfig');
424 guidata(hObject, handles);
425 end
426 end
427
428
429 % --- plots the current wavfile into handles.SWhandle.axes_main
430 function plotCurrentWav(handles)
431 % get the present file selected
432 VSData = guidata(handles.VSHandle);
433
434 contents = get(handles.listbox_filelist, 'String');
435 if (isempty(contents))
436 return; % do nothing
437 end
438 inx = get(handles.listbox_filelist, 'Value');
439 filename = contents{inx};
440 directory = get(handles.edit_inputdirectory, 'String');
441 wavfile = [directory VSData.vars.dirdelimiter filename];
442
443 [y,Fs] = wavread(wavfile);
444 t = linspace(0,length(y)/Fs*1000, length(y));
445 plot(handles.SWhandle.axes_main, t, y);
446 ylabel(handles.SWhandle.axes_main, 'Amplitude');
447 xlabel(handles.SWhandle.axes_main, 'Time (ms)');
448 axis(handles.SWhandle.axes_main, 'tight');
449 set(handles.SWhandle.figure_ShowWaveform, 'Name', filename);
450
451
452 % --- Executes on button press in togglebutton_start.
453 function togglebutton_start_Callback(hObject, eventdata, handles)
454 % hObject handle to togglebutton_start (see GCBO)
455 % eventdata reserved - to be defined in a future version of MATLAB
456 % handles structure with handles and user data (see GUIDATA)
457
458 if (get(hObject, 'Value') == 1) % start the process
459 set(hObject, 'String', 'Processing...', 'ForegroundColor', 'red');
460
461 BatchProcess(handles);
462 set(hObject, 'String', 'Start!', 'ForegroundColor', 'black', 'Value', 0);
463
464 end
465
466
467
468 % this is the main parameter estimation function
469 function BatchProcess(handles)
470 VSData = guidata(handles.VSHandle);
471 filelist = get(handles.listbox_filelist, 'String');
472 paramlist = VSData.vars.PE_params;
473
474 if (isempty(filelist))
475 msgbox('No input files.', 'Error', 'warn', 'modal');
476 return;
477 end
478
479 if (isempty(paramlist))
480 msgbox('No parameters selected.', 'Error', 'warn', 'modal');
481 return;
482 end
483
484 MBox = MessageBox;
485 MBoxHandles = guidata(MBox);
486
487 messages = cell(length(filelist)+1, 1); % allocate some memory for messages
488
489 % get the variables from settings
490 windowsize = VSData.vars.windowsize;
491 frameshift = VSData.vars.frameshift;
492 preemphasis = VSData.vars.preemphasis;
493 F0algorithm = VSData.vars.F0algorithm;
494 FMTalgorithm = VSData.vars.FMTalgorithm;
495 maxF0 = VSData.vars.maxF0;
496 minF0 = VSData.vars.minF0;
497 frame_precision = VSData.vars.frame_precision; % used for Praat f0/formant
498 % estimation, SHR algorithm
499 % to set precision for time
500 % alignment of data
501 % vectors, in terms of frames
502
503 inputdir = get(handles.edit_inputdirectory, 'String');
504 outputdir = get(handles.edit_outputdirectory, 'String');
505
506 % start the processing of each file
507 for k=1:length(filelist)
508 % check if 'stop' button has been pressed
509 if (~ishandle(MBoxHandles.figure_MessageBox) || get(MBoxHandles.figure_MessageBox, 'UserData') == 1)
510 messages{k} = 'Stop button pressed by user.';
511 if (ishandle(MBoxHandles.figure_MessageBox))
512 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
513 end
514 return;
515 end
516
517 messages{k} = sprintf('%d/%d. %s: ', k, length(filelist), filelist{k});
518 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
519 set(handles.listbox_filelist, 'Value', k);
520 drawnow;
521
522 wavfile = [inputdir VSData.vars.dirdelimiter filelist{k}];
523 matfile = [outputdir VSData.vars.dirdelimiter filelist{k}(1:end-3) 'mat'];
524 textgridfile = [wavfile(1:end-3) 'Textgrid'];
525
526 % strip down the matfile and check if the directory exists
527 mdir = fileparts(matfile);
528 if (exist(mdir, 'dir') ~= 7)
529 mkdir(mdir);
530 end
531
532 % check if we are showing the waveforms
533 if (get(handles.checkbox_showwaveform, 'Value') == 1)
534 plotCurrentWav(handles);
535 end
536
537 % check to see if we're using textgrids
538 useTextgrid = get(handles.checkbox_useTextgrid, 'Value');
539 if (useTextgrid == 1)
540 if (exist(textgridfile, 'file') == 0)
541 useTextgrid = 0;
542 end
543 end
544
545 % read in the wav file
546 [y, Fs, nbits] = wavread(wavfile);
547
548 if (size(y, 2) > 1)
549 messages{k} = [messages{k} ' Multi-channel wav file - using first channel only: '];
550 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
551 drawnow;
552 y = y(:,1);
553 end
554
555 % see if we need to resample to 16 kHz (faster for Straight)
556 resampled = 0;
557 if (get(handles.checkbox_process16khz, 'Value') == 1)
558 if (Fs ~= 16000)
559 y = resample(y, 16000, Fs);
560 wavfile = generateRandomFile(wavfile, handles);
561 wavfile = [wavfile(1:end-4) '_16kHz.wav'];
562 warning off; % stop clipping messages
563 wavwrite(y, 16000, nbits, wavfile);
564 warning on;
565 resampled = 1;
566 end
567 [y, Fs] = wavread(wavfile); % reread the resampled file
568 end
569
570 % calculate the length of data vectors - all measures will have this
571 % length - important!!
572 data_len = floor(length(y) / Fs * 1000 / frameshift);
573
574 % parse the parameter list to get proper ordering
575 paramlist = func_parseParameters(paramlist, handles, matfile, data_len);
576
577 for n=1:length(paramlist)
578
579 % check if 'stop' button has been pressed
580 if (~ishandle(MBoxHandles.figure_MessageBox) || get(MBoxHandles.figure_MessageBox, 'UserData') == 1)
581 break;
582 end
583
584
585 % F0 straight
586 if (strcmp(paramlist{n}, 'F0 (Straight)'))
587 messages{k} = [messages{k} 'strF0 '];
588 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
589 drawnow;
590 err = 0;
591
592 if (useTextgrid)
593 try
594 [strF0, V] = func_StraightPitch(y, Fs, VSData.vars, textgridfile);
595 catch
596 err = 1;
597 end
598 else
599 try
600 [strF0, V] = func_StraightPitch(y, Fs, VSData.vars);
601 catch
602 err = 1;
603 end
604 end
605
606 if (strcmp(VSData.vars.F0algorithm, 'F0 (Straight)') && err == 1)
607 messages{k+1} = 'Error: Problem with STRAIGHT - please check settings';
608 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k+1);
609 set(MBoxHandles.pushbutton_close, 'Enable', 'on');
610 set(MBoxHandles.pushbutton_stop, 'Enable', 'off');
611
612 msgbox({'Error: Unable to proceed.', 'Problem with STRAIGHT - please check settings'}, 'Error', 'error', 'modal');
613 if (resampled) % delete the temporary file if it exists
614 delete(wavfile);
615 end
616 return;
617 end
618
619 strF0 = strF0(1:frameshift:end); % drop samples if necessary
620
621 if (length(strF0) > data_len)
622 strF0 = strF0(1:data_len);
623 elseif (length(strF0) < data_len)
624 strF0 = [strF0; ones(data_len - length(strF0), 1) * NaN];
625 end
626
627 if (exist(matfile, 'file'))
628 save(matfile, 'strF0', 'Fs', '-append');
629 else
630 save(matfile, 'strF0', 'Fs');
631 end
632
633
634 % F0 (Snack)
635 elseif (strcmp(paramlist{n}, 'F0 (Snack)'))
636 messages{k} = [messages{k} 'sF0 '];
637 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
638 drawnow;
639
640 % guard case for 32-bit precision files - some version of snack
641 % on a 64-bit machine causes pitch estimation to fail
642 use_alt_file = 0;
643 if (nbits ~= 16)
644 snackwavfile = [wavfile(1:end-4) '_16b.wav'];
645 use_alt_file = 1;
646 wavwrite(y, Fs, 16, snackwavfile);
647 else
648 snackwavfile = wavfile;
649 end
650
651 err = 0;
652 try
653 [sF0, sV, err] = func_SnackPitch(snackwavfile, windowsize/1000, frameshift/1000, maxF0, minF0);
654 catch
655 err = 1;
656 end
657
658 % check for fatal errors
659 if (strcmp(VSData.vars.F0algorithm, 'F0 (Snack)') && err == 1)
660 messages{k+1} = 'Error: Problem with snack - please check settings';
661 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k+1);
662 set(MBoxHandles.pushbutton_close, 'Enable', 'on');
663 set(MBoxHandles.pushbutton_stop, 'Enable', 'off');
664
665 msgbox({'Error: Unable to proceed.', 'Problem with snack - please check settings'}, 'Error', 'error', 'modal');
666 if (resampled) % delete the temporary file if it exists
667 delete(wavfile);
668 end
669 if (use_alt_file)
670 delete(snackwavfile);
671 end
672 return;
673 end
674
675 sF0 = [zeros(floor(windowsize/frameshift/2),1)*NaN; sF0]; sF0 = [sF0; ones(data_len-length(sF0), 1)*NaN];
676 sV = [zeros(floor(windowsize/frameshift/2),1)*NaN; sV]; sV = [sV; ones(data_len-length(sV), 1)* NaN];
677
678 if (exist(matfile, 'file'))
679 save(matfile, 'sF0', 'sV', 'Fs', '-append');
680 else
681 save(matfile, 'sF0', 'sV', 'Fs');
682 end
683
684 if (use_alt_file)
685 delete(snackwavfile);
686 end
687
688 % F0 (Praat)
689 elseif (strcmp(paramlist{n}, 'F0 (Praat)'))
690 messages{k} = [messages{k} 'pF0 '];
691 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
692 drawnow;
693
694 % guard case for 32-bit precision files - some version of snack
695 % on a 64-bit machine causes pitch estimation to fail
696 err = 0;
697 try
698 [pF0, err] = func_PraatPitch(wavfile, frameshift/1000, frame_precision, ...
699 VSData.vars.F0Praatmin, ...
700 VSData.vars.F0Praatmax, ...
701 VSData.vars.F0PraatSilenceThreshold, ...
702 VSData.vars.F0PraatVoiceThreshold, ...
703 VSData.vars.F0PraatOctaveCost, ...
704 VSData.vars.F0PraatOctaveJumpCost, ...
705 VSData.vars.F0PraatVoicedUnvoicedCost, ...
706 VSData.vars.F0PraatKillOctaveJumps, ...
707 VSData.vars.F0PraatSmooth, ...
708 VSData.vars.F0PraatSmoothingBandwidth, ...
709 VSData.vars.F0PraatInterpolate, ...
710 VSData.vars.F0Praatmethod, ...
711 data_len);
712 catch
713 err = 1;
714 end
715
716 % check for fatal errors
717 if (strcmp(VSData.vars.F0algorithm, 'F0 (Praat)') && err ~= 0)
718 messages{k+1} = 'Error: Problem with Praat - please check settings';
719 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k+1);
720 set(MBoxHandles.pushbutton_close, 'Enable', 'on');
721 set(MBoxHandles.pushbutton_stop, 'Enable', 'off');
722
723 msgbox({'Error: Unable to proceed.', 'Problem with Praat - please check settings'}, 'Error', 'error', 'modal');
724 if (resampled) % delete the temporary file if it exists
725 delete(wavfile);
726 end
727
728 return;
729 elseif (err ~= 0)
730 messages{k} = [messages{k} '(error) '];
731 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
732 end
733
734 if (exist(matfile, 'file'))
735 save(matfile, 'pF0', 'Fs', '-append');
736 else
737 save(matfile, 'pF0', 'Fs');
738 end
739
740 % F0 (Other)
741 elseif (strcmp(paramlist{n}, 'F0 (Other)'))
742 messages{k} = [messages{k} 'oF0 '];
743 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
744 drawnow;
745
746 oF0 = zeros(data_len, 1) * NaN; % allocate some memory
747
748 err = 0;
749 try
750 [F0, errmsg] = func_OtherPitch(wavfile, handles);
751 catch
752 err = 1;
753 end
754
755 if ((length(F0)==1 && isnan(F0)) || isempty(F0))
756 err = 1;
757 end
758
759 % check for fatal errors
760 if (err == 1)
761 messages{k} = [messages{k} '- error: ' errmsg ' '];
762 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
763
764 if (strcmp(VSData.vars.F0algorithm, 'F0 (Other)'))
765 set(MBoxHandles.pushbutton_close, 'Enable', 'on');
766 set(MBoxHandles.pushbutton_stop, 'Enable', 'off');
767 msgbox({['Error: ' errmsg], 'Problem with F0 estimation - please check settings'}, 'Error', 'error', 'modal');
768 if (resampled) % delete the temporary file if it exists
769 delete(wavfile);
770 end
771 return;
772 end
773 elseif (err ~= 0)
774 messages{k} = [messages{k} '(error) '];
775 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
776 end
777
778
779 if (VSData.vars.F0OtherOffset + length(F0) <= data_len)
780 oF0(VSData.vars.F0OtherOffset+1:VSData.vars.F0OtherOffset + length(F0)) = F0;
781 else % need to trim F0
782 oF0(VSData.vars.F0OtherOffset+1:end) = F0(1:data_len - VSData.vars.F0OtherOffset);
783 end
784
785 if (exist(matfile, 'file'))
786 save(matfile, 'oF0', 'Fs', '-append');
787 else
788 save(matfile, 'oF0', 'Fs');
789 end
790
791
792 % F1, F2, F3, F4 (Snack)
793 elseif (strcmp(paramlist{n}, 'F1, F2, F3, F4 (Snack)'))
794 messages{k} = [messages{k} 'FMTs '];
795 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
796 drawnow;
797
798 % guard case for 32-bit files - some version of snack on a
799 % 64-bit machine causes formant estimation to fail
800 use_alt_file = 0;
801 if (nbits ~= 16)
802 snackwavfile = [wavfile(1:end-4) '_16b.wav'];
803 wavwrite(y, Fs, 16, snackwavfile);
804 use_alt_file = 1;
805 else
806 snackwavfile = wavfile;
807 end
808
809 [sF1, sF2, sF3, sF4, sB1, sB2, sB3, sB4, err] = func_SnackFormants(snackwavfile, windowsize/1000, frameshift/1000, preemphasis);
810
811 if (strcmp(VSData.vars.FMTalgorithm, 'F1, F2, F3, F4 (Snack)') && err == 1)
812 messages{k+1} = 'Error: Problem with snack - please check settings';
813 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k+1);
814 set(MBoxHandles.pushbutton_close, 'Enable', 'on');
815 set(MBoxHandles.pushbutton_stop, 'Enable', 'off');
816
817 msgbox({'Error: Unable to proceed.', 'Problem with snack - please check settings'}, 'Error', 'error', 'modal');
818 if (resampled) % delete the temporary file if it exists
819 delete(wavfile);
820 end
821 if (use_alt_file)
822 delete(snackwavfile);
823 end
824
825 return;
826 end
827
828 sF1 = [zeros(floor(windowsize/frameshift/2),1) * NaN; sF1]; sF1 = [sF1; ones(data_len-length(sF1), 1)*NaN];
829 sF2 = [zeros(floor(windowsize/frameshift/2),1) * NaN; sF2]; sF2 = [sF2; ones(data_len-length(sF2), 1)*NaN];
830 sF3 = [zeros(floor(windowsize/frameshift/2),1) * NaN; sF3]; sF3 = [sF3; ones(data_len-length(sF3), 1)*NaN];
831 sF4 = [zeros(floor(windowsize/frameshift/2),1) * NaN; sF4]; sF4 = [sF4; ones(data_len-length(sF4), 1)*NaN];
832 sB1 = [zeros(floor(windowsize/frameshift/2),1) * NaN; sB1]; sB1 = [sB1; ones(data_len-length(sB1), 1)*NaN];
833 sB2 = [zeros(floor(windowsize/frameshift/2),1) * NaN; sB2]; sB2 = [sB2; ones(data_len-length(sB2), 1)*NaN];
834 sB3 = [zeros(floor(windowsize/frameshift/2),1) * NaN; sB3]; sB3 = [sB3; ones(data_len-length(sB3), 1)*NaN];
835 sB4 = [zeros(floor(windowsize/frameshift/2),1) * NaN; sB4]; sB4 = [sB4; ones(data_len-length(sB4), 1)*NaN];
836
837 if (exist(matfile, 'file'))
838 save(matfile, 'sF1', 'sF2', 'sF3', 'sF4', 'sB1', 'sB2', 'sB3', 'sB4', '-append');
839 save(matfile, 'windowsize', 'frameshift', 'preemphasis', '-append');
840 else
841 save(matfile, 'sF1', 'sF2', 'sF3', 'sF4', 'sB1', 'sB2', 'sB3', 'sB4');
842 save(matfile, 'windowsize', 'frameshift', 'preemphasis', '-append');
843 end
844
845 if (use_alt_file)
846 delete(snackwavfile);
847 end
848
849 % F1, F2, F3, F4 (Praat)
850 elseif (strcmp(paramlist{n}, 'F1, F2, F3, F4 (Praat)'))
851 messages{k} = [messages{k} 'FMTp '];
852 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
853 drawnow;
854
855 [pF1, pF2, pF3, pF4, pB1, pB2, pB3, pB4, err] = ...
856 func_PraatFormants(wavfile, windowsize/1000, frameshift/1000, frame_precision, data_len);
857
858 if (strcmp(VSData.vars.FMTalgorithm, 'F1, F2, F3, F4 (Praat)') && err ~= 0)
859 messages{k+1} = 'Error: Problem with Praat - please check settings';
860 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k+1);
861 set(MBoxHandles.pushbutton_close, 'Enable', 'on');
862 set(MBoxHandles.pushbutton_stop, 'Enable', 'off');
863
864 msgbox({'Error: Unable to proceed.', 'Problem with Praat - please check settings'}, 'Error', 'error', 'modal');
865 if (resampled) % delete the temporary file if it exists
866 delete(wavfile);
867 end
868
869 return;
870 end
871
872 if (exist(matfile, 'file'))
873 save(matfile, 'pF1', 'pF2', 'pF3', 'pF4', 'pB1', 'pB2', 'pB3', 'pB4', '-append');
874 save(matfile, 'windowsize', 'frameshift', 'preemphasis', '-append');
875 else
876 save(matfile, 'pF1', 'pF2', 'pF3', 'pF4', 'pB1', 'pB2', 'pB3', 'pB4');
877 save(matfile, 'windowsize', 'frameshift', 'preemphasis', '-append');
878 end
879
880 % F1, F2, F3, F4 (Other)
881 elseif (strcmp(paramlist{n}, 'F1, F2, F3, F4 (Other)'))
882 messages{k} = [messages{k} 'oFMTs '];
883 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
884 drawnow;
885
886 oF1 = zeros(data_len, 1) * NaN; % allocate some memory
887 oF2 = zeros(data_len, 1) * NaN;
888 oF3 = zeros(data_len, 1) * NaN;
889 oF4 = zeros(data_len, 1) * NaN;
890 oB1 = zeros(data_len, 1) * NaN;
891 oB2 = zeros(data_len, 1) * NaN;
892 oB3 = zeros(data_len, 1) * NaN;
893 oB4 = zeros(data_len, 1) * NaN;
894
895 err = 0;
896 try
897 [F1, F2, F3, F4, B1, B2, B3, B4, errmsg] = func_OtherFormants(wavfile, handles);
898 catch
899 err = 1;
900 end
901
902 if ((length(F1) == 1 && isnan(F1)) || isempty(F1))
903 err = 1;
904 end
905
906 if (err == 1)
907 messages{k} = [messages{k} '-error: ' errmsg];
908 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
909
910 if (strcmp(VSData.vars.FMTalgorithm, 'F1, F2, F3, F4 (Other)'))
911 set(MBoxHandles.pushbutton_close, 'Enable', 'on');
912 set(MBoxHandles.pushbutton_stop, 'Enable', 'off');
913
914 msgbox({'Error: Unable to proceed.', 'Problem with formant tracker - please check settings'}, 'Error', 'error', 'modal');
915 if (resampled) % delete the temporary file if it exists
916 delete(wavfile);
917 end
918
919 return;
920 end
921 end
922
923 % build up the actual vector
924 if (VSData.vars.FormantsOtherOffset + length(F1) <= data_len)
925 oF1(VSData.vars.FormantsOtherOffset+1:VSData.vars.FormantsOtherOffset + length(F1)) = F1;
926 oF2(VSData.vars.FormantsOtherOffset+1:VSData.vars.FormantsOtherOffset + length(F2)) = F2;
927 oF3(VSData.vars.FormantsOtherOffset+1:VSData.vars.FormantsOtherOffset + length(F3)) = F3;
928 oF4(VSData.vars.FormantsOtherOffset+1:VSData.vars.FormantsOtherOffset + length(F4)) = F4;
929 oB1(VSData.vars.FormantsOtherOffset+1:VSData.vars.FormantsOtherOffset + length(B1)) = B1;
930 oB2(VSData.vars.FormantsOtherOffset+1:VSData.vars.FormantsOtherOffset + length(B2)) = B2;
931 oB3(VSData.vars.FormantsOtherOffset+1:VSData.vars.FormantsOtherOffset + length(B3)) = B3;
932 oB4(VSData.vars.FormantsOtherOffset+1:VSData.vars.FormantsOtherOffset + length(B4)) = B4;
933 else % need to trim
934 oF1(VSData.vars.FormantsOtherOffset+1:end) = F1(1:data_len - VSData.vars.FormantsOtherOffset);
935 oF2(VSData.vars.FormantsOtherOffset+1:end) = F2(1:data_len - VSData.vars.FormantsOtherOffset);
936 oF3(VSData.vars.FormantsOtherOffset+1:end) = F3(1:data_len - VSData.vars.FormantsOtherOffset);
937 oF4(VSData.vars.FormantsOtherOffset+1:end) = F4(1:data_len - VSData.vars.FormantsOtherOffset);
938 oB1(VSData.vars.FormantsOtherOffset+1:end) = B1(1:data_len - VSData.vars.FormantsOtherOffset);
939 oB2(VSData.vars.FormantsOtherOffset+1:end) = B2(1:data_len - VSData.vars.FormantsOtherOffset);
940 oB3(VSData.vars.FormantsOtherOffset+1:end) = B3(1:data_len - VSData.vars.FormantsOtherOffset);
941 oB4(VSData.vars.FormantsOtherOffset+1:end) = B4(1:data_len - VSData.vars.FormantsOtherOffset);
942 end
943
944 if (exist(matfile, 'file'))
945 save(matfile, 'oF1', 'oF2', 'oF3', 'oF4', 'oB1', 'oB2', 'oB3', 'oB4', '-append');
946 else
947 save(matfile, 'oF1', 'oF2', 'oF3', 'oF4', 'oB1', 'oB2', 'oB3', 'oB4');
948 end
949
950
951
952 % H1, H2, H4
953 elseif (strcmp(paramlist{n}, 'H1, H2, H4'))
954 messages{k} = [messages{k} 'Hx '];
955 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
956 drawnow;
957
958 matdata = load(matfile);
959
960 F0 = func_parseF0(matdata, F0algorithm);
961
962 if (useTextgrid)
963 [H1, H2, H4, isComplete] = func_GetH1_H2_H4(y, Fs, F0, MBoxHandles, VSData.vars, textgridfile);
964 else
965 [H1, H2, H4, isComplete] = func_GetH1_H2_H4(y, Fs, F0, MBoxHandles, VSData.vars);
966 end
967
968 HF0algorithm = F0algorithm;
969
970 % check if the process was completed
971 if (isComplete==0)
972 messages{k+1} = 'Stop button pressed by user.';
973 if (ishandle(MBoxHandles.figure_MessageBox))
974 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k+1);
975 end
976 if (resampled) % delete the temporary file if it exists
977 delete(wavfile);
978 end
979
980 return;
981 end
982
983 if (exist(matfile, 'file'))
984 save(matfile, 'H1', 'H2', 'H4', 'HF0algorithm', '-append');
985 else
986 save(matfile, 'H1', 'H2', 'H4', 'HF0algorithm');
987 end
988
989
990
991 % A1, A2, A3
992 elseif (strcmp(paramlist{n}, 'A1, A2, A3'))
993 messages{k} = [messages{k} 'Ax '];
994 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
995 drawnow;
996
997 matdata = load(matfile); % file has to exist at this point - dependency checking should make sure of this
998
999 F0 = func_parseF0(matdata, F0algorithm);
1000 [F1, F2, F3] = func_parseFMT(matdata, FMTalgorithm);
1001
1002 if (useTextgrid)
1003 [A1, A2, A3] = func_GetA1A2A3(y, Fs, F0, F1, F2, F3, VSData.vars, textgridfile);
1004 else
1005 [A1, A2, A3] = func_GetA1A2A3(y, Fs, F0, F1, F2, F3, VSData.vars);
1006 end
1007
1008 AFMTalgorithm = FMTalgorithm;
1009
1010 save(matfile, 'A1', 'A2', 'A3', 'AFMTalgorithm', '-append');
1011
1012
1013 % H1*-H2* and H2*-H4*
1014 elseif (strcmp(paramlist{n}, 'H1*-H2*, H2*-H4*'))
1015 messages{k} = [messages{k} 'H1H2c H2H4c '];
1016 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
1017 drawnow;
1018
1019 matdata = load(matfile);
1020 F0 = func_parseF0(matdata, F0algorithm);
1021 [F1, F2, F3] = func_parseFMT(matdata, FMTalgorithm);
1022
1023 [H1H2c, H2H4c] = func_GetH1H2_H2H4(matdata.H1, matdata.H2, matdata.H4, Fs, F0, F1, F2);
1024 save(matfile, 'H1H2c', 'H2H4c', '-append');
1025
1026
1027 % H1*-A1*, H1*-A2*, and H1*-A3*
1028 elseif (strcmp(paramlist{n}, 'H1*-A1*, H1*-A2*, H1*-A3*'))
1029 messages{k} = [messages{k} 'H1A1c H1A2c H1A3c '];
1030 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
1031 drawnow;
1032
1033 matdata = load(matfile);
1034 F0 = func_parseF0(matdata, F0algorithm);
1035 [F1, F2, F3] = func_parseFMT(matdata, FMTalgorithm);
1036
1037 [H1A1c, H1A2c, H1A3c] = func_GetH1A1_H1A2_H1A3(matdata.H1, matdata.A1, matdata.A2, matdata.A3, Fs, F0, F1, F2, F3);
1038 save(matfile, 'H1A1c', 'H1A2c', 'H1A3c', '-append');
1039
1040
1041 % Energy
1042 elseif (strcmp(paramlist{n}, 'Energy'))
1043 messages{k} = [messages{k} 'E '];
1044 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
1045 drawnow;
1046
1047 matdata = load(matfile);
1048 F0 = func_parseF0(matdata, F0algorithm);
1049
1050 Energy = func_GetEnergy(y, F0, Fs, VSData.vars);
1051 save(matfile, 'Energy', '-append');
1052
1053
1054 % CPP
1055 elseif (strcmp(paramlist{n}, 'CPP'))
1056 messages{k} = [messages{k} 'CPP '];
1057 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
1058 drawnow;
1059
1060 matdata = load(matfile);
1061 F0 = func_parseF0(matdata, F0algorithm);
1062
1063 CPP = func_GetCPP(y, Fs, F0, VSData.vars);
1064 save(matfile, 'CPP', '-append');
1065
1066
1067 % HNR
1068 elseif (strcmp(paramlist{n}, 'Harmonic to Noise Ratios - HNR'))
1069 messages{k} = [messages{k} 'HNR '];
1070 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
1071 drawnow;
1072
1073 matdata = load(matfile);
1074 F0 = func_parseF0(matdata, F0algorithm);
1075
1076 [HNR05, HNR15, HNR25, HNR35] = func_GetHNR(y, Fs, F0, VSData.vars);
1077 save(matfile, 'HNR05', 'HNR15', 'HNR25', 'HNR35', '-append');
1078
1079
1080 % SHR
1081 elseif (strcmp(paramlist{n}, 'Subharmonic to Harmonic Ratio/F0 - SHR, (shr)F0'))
1082 messages{k} = [messages{k} 'SHR, shrF0 '];
1083 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', k);
1084 drawnow;
1085
1086 matdata = load(matfile);
1087
1088 [SHR, shrF0] = func_GetSHRP(y, Fs, VSData.vars, data_len);
1089 save(matfile, 'SHR', 'shrF0', '-append');
1090 end
1091
1092 end
1093
1094 if (resampled) % delete the temporary file if it exists
1095 delete(wavfile);
1096 end
1097
1098 end
1099
1100 messages{length(filelist)+1} = 'Processing complete.';
1101 set(MBoxHandles.listbox_messages, 'String', messages, 'Value', length(filelist)+1);
1102 set(MBoxHandles.pushbutton_close, 'Enable', 'on');
1103 set(MBoxHandles.pushbutton_stop, 'Enable', 'off');
1104
1105
1106 % Function to generate random file names
1107 function filename = generateRandomFile(fname, handles)
1108 VSData = guidata(handles.VSHandle);
1109 N = 8; % this many random digits/characters
1110 [pathstr, name, ext] = fileparts(fname);
1111 randstr = '00000000';
1112
1113 isok = 0;
1114
1115 while(isok == 0)
1116 for k=1:N
1117 randstr(k) = floor(rand() * 25) + 65;
1118 end
1119 filename = [pathstr VSData.vars.dirdelimiter 'tmp_' name randstr ext];
1120
1121 if (exist(filename, 'file') == 0)
1122 isok = 1;
1123 end
1124 end
1125
1126
1127 % --- Executes when user attempts to close figure_ParameterEstimation.
1128 function figure_ParameterEstimation_CloseRequestFcn(hObject, eventdata, handles)
1129 % hObject handle to figure_ParameterEstimation (see GCBO)
1130 % eventdata reserved - to be defined in a future version of MATLAB
1131 % handles structure with handles and user data (see GUIDATA)
1132
1133 % Hint: delete(hObject) closes the figure
1134 if (isfield(handles, 'SWfig'))
1135 delete(handles.SWfig);
1136 end
1137
1138 VSData = guidata(handles.VSHandle);
1139 VSData.vars.PE_showwaveforms = 0;
1140 guidata(handles.VSHandle, VSData);
1141
1142 delete(hObject);
1143
1144