0001 function out=DIVA_AuditoryCortex(varargin);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 out=[];
0036 global DIVA_AuditoryCortex_data
0037
0038
0039
0040
0041 for indexargin=1:2:nargin,
0042 switch(varargin{indexargin}),
0043 case 'init',
0044 SessionFolder=strcat(DIVA('SessionFolder'),filesep);
0045 if nargin<indexargin+1 | isempty(varargin{indexargin+1}),
0046 initfile='';
0047 else,
0048 initfile=[SessionFolder,'Session_',varargin{indexargin+1},filesep,mfilename,'.mat'];
0049 end
0050
0051 if isempty(initfile) || isempty(dir(initfile)),
0052 disp([mfilename, ' : Defining new session...']);
0053 DIVA_AuditoryCortex_data.params=struct(...
0054 'delayToSoundMap',.005,...
0055 'delayToMotorCortex',.005,...
0056 'WeightsFromTargets',[],...
0057 'error_sound',[],...
0058 'nFormants',3);
0059
0060 else,
0061 data=load(initfile,'-mat');
0062 DIVA_AuditoryCortex_data.params=data.params;
0063 end
0064 DIVA_AuditoryCortex_data.params.TimeStep=DIVA('TimeStep');
0065 DIVA_AuditoryCortex_data.params.current.target=[];
0066 DIVA_AuditoryCortex_data.params.current.sound=[];
0067
0068 out={'target','sound'};
0069
0070 case 'save',
0071 SessionFolder=strcat(DIVA('SessionFolder'),filesep);
0072 if nargin<indexargin+1,
0073 initfile=[SessionFolder,'Session_','default',filesep,mfilename,'.mat'];
0074 else,
0075 initfile=[SessionFolder,'Session_',varargin{indexargin+1},filesep,mfilename,'.mat'];
0076 end
0077 params=DIVA_AuditoryCortex_data.params;
0078 save(initfile,'params');
0079
0080 case 'exit',
0081 clear DIVA_AuditoryCortex_data;
0082
0083 case 'disp',
0084 disp(DIVA_AuditoryCortex_data.params);
0085 out=fieldnames(DIVA_AuditoryCortex_data.params);
0086
0087 case 'WeightsFromTargets',
0088 if indexargin==nargin,
0089 out=DIVA_AuditoryCortex_data.params.(varargin{indexargin});
0090 else,
0091 DIVA_AuditoryCortex_data.params.(varargin{indexargin})=varargin{indexargin+1};
0092 DIVA('GUI','AC_WeightsFromTargets','target');
0093 end
0094
0095
0096
0097
0098 case 'target'
0099
0100 DIVA_AuditoryCortex_data.params.current.target = varargin{indexargin+1};
0101 if ~nargout,
0102 DIVA('ModelStatePlot','AuditoryCortex','target');
0103 end
0104
0105 case 'sound'
0106 currentsound = varargin{indexargin+1};
0107
0108 if isempty(DIVA_AuditoryCortex_data.params.current.target),
0109
0110 if ~nargout,
0111 oldcurrentsound = DIVA_AuditoryCortex_data.params.current.sound;
0112 else,
0113 oldcurrentsound = [];
0114 end
0115
0116 out = currentsound;
0117
0118 if ~nargout,
0119 DIVA_AuditoryCortex_data.params.current.sound = ...
0120 [DIVA_AuditoryCortex_data.params.current.sound,currentsound];
0121
0122
0123 DIVA('AuditoryCortexCategorical','sound',out,...
0124 DIVA_AuditoryCortex_data.params.delayToSoundMap);
0125 end
0126
0127 else,
0128
0129
0130
0131
0132
0133
0134 idx = union(floor(DIVA_AuditoryCortex_data.params.current.target),...
0135 ceil(DIVA_AuditoryCortex_data.params.current.target));
0136
0137 if length(idx)>1,
0138
0139 DIVA_AuditoryCortex_data.params.current.targetsound = ...
0140 fastinterp1(idx,DIVA_AuditoryCortex_data.params.WeightsFromTargets(:,idx),...
0141 DIVA_AuditoryCortex_data.params.current.target);
0142 else,
0143
0144 DIVA_AuditoryCortex_data.params.current.targetsound = ...
0145 DIVA_AuditoryCortex_data.params.WeightsFromTargets(:,idx*ones(1,size(DIVA_AuditoryCortex_data.params.current.target,2)));
0146 end
0147
0148
0149
0150
0151
0152
0153
0154
0155 upper = DIVA_AuditoryCortex_data.params.current.targetsound(4:6,:);
0156 lower = DIVA_AuditoryCortex_data.params.current.targetsound(1:3,:);
0157
0158 if ~nargout,
0159 oldcurrentsound = DIVA_AuditoryCortex_data.params.current.sound;
0160 else,
0161 oldcurrentsound = [];
0162 end
0163
0164
0165
0166
0167 for n=1:DIVA_AuditoryCortex_data.params.nFormants,
0168 meansound(n,:) = mean([upper(n,:);lower(n,:)],1);
0169 end
0170
0171
0172 out= min(0,upper-currentsound)+max(0,lower-currentsound);
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194 if ~nargout,
0195 DIVA_AuditoryCortex_data.params.current.sound = ...
0196 [DIVA_AuditoryCortex_data.params.current.sound,currentsound];
0197 DIVA_AuditoryCortex_data.params.current.error=out;
0198 DIVA('MotorCortex','error_sound',...
0199 DIVA_AuditoryCortex_data.params.current.error,...
0200 DIVA_AuditoryCortex_data.params.delayToMotorCortex);
0201 end
0202 DIVA_AuditoryCortex_data.params.current.target=[];
0203 end
0204
0205 if any(any(isnan(varargin{indexargin+1}))),
0206 DIVA_AuditoryCortex_data.params.current.sound=[];
0207 end
0208
0209 if ~nargout,
0210
0211 DIVA('ModelStatePlot','AuditoryCortex','sound');
0212 DIVA('GUI','AC_WeightsFromTargets','update');
0213 DIVA('GUI','other_weights','auditory');
0214 end
0215
0216 otherwise,
0217 if isfield(DIVA_AuditoryCortex_data.params,varargin{indexargin}),
0218 if indexargin==nargin,
0219 out=DIVA_AuditoryCortex_data.params.(varargin{indexargin});
0220 else,
0221 DIVA_AuditoryCortex_data.params.(varargin{indexargin})=varargin{indexargin+1};
0222 end
0223 else,
0224 warning('DIVA_AuditoryCortex: wrong argument');
0225 end
0226
0227 end
0228 end