annotate aim-mat/gui/do_aim_calculate.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % procedure for 'aim-mat'
tomwalters@0 2 %
tomwalters@0 3 % function handles=do_aim_calculate(handles)
tomwalters@0 4 %
tomwalters@0 5 % INPUT VALUES:
tomwalters@0 6 % handles: all relevant data and information in a struct
tomwalters@0 7 % RETURN VALUE:
tomwalters@0 8 % handles: the updated data
tomwalters@0 9 %
tomwalters@0 10 % this function does all relevant calculation (can be called with or
tomwalters@0 11 % without graphic.
tomwalters@0 12 %
bleeck@3 13 %
tomwalters@0 14 % (c) 2011, University of Southampton
bleeck@3 15 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 16 % download of current version is on the soundsoftware site:
bleeck@3 17 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 18 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 19
tomwalters@0 20
tomwalters@0 21
tomwalters@0 22 function handles=do_aim_calculate(handles)
tomwalters@0 23 %
tomwalters@0 24 % % if in the graphic version, then we take the parameters from the parameter
tomwalters@0 25 % % file. If in the nographic version, all parameters come in handles.
tomwalters@0 26
tomwalters@0 27 % save for later
tomwalters@0 28 oldoptions=handles.all_options;
tomwalters@0 29
tomwalters@0 30 if handles.with_graphic==1
tomwalters@0 31 set(handles.figure1,'Pointer','watch'); % set the mousepointer to the busy-sign
tomwalters@0 32
tomwalters@0 33 if ~isfield(handles.info,'no_automatic_parameter_update')
tomwalters@0 34 no_automatic_parameter_update=1;
tomwalters@0 35 else
tomwalters@0 36 no_automatic_parameter_update=handles.info.no_automatic_parameter_update;
tomwalters@0 37 end
tomwalters@0 38
tomwalters@0 39 if no_automatic_parameter_update==0
tomwalters@0 40 % first read in the new parameter values and see, which ones have changed
tomwalters@0 41 parfile=handles.info.parameterfilename;
tomwalters@0 42 [pathstr,parfilename,ext] = fileparts(parfile);
tomwalters@0 43 old=pwd;
tomwalters@0 44 lookpath=fullfile(handles.info.original_soundfile_directory,pathstr);
tomwalters@0 45 cd(lookpath);
tomwalters@0 46 eval(parfilename);
tomwalters@0 47 cd(old);
tomwalters@0 48 newoptions=all_options;
tomwalters@0 49 handles.all_options=newoptions;
tomwalters@0 50 end
tomwalters@0 51 end
tomwalters@0 52
tomwalters@0 53
tomwalters@0 54 % first calculate the signal
tomwalters@0 55 % check, if the signal has been changed:
tomwalters@0 56 sigopts=handles.all_options.signal;
tomwalters@0 57 sig=handles.data.signal;
tomwalters@0 58 changesig=0;
tomwalters@0 59 if sigopts.duration~=getlength(sig);
tomwalters@0 60 changesig=1;
tomwalters@0 61 end
tomwalters@0 62 if sigopts.start_time~=getminimumtime(sig);
tomwalters@0 63 changesig=1;
tomwalters@0 64 end
tomwalters@0 65 if structisequal(oldoptions.signal,handles.all_options.signal)
tomwalters@0 66 changesig=1;
tomwalters@0 67 end
tomwalters@0 68
tomwalters@0 69 if changesig
tomwalters@0 70 %|| handles.info.calculate_signal==1
tomwalters@0 71 start=handles.all_options.signal.start_time;
tomwalters@0 72 duration=handles.all_options.signal.duration;
tomwalters@0 73 orgsig=handles.data.original_signal;
tomwalters@0 74
tomwalters@0 75 % do some error checking, just in case:
tomwalters@0 76 sigdur=getlength(orgsig);
tomwalters@0 77 start=max(start,0);
tomwalters@0 78 start=min(start,sigdur-0.001);
tomwalters@0 79 duration=max(0,duration);
tomwalters@0 80 duration=min(duration,sigdur-start);
tomwalters@0 81
tomwalters@0 82 sig=getpart(orgsig,start,start+duration);
tomwalters@0 83 handles.data.signal=sig;
tomwalters@0 84 name=handles.info.signalname;
tomwalters@0 85 lookpath=fullfile(handles.info.original_soundfile_directory,name);
tomwalters@0 86 graphic_dir=fullfile(handles.info.original_soundfile_directory,handles.info.directoryname);
tomwalters@0 87
tomwalters@0 88 if exist(graphic_dir)==7 % only, if not in ne graphic mode
tomwalters@0 89 aim_savefile(handles,sig,name,'signal','signal',[],handles.all_options);
tomwalters@0 90 signame= fullfile(handles.info.original_soundfile_directory,handles.info.signalwavename);
tomwalters@0 91 savewave(sig,signame,0);
tomwalters@0 92 end
tomwalters@0 93
tomwalters@0 94 % handles.info.calculate_signal=0;
tomwalters@0 95
tomwalters@0 96 end
tomwalters@0 97
tomwalters@0 98
tomwalters@0 99
tomwalters@0 100 % calculate outerear /middle ear transfere function
tomwalters@0 101 % if get(handles.checkbox0,'Value')==1
tomwalters@0 102 if handles.info.calculate_pcp==1
tomwalters@0 103 [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,2);
tomwalters@0 104 handles.info.calculated_pcp_module=generating_module; % this one is really calculated
tomwalters@0 105 sig=handles.data.signal;
tomwalters@0 106 callline=sprintf('res=%s(sig,coptions);',generating_function);
tomwalters@0 107 eval(callline); % evaluate the generating function
tomwalters@0 108 % store the result
tomwalters@0 109 handles.data.pcp=res;
tomwalters@0 110
tomwalters@0 111 if handles.info.save_pcp==1
tomwalters@0 112 aim_savefile(handles,res,handles.info.pcpname,'pcp',generating_module,coptions,handles.all_options);
tomwalters@0 113 end
tomwalters@0 114 if handles.with_graphic==1
tomwalters@0 115 handles.info.pcp_loaded=1;
tomwalters@0 116 handles.info.current_plot=2; % display the new data
tomwalters@0 117 set(handles.checkbox0,'Value',0);
tomwalters@0 118 handles=aim_deletefile(handles,'bmm');
tomwalters@0 119 handles=aim_deletefile(handles,'nap');
tomwalters@0 120 handles=aim_deletefile(handles,'strobes');
tomwalters@0 121 handles=aim_deletefile(handles,'sai');
tomwalters@0 122 handles=aim_deletefile(handles,'usermodule');
tomwalters@0 123 end
tomwalters@0 124 end
tomwalters@0 125
tomwalters@0 126 % calculate outer ear middle ear transfere functin
tomwalters@0 127 % if get(handles.checkbox1,'Value')==1
tomwalters@0 128 if handles.info.calculate_bmm==1
tomwalters@0 129 [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,3);
tomwalters@0 130 handles.info.calculated_bmm_module=generating_module; % this one is really calculated
tomwalters@0 131 sig=handles.data.pcp;
tomwalters@0 132 callline=sprintf('res=%s(sig,coptions);',generating_function);
tomwalters@0 133 eval(callline);
tomwalters@0 134 % store the result
tomwalters@0 135 handles.data.bmm=res;
tomwalters@0 136 if handles.info.save_bmm==1
tomwalters@0 137 aim_savefile(handles,res,handles.info.bmmname,'bmm',generating_module,coptions,handles.all_options);
tomwalters@0 138 end
tomwalters@0 139 if handles.with_graphic==1
tomwalters@0 140 handles.info.bmm_loaded=1;
tomwalters@0 141 handles.info.current_plot=3; % display the new data
tomwalters@0 142 % if this one is calculated new, then the further part has no relevance any more:
tomwalters@0 143 set(handles.checkbox1,'Value',0);
tomwalters@0 144 handles=aim_deletefile(handles,'nap');
tomwalters@0 145 handles=aim_deletefile(handles,'strobes');
tomwalters@0 146 handles=aim_deletefile(handles,'sai');
tomwalters@0 147 handles=aim_deletefile(handles,'usermodule');
tomwalters@0 148 end
tomwalters@0 149 end
tomwalters@0 150
tomwalters@0 151 % calculate NAP
tomwalters@0 152 % if get(handles.checkbox2,'Value')==1
tomwalters@0 153 if handles.info.calculate_nap==1
tomwalters@0 154 [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,4);
tomwalters@0 155 handles.info.calculated_nap_module=generating_module; % this one is really calculated
tomwalters@0 156 bmm=handles.data.bmm;
tomwalters@0 157 callline=sprintf('res=%s(bmm,coptions);',generating_function);
tomwalters@0 158 eval(callline);
tomwalters@0 159 % store the result
tomwalters@0 160 handles.data.nap=res;
tomwalters@0 161 if handles.info.save_nap==1
tomwalters@0 162 aim_savefile(handles,res,handles.info.napname,'nap',generating_module,coptions,handles.all_options);
tomwalters@0 163 end
tomwalters@0 164 if handles.with_graphic==1
tomwalters@0 165 handles.info.nap_loaded=1;
tomwalters@0 166 handles.info.current_plot=4; % display the new data
tomwalters@0 167 % if this one is calculated new, then the further part has no relevance any more:
tomwalters@0 168 set(handles.checkbox2,'Value',0);
tomwalters@0 169 handles=aim_deletefile(handles,'strobes');
tomwalters@0 170 handles=aim_deletefile(handles,'sai');
tomwalters@0 171 handles=aim_deletefile(handles,'usermodule');
tomwalters@0 172 end
tomwalters@0 173 end
tomwalters@0 174
tomwalters@0 175 % calculate Strobes
tomwalters@0 176 % if get(handles.checkbox3,'Value')==1
tomwalters@0 177 if handles.info.calculate_strobes==1
tomwalters@0 178 [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,5);
tomwalters@0 179 handles.info.calculated_strobes_module=generating_module; % this one is really calculated
tomwalters@0 180 nap=handles.data.nap;
tomwalters@0 181 callline=sprintf('[res,thres]=%s(nap,coptions);',generating_function);
tomwalters@0 182 eval(callline);
tomwalters@0 183 % store the result
tomwalters@0 184 handles.data.strobes=res;
tomwalters@0 185 if handles.info.save_strobes==1
tomwalters@0 186 aim_savefile(handles,res,handles.info.strobesname,'strobes',generating_module,coptions,handles.all_options);
tomwalters@0 187 % if isoftype(handles.data.bmm,'frame') && getnrchannels(handles.data.bmm)==1
tomwalters@0 188 aim_savefile(handles,thres,handles.info.thresholdsname,'thresholds',generating_module,coptions,handles.all_options);
tomwalters@0 189 % end
tomwalters@0 190 end
tomwalters@0 191 if handles.with_graphic==1
tomwalters@0 192 % if we only have one channel, then it is useful also to have the
tomwalters@0 193 % thresholds:
tomwalters@0 194
tomwalters@0 195 handles.data.thresholds=thres;
tomwalters@0 196 handles.info.strobes_loaded=1;
tomwalters@0 197 handles.info.current_plot=5; % display the new data
tomwalters@0 198
tomwalters@0 199 % if this one is calculated new, then the further part has no relevance any more:
tomwalters@0 200 set(handles.checkbox3,'Value',0);
tomwalters@0 201 handles=aim_deletefile(handles,'sai');
tomwalters@0 202 handles=aim_deletefile(handles,'usermodule');
tomwalters@0 203
tomwalters@0 204 %TCW AIM2006
tomwalters@0 205 handles=aim_deletefile(handles,'pitch_image');
tomwalters@0 206 % This cleans up after pitchresonance and other dual output SAI
tomwalters@0 207 % modules but will log an error to the command window if the
tomwalters@0 208 % previous SAI module wasn't dual output. This is a bug and needs fixing.
tomwalters@0 209 end
tomwalters@0 210 end
tomwalters@0 211
tomwalters@0 212 % calculate SAI
tomwalters@0 213 % if get(handles.checkbox4,'Value')==1
tomwalters@0 214 if handles.info.calculate_sai==1
tomwalters@0 215 [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,6);
tomwalters@0 216 handles.info.calculated_sai_module=generating_module; % this one is really calculated
tomwalters@0 217 nap=handles.data.nap;
tomwalters@0 218 strobes=handles.data.strobes;
tomwalters@0 219 callline=sprintf('res=%s(nap,strobes,coptions);',generating_function);
tomwalters@0 220
tomwalters@0 221 % add the soundfilename in case for ams
tomwalters@0 222 if strcmp(generating_module,'ams') % for one channel we additionally pass the threshold:
tomwalters@0 223 coptions.soundfile=handles.info.oldsignalwavename;
tomwalters@0 224 else
tomwalters@0 225 if getnrchannels(handles.data.bmm)==1 % for one channel we additionally pass the threshold:
tomwalters@0 226 coptions.single_channel_threshold=handles.data.thresholds;
tomwalters@0 227 end
tomwalters@0 228 end
tomwalters@0 229
tomwalters@0 230 eval(callline);
tomwalters@0 231
tomwalters@0 232 % This module is a special case, as we can have two sorts of output
tomwalters@0 233 % from it, either the straight SAI (as seen in AIM 2003), or a pair of images: the pitch
tomwalters@0 234 % image and resonance image. If the dual_output option is set to 1 in
tomwalters@0 235 % the parameters file, then the module is taken to have two outputs.
tomwalters@0 236 % One of these outputs, the resonance image, gets put in the old 'sai'
tomwalters@0 237 % part of the structure, and the pitch image is placed in a new
tomwalters@0 238 % structure, 'pitch_image'.
tomwalters@0 239 if ~isfield(coptions, 'dual_output')
tomwalters@0 240 coptions.dual_output=0;
tomwalters@0 241 end
tomwalters@0 242
tomwalters@0 243 % store the result
tomwalters@0 244 if (coptions.dual_output==1)
tomwalters@0 245 handles.data.sai=res{1};
tomwalters@0 246 handles.data.pitch_image=res{2};
tomwalters@0 247 else
tomwalters@0 248 handles.data.sai=res;
tomwalters@0 249 end
tomwalters@0 250
tomwalters@0 251
tomwalters@0 252 %handles.data.sai=res;
tomwalters@0 253
tomwalters@0 254 if handles.info.save_sai==1
tomwalters@0 255 if (coptions.dual_output==1)
tomwalters@0 256 aim_savefile(handles,res{1},handles.info.sainame,'sai',generating_module,coptions,handles.all_options);
tomwalters@0 257 aim_savefile(handles,res{2},handles.info.pitch_imagename,'pitch_image',generating_module,coptions,handles.all_options);
tomwalters@0 258 else
tomwalters@0 259 aim_savefile(handles,res,handles.info.sainame,'sai',generating_module,coptions,handles.all_options);
tomwalters@0 260 end
tomwalters@0 261 end
tomwalters@0 262
tomwalters@0 263 if handles.with_graphic==1
tomwalters@0 264 handles.info.sai_loaded=1;
tomwalters@0 265 handles.info.current_plot=6; % display the new data
tomwalters@0 266 % if this one is calculated new, then the further part has no relevance any more:
tomwalters@0 267 set(handles.checkbox4,'Value',0);
tomwalters@0 268 handles=aim_deletefile(handles,'usermodule');
tomwalters@0 269 end
tomwalters@0 270 end
tomwalters@0 271
tomwalters@0 272
tomwalters@0 273 % calculate user module
tomwalters@0 274 % if get(handles.checkbox8,'Value')==1
tomwalters@0 275 if handles.info.calculate_usermodule==1
tomwalters@0 276 [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,7);
tomwalters@0 277 handles.info.calculated_usermodule_module=generating_module; % this one is really calculated
tomwalters@0 278
tomwalters@0 279 sai=handles.data.sai;
tomwalters@0 280
tomwalters@0 281 % TCW AIM2006 - to cary through pitch-resonance output to the latter
tomwalters@0 282 % stages
tomwalters@0 283 if ~isfield(coptions, 'dual_input')
tomwalters@0 284 coptions.dual_input=0;
tomwalters@0 285 end
tomwalters@0 286
tomwalters@0 287
tomwalters@0 288 if coptions.dual_input==1
tomwalters@0 289 if isfield(handles.data, 'pitch_image')
tomwalters@0 290 pitch_image=handles.data.pitch_image;
tomwalters@0 291 callline=sprintf('res=%s(sai,pitch_image,coptions);',generating_function);
tomwalters@0 292 else
tomwalters@0 293 error(['The module ' generating_module ' is dual input, but the SAI module used before it'...
tomwalters@0 294 ' was not dual output, please use a compatible module at this stage'...
tomwalters@0 295 ' for more information, see the documentation at'...
tomwalters@0 296 ' http://www.pdn.cam.ac.uk/cnbh/aim2006/']);
tomwalters@0 297 end
tomwalters@0 298 else
tomwalters@0 299 if isfield(handles.data, 'pitch_image')
tomwalters@0 300 error(['The module ' generating_module ' is not dual input, but the SAI module used before it'...
tomwalters@0 301 ' was dual output, please use a compatible module at this stage'...
tomwalters@0 302 ' for more information, see the documentation at'...
tomwalters@0 303 ' http://www.pdn.cam.ac.uk/cnbh/aim2006/']);
tomwalters@0 304 else
tomwalters@0 305 callline=sprintf('res=%s(sai,coptions);',generating_function);
tomwalters@0 306 end
tomwalters@0 307
tomwalters@0 308 end
tomwalters@0 309
tomwalters@0 310
tomwalters@0 311 eval(callline);
tomwalters@0 312
tomwalters@0 313 % store the result
tomwalters@0 314 handles.data.usermodule=res;
tomwalters@0 315 if handles.info.save_usermodule==1
tomwalters@0 316 aim_savefile(handles,res,handles.info.usermodulename,'usermodule',generating_module,coptions,handles.all_options);
tomwalters@0 317 end
tomwalters@0 318 if handles.with_graphic==1
tomwalters@0 319 handles.info.usermodule_loaded=1;
tomwalters@0 320 handles.info.current_plot=7; % display the new data
tomwalters@0 321 % if this one is calculated new, then the further part has no relevance any more:
tomwalters@0 322 set(handles.checkbox8,'Value',0);
tomwalters@0 323 end
tomwalters@0 324 end
tomwalters@0 325
tomwalters@0 326 % calculate movies
tomwalters@0 327 % if get(handles.checkbox5,'Value')==1
tomwalters@0 328 if handles.info.calculate_movie==1
tomwalters@0 329 [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,8);
tomwalters@0 330 handles.info.calculated_movie_module=generating_module; % this one is really calculated
tomwalters@0 331 % if strcmp(handles.info.current_usermodule_module,'none')
tomwalters@0 332 % data=handles.data.sai;
tomwalters@0 333 % else
tomwalters@0 334 % data=handles.data.usermodule;
tomwalters@0 335 % end
tomwalters@0 336
tomwalters@0 337 % % if we dont know about the framerate, then get the framerate from the
tomwalters@0 338 % % sai-module
tomwalters@0 339 % if ~isfield(coptions,'frames_per_second')
tomwalters@0 340 % [mod,func,opts]=aim_getcurrent_module(handles,7); % try in the usermodule
tomwalters@0 341 % if ~isfield(opts,'frames_per_second')
tomwalters@0 342 % [mod,func,opts2]=aim_getcurrent_module(handles,6); % try in the sai-module
tomwalters@0 343 % if ~isfield(opts2,'frames_per_second')
tomwalters@0 344 % disp('dont know about the framerate! Assuming 20');
tomwalters@0 345 % coptions.frames_per_second=20; % dont know about it
tomwalters@0 346 % else
tomwalters@0 347 % coptions.frames_per_second=opts2.frames_per_second;
tomwalters@0 348 % end
tomwalters@0 349 % else
tomwalters@0 350 % coptions.frames_per_second=opts.frames_per_second;
tomwalters@0 351 % end
tomwalters@0 352 % end
tomwalters@0 353
tomwalters@0 354
tomwalters@0 355 % in case of the screen-movie, we need some additional information:
tomwalters@0 356 % if strcmp(handles.info.current_movie_module,'screen')
tomwalters@0 357 if handles.with_graphic==1
tomwalters@0 358 if get(handles.checkbox7,'Value')==1
tomwalters@0 359 handles.all_options.movie.screen.withtime=1;
tomwalters@0 360 coptions.withtime=1;
tomwalters@0 361 else
tomwalters@0 362 handles.all_options.movie.screen.withtime=0;
tomwalters@0 363 coptions.withtime=0;
tomwalters@0 364 end
tomwalters@0 365 % and if we want to see the frequency profile:
tomwalters@0 366 if get(handles.checkbox6,'Value')==1
tomwalters@0 367 handles.all_options.movie.screen.withfre=1;
tomwalters@0 368 coptions.withfre=1;
tomwalters@0 369 else
tomwalters@0 370 handles.all_options.movie.screen.withfre=0;
tomwalters@0 371 coptions.withfre=0;
tomwalters@0 372 end
tomwalters@0 373 % do we want to see the signal?
tomwalters@0 374 if get(handles.checkbox10,'Value')==1
tomwalters@0 375 handles.all_options.movie.screen.withsignal=1;
tomwalters@0 376 coptions.withsignal=1;
tomwalters@0 377 else
tomwalters@0 378 handles.all_options.movie.screen.withsignal=0;
tomwalters@0 379 coptions.withsignal=0;
tomwalters@0 380 end
tomwalters@0 381 % scaling properties
tomwalters@0 382 data_scale=slidereditcontrol_get_value(handles.slideredit_scale);
tomwalters@0 383 handles.all_options.movie.screen.data_scale=data_scale;
tomwalters@0 384 coptions.data_scale=data_scale;
tomwalters@0 385 end
tomwalters@0 386 % end
tomwalters@0 387
tomwalters@0 388 % give the movie access to all data, which is useful for bmm, etc
tomwalters@0 389 data=handles.data;
tomwalters@0 390
tomwalters@0 391
tomwalters@0 392 % add a few names to the options, so that the movie can be saved
tomwalters@0 393 if handles.with_graphic==1
tomwalters@0 394 uniqueworkingname=handles.info.uniqueworkingname;
tomwalters@0 395 directoryname=handles.info.directoryname;
tomwalters@0 396 % find out the name of this movie. Movies are numberd in their
tomwalters@0 397 % order, so that no one is lost
tomwalters@0 398 moviename=generate_new_movie_name(handles);
tomwalters@0 399 newname=fullfile(handles.info.uniqueworkingname,moviename);
tomwalters@0 400 coptions.moviename=newname;
tomwalters@0 401 coptions.soundfilename=handles.info.signalwavename;
tomwalters@0 402 coptions.handles=handles;
tomwalters@0 403 callline=sprintf('%s(data,coptions);',generating_function);
tomwalters@0 404 eval(callline);
tomwalters@0 405 handles.info.movie_loaded=1;
tomwalters@0 406 handles.info.last_movie_name_generated=moviename;
tomwalters@0 407 set(handles.checkbox5,'Value',0);
tomwalters@0 408 else
tomwalters@0 409 coptions.moviename=sprintf('%s.%s.mov',handles.info.uniqueworkingname,handles.info.current_movie_module);
tomwalters@0 410 coptions.soundfilename=handles.all_options.signal.signal_filename;
tomwalters@0 411 coptions.handles=handles;
tomwalters@0 412 callline=sprintf('%s(sai,coptions);',generating_function);
tomwalters@0 413 eval(callline);
tomwalters@0 414 end
tomwalters@0 415 end
tomwalters@0 416
tomwalters@0 417 % return the pointer shape
tomwalters@0 418 if handles.with_graphic==1
tomwalters@0 419 set(handles.figure1,'Pointer','arrow');
tomwalters@0 420 end