tomwalters@0: % procedure for 'aim-mat' tomwalters@0: % tomwalters@0: % function handles=do_aim_calculate(handles) tomwalters@0: % tomwalters@0: % INPUT VALUES: tomwalters@0: % handles: all relevant data and information in a struct tomwalters@0: % RETURN VALUE: tomwalters@0: % handles: the updated data tomwalters@0: % tomwalters@0: % this function does all relevant calculation (can be called with or tomwalters@0: % without graphic. tomwalters@0: % bleeck@3: % tomwalters@0: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: function handles=do_aim_calculate(handles) tomwalters@0: % tomwalters@0: % % if in the graphic version, then we take the parameters from the parameter tomwalters@0: % % file. If in the nographic version, all parameters come in handles. tomwalters@0: tomwalters@0: % save for later tomwalters@0: oldoptions=handles.all_options; tomwalters@0: tomwalters@0: if handles.with_graphic==1 tomwalters@0: set(handles.figure1,'Pointer','watch'); % set the mousepointer to the busy-sign tomwalters@0: tomwalters@0: if ~isfield(handles.info,'no_automatic_parameter_update') tomwalters@0: no_automatic_parameter_update=1; tomwalters@0: else tomwalters@0: no_automatic_parameter_update=handles.info.no_automatic_parameter_update; tomwalters@0: end tomwalters@0: tomwalters@0: if no_automatic_parameter_update==0 tomwalters@0: % first read in the new parameter values and see, which ones have changed tomwalters@0: parfile=handles.info.parameterfilename; tomwalters@0: [pathstr,parfilename,ext] = fileparts(parfile); tomwalters@0: old=pwd; tomwalters@0: lookpath=fullfile(handles.info.original_soundfile_directory,pathstr); tomwalters@0: cd(lookpath); tomwalters@0: eval(parfilename); tomwalters@0: cd(old); tomwalters@0: newoptions=all_options; tomwalters@0: handles.all_options=newoptions; tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: % first calculate the signal tomwalters@0: % check, if the signal has been changed: tomwalters@0: sigopts=handles.all_options.signal; tomwalters@0: sig=handles.data.signal; tomwalters@0: changesig=0; tomwalters@0: if sigopts.duration~=getlength(sig); tomwalters@0: changesig=1; tomwalters@0: end tomwalters@0: if sigopts.start_time~=getminimumtime(sig); tomwalters@0: changesig=1; tomwalters@0: end tomwalters@0: if structisequal(oldoptions.signal,handles.all_options.signal) tomwalters@0: changesig=1; tomwalters@0: end tomwalters@0: tomwalters@0: if changesig tomwalters@0: %|| handles.info.calculate_signal==1 tomwalters@0: start=handles.all_options.signal.start_time; tomwalters@0: duration=handles.all_options.signal.duration; tomwalters@0: orgsig=handles.data.original_signal; tomwalters@0: tomwalters@0: % do some error checking, just in case: tomwalters@0: sigdur=getlength(orgsig); tomwalters@0: start=max(start,0); tomwalters@0: start=min(start,sigdur-0.001); tomwalters@0: duration=max(0,duration); tomwalters@0: duration=min(duration,sigdur-start); tomwalters@0: tomwalters@0: sig=getpart(orgsig,start,start+duration); tomwalters@0: handles.data.signal=sig; tomwalters@0: name=handles.info.signalname; tomwalters@0: lookpath=fullfile(handles.info.original_soundfile_directory,name); tomwalters@0: graphic_dir=fullfile(handles.info.original_soundfile_directory,handles.info.directoryname); tomwalters@0: tomwalters@0: if exist(graphic_dir)==7 % only, if not in ne graphic mode tomwalters@0: aim_savefile(handles,sig,name,'signal','signal',[],handles.all_options); tomwalters@0: signame= fullfile(handles.info.original_soundfile_directory,handles.info.signalwavename); tomwalters@0: savewave(sig,signame,0); tomwalters@0: end tomwalters@0: tomwalters@0: % handles.info.calculate_signal=0; tomwalters@0: tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: % calculate outerear /middle ear transfere function tomwalters@0: % if get(handles.checkbox0,'Value')==1 tomwalters@0: if handles.info.calculate_pcp==1 tomwalters@0: [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,2); tomwalters@0: handles.info.calculated_pcp_module=generating_module; % this one is really calculated tomwalters@0: sig=handles.data.signal; tomwalters@0: callline=sprintf('res=%s(sig,coptions);',generating_function); tomwalters@0: eval(callline); % evaluate the generating function tomwalters@0: % store the result tomwalters@0: handles.data.pcp=res; tomwalters@0: tomwalters@0: if handles.info.save_pcp==1 tomwalters@0: aim_savefile(handles,res,handles.info.pcpname,'pcp',generating_module,coptions,handles.all_options); tomwalters@0: end tomwalters@0: if handles.with_graphic==1 tomwalters@0: handles.info.pcp_loaded=1; tomwalters@0: handles.info.current_plot=2; % display the new data tomwalters@0: set(handles.checkbox0,'Value',0); tomwalters@0: handles=aim_deletefile(handles,'bmm'); tomwalters@0: handles=aim_deletefile(handles,'nap'); tomwalters@0: handles=aim_deletefile(handles,'strobes'); tomwalters@0: handles=aim_deletefile(handles,'sai'); tomwalters@0: handles=aim_deletefile(handles,'usermodule'); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % calculate outer ear middle ear transfere functin tomwalters@0: % if get(handles.checkbox1,'Value')==1 tomwalters@0: if handles.info.calculate_bmm==1 tomwalters@0: [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,3); tomwalters@0: handles.info.calculated_bmm_module=generating_module; % this one is really calculated tomwalters@0: sig=handles.data.pcp; tomwalters@0: callline=sprintf('res=%s(sig,coptions);',generating_function); tomwalters@0: eval(callline); tomwalters@0: % store the result tomwalters@0: handles.data.bmm=res; tomwalters@0: if handles.info.save_bmm==1 tomwalters@0: aim_savefile(handles,res,handles.info.bmmname,'bmm',generating_module,coptions,handles.all_options); tomwalters@0: end tomwalters@0: if handles.with_graphic==1 tomwalters@0: handles.info.bmm_loaded=1; tomwalters@0: handles.info.current_plot=3; % display the new data tomwalters@0: % if this one is calculated new, then the further part has no relevance any more: tomwalters@0: set(handles.checkbox1,'Value',0); tomwalters@0: handles=aim_deletefile(handles,'nap'); tomwalters@0: handles=aim_deletefile(handles,'strobes'); tomwalters@0: handles=aim_deletefile(handles,'sai'); tomwalters@0: handles=aim_deletefile(handles,'usermodule'); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % calculate NAP tomwalters@0: % if get(handles.checkbox2,'Value')==1 tomwalters@0: if handles.info.calculate_nap==1 tomwalters@0: [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,4); tomwalters@0: handles.info.calculated_nap_module=generating_module; % this one is really calculated tomwalters@0: bmm=handles.data.bmm; tomwalters@0: callline=sprintf('res=%s(bmm,coptions);',generating_function); tomwalters@0: eval(callline); tomwalters@0: % store the result tomwalters@0: handles.data.nap=res; tomwalters@0: if handles.info.save_nap==1 tomwalters@0: aim_savefile(handles,res,handles.info.napname,'nap',generating_module,coptions,handles.all_options); tomwalters@0: end tomwalters@0: if handles.with_graphic==1 tomwalters@0: handles.info.nap_loaded=1; tomwalters@0: handles.info.current_plot=4; % display the new data tomwalters@0: % if this one is calculated new, then the further part has no relevance any more: tomwalters@0: set(handles.checkbox2,'Value',0); tomwalters@0: handles=aim_deletefile(handles,'strobes'); tomwalters@0: handles=aim_deletefile(handles,'sai'); tomwalters@0: handles=aim_deletefile(handles,'usermodule'); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % calculate Strobes tomwalters@0: % if get(handles.checkbox3,'Value')==1 tomwalters@0: if handles.info.calculate_strobes==1 tomwalters@0: [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,5); tomwalters@0: handles.info.calculated_strobes_module=generating_module; % this one is really calculated tomwalters@0: nap=handles.data.nap; tomwalters@0: callline=sprintf('[res,thres]=%s(nap,coptions);',generating_function); tomwalters@0: eval(callline); tomwalters@0: % store the result tomwalters@0: handles.data.strobes=res; tomwalters@0: if handles.info.save_strobes==1 tomwalters@0: aim_savefile(handles,res,handles.info.strobesname,'strobes',generating_module,coptions,handles.all_options); tomwalters@0: % if isoftype(handles.data.bmm,'frame') && getnrchannels(handles.data.bmm)==1 tomwalters@0: aim_savefile(handles,thres,handles.info.thresholdsname,'thresholds',generating_module,coptions,handles.all_options); tomwalters@0: % end tomwalters@0: end tomwalters@0: if handles.with_graphic==1 tomwalters@0: % if we only have one channel, then it is useful also to have the tomwalters@0: % thresholds: tomwalters@0: tomwalters@0: handles.data.thresholds=thres; tomwalters@0: handles.info.strobes_loaded=1; tomwalters@0: handles.info.current_plot=5; % display the new data tomwalters@0: tomwalters@0: % if this one is calculated new, then the further part has no relevance any more: tomwalters@0: set(handles.checkbox3,'Value',0); tomwalters@0: handles=aim_deletefile(handles,'sai'); tomwalters@0: handles=aim_deletefile(handles,'usermodule'); tomwalters@0: tomwalters@0: %TCW AIM2006 tomwalters@0: handles=aim_deletefile(handles,'pitch_image'); tomwalters@0: % This cleans up after pitchresonance and other dual output SAI tomwalters@0: % modules but will log an error to the command window if the tomwalters@0: % previous SAI module wasn't dual output. This is a bug and needs fixing. tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % calculate SAI tomwalters@0: % if get(handles.checkbox4,'Value')==1 tomwalters@0: if handles.info.calculate_sai==1 tomwalters@0: [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,6); tomwalters@0: handles.info.calculated_sai_module=generating_module; % this one is really calculated tomwalters@0: nap=handles.data.nap; tomwalters@0: strobes=handles.data.strobes; tomwalters@0: callline=sprintf('res=%s(nap,strobes,coptions);',generating_function); tomwalters@0: tomwalters@0: % add the soundfilename in case for ams tomwalters@0: if strcmp(generating_module,'ams') % for one channel we additionally pass the threshold: tomwalters@0: coptions.soundfile=handles.info.oldsignalwavename; tomwalters@0: else tomwalters@0: if getnrchannels(handles.data.bmm)==1 % for one channel we additionally pass the threshold: tomwalters@0: coptions.single_channel_threshold=handles.data.thresholds; tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: eval(callline); tomwalters@0: tomwalters@0: % This module is a special case, as we can have two sorts of output tomwalters@0: % from it, either the straight SAI (as seen in AIM 2003), or a pair of images: the pitch tomwalters@0: % image and resonance image. If the dual_output option is set to 1 in tomwalters@0: % the parameters file, then the module is taken to have two outputs. tomwalters@0: % One of these outputs, the resonance image, gets put in the old 'sai' tomwalters@0: % part of the structure, and the pitch image is placed in a new tomwalters@0: % structure, 'pitch_image'. tomwalters@0: if ~isfield(coptions, 'dual_output') tomwalters@0: coptions.dual_output=0; tomwalters@0: end tomwalters@0: tomwalters@0: % store the result tomwalters@0: if (coptions.dual_output==1) tomwalters@0: handles.data.sai=res{1}; tomwalters@0: handles.data.pitch_image=res{2}; tomwalters@0: else tomwalters@0: handles.data.sai=res; tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: %handles.data.sai=res; tomwalters@0: tomwalters@0: if handles.info.save_sai==1 tomwalters@0: if (coptions.dual_output==1) tomwalters@0: aim_savefile(handles,res{1},handles.info.sainame,'sai',generating_module,coptions,handles.all_options); tomwalters@0: aim_savefile(handles,res{2},handles.info.pitch_imagename,'pitch_image',generating_module,coptions,handles.all_options); tomwalters@0: else tomwalters@0: aim_savefile(handles,res,handles.info.sainame,'sai',generating_module,coptions,handles.all_options); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: if handles.with_graphic==1 tomwalters@0: handles.info.sai_loaded=1; tomwalters@0: handles.info.current_plot=6; % display the new data tomwalters@0: % if this one is calculated new, then the further part has no relevance any more: tomwalters@0: set(handles.checkbox4,'Value',0); tomwalters@0: handles=aim_deletefile(handles,'usermodule'); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: % calculate user module tomwalters@0: % if get(handles.checkbox8,'Value')==1 tomwalters@0: if handles.info.calculate_usermodule==1 tomwalters@0: [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,7); tomwalters@0: handles.info.calculated_usermodule_module=generating_module; % this one is really calculated tomwalters@0: tomwalters@0: sai=handles.data.sai; tomwalters@0: tomwalters@0: % TCW AIM2006 - to cary through pitch-resonance output to the latter tomwalters@0: % stages tomwalters@0: if ~isfield(coptions, 'dual_input') tomwalters@0: coptions.dual_input=0; tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: if coptions.dual_input==1 tomwalters@0: if isfield(handles.data, 'pitch_image') tomwalters@0: pitch_image=handles.data.pitch_image; tomwalters@0: callline=sprintf('res=%s(sai,pitch_image,coptions);',generating_function); tomwalters@0: else tomwalters@0: error(['The module ' generating_module ' is dual input, but the SAI module used before it'... tomwalters@0: ' was not dual output, please use a compatible module at this stage'... tomwalters@0: ' for more information, see the documentation at'... tomwalters@0: ' http://www.pdn.cam.ac.uk/cnbh/aim2006/']); tomwalters@0: end tomwalters@0: else tomwalters@0: if isfield(handles.data, 'pitch_image') tomwalters@0: error(['The module ' generating_module ' is not dual input, but the SAI module used before it'... tomwalters@0: ' was dual output, please use a compatible module at this stage'... tomwalters@0: ' for more information, see the documentation at'... tomwalters@0: ' http://www.pdn.cam.ac.uk/cnbh/aim2006/']); tomwalters@0: else tomwalters@0: callline=sprintf('res=%s(sai,coptions);',generating_function); tomwalters@0: end tomwalters@0: tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: eval(callline); tomwalters@0: tomwalters@0: % store the result tomwalters@0: handles.data.usermodule=res; tomwalters@0: if handles.info.save_usermodule==1 tomwalters@0: aim_savefile(handles,res,handles.info.usermodulename,'usermodule',generating_module,coptions,handles.all_options); tomwalters@0: end tomwalters@0: if handles.with_graphic==1 tomwalters@0: handles.info.usermodule_loaded=1; tomwalters@0: handles.info.current_plot=7; % display the new data tomwalters@0: % if this one is calculated new, then the further part has no relevance any more: tomwalters@0: set(handles.checkbox8,'Value',0); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % calculate movies tomwalters@0: % if get(handles.checkbox5,'Value')==1 tomwalters@0: if handles.info.calculate_movie==1 tomwalters@0: [generating_module,generating_function,coptions]=aim_getcurrent_module(handles,8); tomwalters@0: handles.info.calculated_movie_module=generating_module; % this one is really calculated tomwalters@0: % if strcmp(handles.info.current_usermodule_module,'none') tomwalters@0: % data=handles.data.sai; tomwalters@0: % else tomwalters@0: % data=handles.data.usermodule; tomwalters@0: % end tomwalters@0: tomwalters@0: % % if we dont know about the framerate, then get the framerate from the tomwalters@0: % % sai-module tomwalters@0: % if ~isfield(coptions,'frames_per_second') tomwalters@0: % [mod,func,opts]=aim_getcurrent_module(handles,7); % try in the usermodule tomwalters@0: % if ~isfield(opts,'frames_per_second') tomwalters@0: % [mod,func,opts2]=aim_getcurrent_module(handles,6); % try in the sai-module tomwalters@0: % if ~isfield(opts2,'frames_per_second') tomwalters@0: % disp('dont know about the framerate! Assuming 20'); tomwalters@0: % coptions.frames_per_second=20; % dont know about it tomwalters@0: % else tomwalters@0: % coptions.frames_per_second=opts2.frames_per_second; tomwalters@0: % end tomwalters@0: % else tomwalters@0: % coptions.frames_per_second=opts.frames_per_second; tomwalters@0: % end tomwalters@0: % end tomwalters@0: tomwalters@0: tomwalters@0: % in case of the screen-movie, we need some additional information: tomwalters@0: % if strcmp(handles.info.current_movie_module,'screen') tomwalters@0: if handles.with_graphic==1 tomwalters@0: if get(handles.checkbox7,'Value')==1 tomwalters@0: handles.all_options.movie.screen.withtime=1; tomwalters@0: coptions.withtime=1; tomwalters@0: else tomwalters@0: handles.all_options.movie.screen.withtime=0; tomwalters@0: coptions.withtime=0; tomwalters@0: end tomwalters@0: % and if we want to see the frequency profile: tomwalters@0: if get(handles.checkbox6,'Value')==1 tomwalters@0: handles.all_options.movie.screen.withfre=1; tomwalters@0: coptions.withfre=1; tomwalters@0: else tomwalters@0: handles.all_options.movie.screen.withfre=0; tomwalters@0: coptions.withfre=0; tomwalters@0: end tomwalters@0: % do we want to see the signal? tomwalters@0: if get(handles.checkbox10,'Value')==1 tomwalters@0: handles.all_options.movie.screen.withsignal=1; tomwalters@0: coptions.withsignal=1; tomwalters@0: else tomwalters@0: handles.all_options.movie.screen.withsignal=0; tomwalters@0: coptions.withsignal=0; tomwalters@0: end tomwalters@0: % scaling properties tomwalters@0: data_scale=slidereditcontrol_get_value(handles.slideredit_scale); tomwalters@0: handles.all_options.movie.screen.data_scale=data_scale; tomwalters@0: coptions.data_scale=data_scale; tomwalters@0: end tomwalters@0: % end tomwalters@0: tomwalters@0: % give the movie access to all data, which is useful for bmm, etc tomwalters@0: data=handles.data; tomwalters@0: tomwalters@0: tomwalters@0: % add a few names to the options, so that the movie can be saved tomwalters@0: if handles.with_graphic==1 tomwalters@0: uniqueworkingname=handles.info.uniqueworkingname; tomwalters@0: directoryname=handles.info.directoryname; tomwalters@0: % find out the name of this movie. Movies are numberd in their tomwalters@0: % order, so that no one is lost tomwalters@0: moviename=generate_new_movie_name(handles); tomwalters@0: newname=fullfile(handles.info.uniqueworkingname,moviename); tomwalters@0: coptions.moviename=newname; tomwalters@0: coptions.soundfilename=handles.info.signalwavename; tomwalters@0: coptions.handles=handles; tomwalters@0: callline=sprintf('%s(data,coptions);',generating_function); tomwalters@0: eval(callline); tomwalters@0: handles.info.movie_loaded=1; tomwalters@0: handles.info.last_movie_name_generated=moviename; tomwalters@0: set(handles.checkbox5,'Value',0); tomwalters@0: else tomwalters@0: coptions.moviename=sprintf('%s.%s.mov',handles.info.uniqueworkingname,handles.info.current_movie_module); tomwalters@0: coptions.soundfilename=handles.all_options.signal.signal_filename; tomwalters@0: coptions.handles=handles; tomwalters@0: callline=sprintf('%s(sai,coptions);',generating_function); tomwalters@0: eval(callline); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % return the pointer shape tomwalters@0: if handles.with_graphic==1 tomwalters@0: set(handles.figure1,'Pointer','arrow'); tomwalters@0: end