Home > . > DIVA_AuditoryCortex.m

DIVA_AuditoryCortex

PURPOSE ^

DIVA_AuditoryCortex Auditory cortex model

SYNOPSIS ^

function out=DIVA_AuditoryCortex(varargin);

DESCRIPTION ^

 DIVA_AuditoryCortex Auditory cortex model

 This model computes the cortical representation of a
 a sound and its difference with the target sound.

 DIVA_AuditoryCortex('init' [,SessionName]);          Initializes the module
 DIVA_AuditoryCortex('save' [,SessionName] );         Saves state
 DIVA_AuditoryCortex('exit');                         Exits the module (without saving)
 DIVA_AuditoryCortex(PropertyName [,PropertyValue] )  Reads and writes internal model
                                                      properties

 DIVA_AuditoryCortex('sound',s1);
 The model computes the cortical sound representation of the sound s1
 and passes it to the SoundMap area for categorical perception.

 DIVA_AuditoryCortex('target',s2,'sound',s1);
 The model computes the difference between the target signal s2
 and the sound signal s1 and sends it to motor cortex (DIVA_MotorCortex).

 The signal s1 is a cochlear representation of a sound (Formant
 vector, see DIVA_Cochlea) and the signal s2 is a categorical
 representation (Formant vector with min and max values, see
 DIVA_SoundMap) of the sound. The model stores the weights, 
 WeightsFromTargets used to compare incoming auditory input with
 stored weights

 Current DIVA_AuditoryCortex properties are: (* requires re-initialization)
  *  delayToSoundMap        : delay (in seconds) for signals to SoundMap
  *  delayToMotorCortex     : delay (in seconds) for signals to SoundMap
     WeightsFromTargets     : weights for target signals

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function out=DIVA_AuditoryCortex(varargin);
0002 % DIVA_AuditoryCortex Auditory cortex model
0003 %
0004 % This model computes the cortical representation of a
0005 % a sound and its difference with the target sound.
0006 %
0007 % DIVA_AuditoryCortex('init' [,SessionName]);          Initializes the module
0008 % DIVA_AuditoryCortex('save' [,SessionName] );         Saves state
0009 % DIVA_AuditoryCortex('exit');                         Exits the module (without saving)
0010 % DIVA_AuditoryCortex(PropertyName [,PropertyValue] )  Reads and writes internal model
0011 %                                                      properties
0012 %
0013 % DIVA_AuditoryCortex('sound',s1);
0014 % The model computes the cortical sound representation of the sound s1
0015 % and passes it to the SoundMap area for categorical perception.
0016 %
0017 % DIVA_AuditoryCortex('target',s2,'sound',s1);
0018 % The model computes the difference between the target signal s2
0019 % and the sound signal s1 and sends it to motor cortex (DIVA_MotorCortex).
0020 %
0021 % The signal s1 is a cochlear representation of a sound (Formant
0022 % vector, see DIVA_Cochlea) and the signal s2 is a categorical
0023 % representation (Formant vector with min and max values, see
0024 % DIVA_SoundMap) of the sound. The model stores the weights,
0025 % WeightsFromTargets used to compare incoming auditory input with
0026 % stored weights
0027 %
0028 % Current DIVA_AuditoryCortex properties are: (* requires re-initialization)
0029 %  *  delayToSoundMap        : delay (in seconds) for signals to SoundMap
0030 %  *  delayToMotorCortex     : delay (in seconds) for signals to SoundMap
0031 %     WeightsFromTargets     : weights for target signals
0032 %
0033 
0034 
0035 out=[];
0036 global DIVA_AuditoryCortex_data
0037 
0038 %%%%%%%%%%%%%%%% INITIALIZATION %%%%%%%%%
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',[],... % stored as matrix [[lower;upper]:ntimepoints]
0057           'error_sound',[],...        % auditory error
0058           'nFormants',3);             % Dimension of auditory representation
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     % Channels
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', % overloaded operator (plot to GUI)
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     %%%%%%%%%%%%%%%% ACTION %%%%%%%%%%%%%%%%%
0096     %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%
0097 
0098    case 'target'
0099     % current sound target projection
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       % if there is no current target, pass the sound representation to the SoundMap area
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         % Send to Categorical Auditory Cortex
0123         DIVA('AuditoryCortexCategorical','sound',out,...
0124              DIVA_AuditoryCortex_data.params.delayToSoundMap);
0125       end
0126 
0127     else,
0128       % if there is a current target, compute the error and send it
0129       % to the PerceptionProduction area
0130       
0131       % indices from SoundMap are real, not integer (see
0132       % AuditoryCortexCategorical for more), so compute appropriate
0133       % integer indicies
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         % Non-stationary target (i.e. CV*)
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         % Steady-state target (i.e. V)
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       % Compute Error between current produced auditory signal and
0150       % stored targets
0151       %
0152       % Auditory error assumed 0 when within stored target regions
0153       % (upper and lower below)
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      % Calculate mean auditory target in case developers want to
0165      % add additional emphasis on moving to the center of the
0166      % target region, currently not used!
0167      for n=1:DIVA_AuditoryCortex_data.params.nFormants,
0168        meansound(n,:) = mean([upper(n,:);lower(n,:)],1);
0169      end     
0170      
0171      % Determine error between auditory signal and target regions
0172      out= min(0,upper-currentsound)+max(0,lower-currentsound);
0173      
0174      % Determine error between auditory signal and target regions with force towards center
0175      %  out = (meansound-currentsound).*(currentsound>upper) + ...
0176      %        (meansound-currentsound).*(currentsound<lower) + ...
0177      %        (meansound-currentsound)*0.1*(currentsound<=upper & currentsound>=lower);
0178      
0179      
0180      % [fmt,errorIdx]=find(any(currentsound<(upper+0.01*(upper-lower)) & ...
0181      %                         currentsound>(lower-0.01*(upper-lower))));
0182      
0183      % Add inverse-gaussian weighted error for areas within the target region
0184      %if(any(currentsound<(upper+0.05*(upper-lower)) & currentsound>(lower-0.05*(upper-lower))))
0185      % if(~isempty(errorIdx))
0186      %   errorWeightMax=normpdf(0,0,[upper(:,errorIdx)-lower(:,errorIdx)]/3); % for 3*std 97% variance
0187      %   errorWeight=...
0188      %       (1-normpdf((meansound(:,errorIdx)-currentsound(:,errorIdx)),0,...
0189      %                  [upper(:,errorIdx)-lower(:,errorIdx)]/3)/errorWeightMax) *...
0190      %       (currentsound(:,errorIdx)-meansound(:,errorIdx));
0191      %   out(:,errorIdx)= out(:,errorIdx)+errorWeight;
0192   
0193 % end
0194      if ~nargout, % Send auditory error to MotorCortex
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, % Attempt to plot relevant information in on the
0210                  % GUI and ModelStatePlot
0211       DIVA('ModelStatePlot','AuditoryCortex','sound');
0212       DIVA('GUI','AC_WeightsFromTargets','update');
0213       DIVA('GUI','other_weights','auditory');
0214     end
0215 
0216    otherwise, % Handle AuditoryCortex Parameters (read/write)
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

Generated on Tue 27-Mar-2007 12:06:24 by m2html © 2003