Home > . > DIVA_Cochlea.m

DIVA_Cochlea

PURPOSE ^

DIVA_Cochlea Cochlear model

SYNOPSIS ^

function out=DIVA_Cochlea(action,varargin);

DESCRIPTION ^

 DIVA_Cochlea Cochlear model

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

 DIVA_Cochlea('sound',s,fs,delay);
 Sends the sound formants in vector s to the cochlear model
 with a given delay. The module computes the cochlear
 representation (simple spectrogram) of this sound for internal
 purposes, and sends FORMANTS to the AuditoryCortex module.

 Current DIVA_AuditoryCortex properties are: (* requires re-initialization)
   *  delayToAuditoryCortex  : delay (in seconds) for signals to AuditoryCortex

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function out=DIVA_Cochlea(action,varargin);
0002 % DIVA_Cochlea Cochlear model
0003 %
0004 % DIVA_Cochlea('init' [,SessionName]);          Initializes the module
0005 % DIVA_Cochlea('save' [,SessionName] );         Saves state
0006 % DIVA_Cochlea('exit');                         Exits the module (without saving)
0007 % DIVA_Cochlea(PropertyName [,PropertyValue] )  Reads and writes internal model properties
0008 %
0009 % DIVA_Cochlea('sound',s,fs,delay);
0010 % Sends the sound formants in vector s to the cochlear model
0011 % with a given delay. The module computes the cochlear
0012 % representation (simple spectrogram) of this sound for internal
0013 % purposes, and sends FORMANTS to the AuditoryCortex module.
0014 %
0015 % Current DIVA_AuditoryCortex properties are: (* requires re-initialization)
0016 %   *  delayToAuditoryCortex  : delay (in seconds) for signals to AuditoryCortex
0017 %
0018 
0019   out=[];
0020   global DIVA_Cochlea_data
0021   if nargin<1,
0022     action='init';
0023   end
0024 
0025   switch(lower(action)),
0026     %%%%%%%%%%%%%%%% INITIALIZATION %%%%%%%%%
0027     %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%
0028    case 'init',
0029     SessionFolder=strcat(DIVA('SessionFolder'),filesep);
0030     if nargin<2 | isempty(varargin{1}),
0031       initfile='';
0032     else,
0033       initfile=[SessionFolder,'Session_',varargin{1},filesep,mfilename,'.mat'];
0034     end
0035 
0036     if isempty(initfile) | isempty(dir(initfile)),
0037       disp([mfilename, ' : Defining new session...']);
0038       DIVA_Cochlea_data.params=struct(...
0039           'fs',10000,...
0040           'delayToForwardModel',.05,...
0041           'delayToAuditoryCortex',.005);
0042     else,
0043       data=load(initfile,'-mat');
0044       DIVA_Cochlea_data.params=data.params;
0045     end
0046     out={};
0047 
0048    case 'save',
0049     SessionFolder = strcat(DIVA('SessionFolder'),filesep);
0050     if nargin<2,
0051       initfile=[SessionFolder,'Session_','default',filesep,mfilename,'.mat'];
0052     else,
0053       initfile=[SessionFolder,'Session_',varargin{1},filesep,mfilename,'.mat'];
0054     end
0055     params=DIVA_Cochlea_data.params;
0056     save(initfile,'params');
0057 
0058    case 'exit',
0059     clear DIVA_Cochlea_data;
0060 
0061    case 'disp',
0062     disp(DIVA_Cochlea_data.params);
0063     out=fieldnames(DIVA_Cochlea_data.params);
0064 
0065     %%%%%%%%%%%%%%%% ACTION %%%%%%%%%%%%%%%%%
0066     %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%
0067 
0068    case 'sound',
0069     % JSB: Do not compute frequency components, simple spectrogram
0070     % is all.  Expect formant input, pass on formant output
0071 
0072     s=varargin{1};
0073 
0074     if nargin<4 | isempty(varargin{3}),
0075       delay=0;
0076     else,
0077       delay=varargin{3};
0078     end
0079 
0080     DIVA_Cochlea_data.params.s = s;
0081     out = s;
0082     % compute internal spectrogram for visualization and
0083     % informational purposes only...Soon!
0084 
0085     % projects output
0086     if ~nargout,
0087       DIVA('AuditoryCortex','sound',cat(2,out,nan+zeros(size(out,1),1)),...
0088            delay+DIVA_Cochlea_data.params.delayToAuditoryCortex);
0089     end
0090     
0091     % Compute spectrogram
0092    case 'spectrogram',
0093     y=varargin{1};
0094     win=hamming(round(0.02*DIVA_Cochlea_data.params.fs));
0095     
0096     if(nargout),
0097       if(strcmp(release_version,'R2006b')),
0098         [Y,f,t]=spectrogram(filtfilt([1 -0.95],1,y),win,...
0099                             length(win)-round(0.001*DIVA_Cochlea_data.params.fs),...
0100                             256,DIVA_Cochlea_data.params.fs);
0101       else,
0102         [Y,f,t]=specgram(filtfilt([1 -0.95],1,y),256,DIVA_Cochlea_data.params.fs,...
0103                          win,length(win)-round(0.001*DIVA_Cochlea_data.params.fs));
0104       end
0105       out={Y,f,t};
0106       %figure,imagesc(abs(Y))
0107     end
0108 
0109    otherwise,
0110     if isfield(DIVA_Cochlea_data.params,action),
0111       if nargin<2,
0112         out=DIVA_Cochlea_data.params.(action);
0113       else,
0114         DIVA_Cochlea_data.params.(action)=varargin{1};
0115       end
0116     else,
0117       warning('DIVA_Cochlea: wrong argument');
0118     end
0119   end

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