%%

	

% 	/* *************** SETTING DIMENSION VALUES ************** */
% 
% 	 Nfreq	 = (unsigned short)get_bat(bt, 0, "DIMENSION_FREQMAP", &Found);
% 	 Naud	 = (unsigned short)get_bat(bt, 0, "DIMENSION_AUDMAP", &Found);
% 	 Nmsc	 = (unsigned short)get_bat(bt, 0, "DIMENSION_EYEPOS", &Found);
% 	 Nmot	 = (unsigned short)get_bat(bt, 0, "DIMENSION_OUTPUT", &Found);
% 	 Nhidden = (unsigned short)get_bat(bt, 0, "DIMENSION_HIDDEN", &Found);
% 
% 
% 	 Sigma	 = get_bat(bt, 0, "SIGMA_MOTMAP", &Found);
% 	 Sig_freq= get_bat(bt, 0, "SIGMA_FREQMAP", &Found);
% 
% 	 Gain_freq= get_bat(bt, 0, "GAIN_FREQMAP", &Found);
% 	 Gain_pos = get_bat(bt, 0, "GAIN_EYEPOS", &Found);
% 	 Gain_mot = get_bat(bt, 0, "GAIN_MOTOR", &Found);
% 	 Exp_freq = get_bat(bt, 0, "EXP_FREQMAP", &Found);
% 
% 	 Eye_range = get_bat(bt, 0, "EYEPOS_RANGE", &Found);
% 	 Mot_range = get_bat(bt, 0, "MOTORERROR_RANGE", &Found);
% 	 Azi_range = get_bat(bt, 0, "AZIMUTH_RANGE", &Found);
% 	 Freq_min  = get_bat(bt, 0, "LOW_FREQUENCY_RANGE", &Found);
% 	 Freq_max  = get_bat(bt, 0, "HIGH_FREQUENCY_RANGE", &Found);
% 	 Int_range = get_bat(bt, 0, "INTENSITY_RANGE", &Found);
% 
% 
% 
% 	 LEARNING_RATE = get_bat(bt, 0, "LEARNING_RATE", &Found);
% 	 BIAS_HID = get_bat(bt, 0, "BIAS_HID", &Found);
% 	 Weights_range = get_bat(bt, 0, "WEIGHTS_RANGE", &Found);
% 
% 	 MOTORERROR_FLAG = (short)get_bat(bt, 0, "MOTORERROR_FLAG", &Found);
% 	 AZIMUTH_FLAG = (short)get_bat(bt, 0, "AZIMUTH_FLAG", &Found);
% 	 EYE_FLAG = (short)get_bat(bt, 0, "EYE_FLAG", &Found);
%  	 FREQUENCY_FLAG = (short)get_bat(bt, 0, "FREQUENCY_FLAG", &Found);
% 	 INTENSITY_FLAG = (short)get_bat(bt, 0, "INTENSITY_FLAG", &Found);
% 	 RAND_FLAG = (short)get_bat(bt, 0, "RANDOM_FLAG", &Found);
% 
% 	 CONTINUE_FLAG = (short)get_bat(bt, 0, "CONTINUE_FLAG", &Found);
% 	 STORE_FLAG = (short)get_bat(bt, 0, "STORE_FLAG", &Found);
% 	 DEMO_FLAG = (short)get_bat(bt, 0, "DEMO_FLAG", &Found);
% 	 STORE = (unsigned long)get_bat(bt, 0, "STORE", &Found);
% 	 WAIT = (unsigned long)get_bat(bt, 0, "DEMO_WAIT", &Found);
% 
% 
% 	/* ************* CREATING VECTORS AND MATRICES *********** */
% 
% 	 Audmap        = vector(1, Naud);
% 	 Eyepos        = matrix(1, 2, 1, Nmsc);
% 	 Cochlea       = matrix(1, 2, 1, Nfreq);
% 
% 	 Hidden        = vector(1, Nhidden);
% 
% 	 MotorError    = vector(1, Nmot);
% 	 Teacher       = vector(1, Nmot);
% 	 Error_hm      = vector(1, Nmot);
% 	 Error_ah      = vector(1, Nhidden);
% 
% 	 Bias_HID      = vector(1, Nhidden);
% 	 Bias_MOT      = vector(1, Nmot);
% 	 Bias_AUD      = vector(1, Naud);
% 
% 	 Weights_AH    = matrix(1, Nhidden, 1, Naud);
% 	 Weights_CA    = matrix(1, Naud, 1, 2 * Nfreq);
% 	 Weights_EH    = matrix(1, Nhidden, 1, 2 * Nmsc);
% 	 Weights_HM    = matrix(1, Nmot, 1, Nhidden);
% 
% /* ************************************************************************************************* */
% 

		     

%%
% /* ******************************* CALC COCHLEA-LAYER ACTIVATION VALUES ****************** */
% /*
%    This function calculates the activity values of the cochlea layers (left and right) which are presented in a forward
%    direction to the audmap layer
% */
% 	 
%        /*
% 	  function that generates Gaussian receptive field profile:
% 	  F = exp( -[(x-x0)^2]/[2sigma^2] )
%        */


%void coch_input(cochlea, azi, nstimuli, Is, freq_flag)

freq_flag=1;
Nfreq=30;
Freq_min=100;
Freq_max=10000;
Sig_freq= 


azi=30;
nstimuli=4;
Is=1;

     cochlea=zeros(2,Nfreq);

	 %/* determine cochlear location in frequency map */

	 m = (Nfreq - 1) / (log(Freq_max) - log(Freq_min));

		for k=1:1:nstimuli
				
				if (not(freq_flag))
					
		 			i0 = randi(10,1,1);
					m = (Nfreq - 1) / (log(Freq_max) - log(Freq_min));
					logf =  ((i0 - 1.0)/m) + log(Freq_min);
					c_fr =  exp(logf);
				end
					
				if (freq_flag)
					c_fr = (Freq_max - Freq_min) / 2.0;
				end
					
				
                % 	 /* nonlinear, saturating, azimuth dependent activity for both cochleae:
                % 	    the threshold is put at 90 deg left and right */
                if (azi < -90.0) rate_r = 0.0;
                    else rate_r = Is + (Gain_freq * (1 - exp( -(azi + 90.0) / Exp_freq) ));
				end
	            if (azi > 90.0)  rate_l = 0.0;
	                else rate_l = Is + (Gain_freq * (1 - exp( +(azi - 90.0) / Exp_freq) ));
				end


				for i = 1:1:Nfreq
					arg = ( sqrt(i-i0) / (2 * sqrt(Sig_freq)) );
					cochlea(1,i) = cochlea(1,i) + rate_r * exp(-arg);
					    if (cochlea(1,i) > rate_r)  cochlea(1,i) = rate_r; end
					cochlea(2,i) = cochlea(2,i) + rate_l * exp(-arg);
					    if (cochlea(2,i) > rate_l)  cochlea(2,i) = rate_l; end
				end
		end % /* end k loop */
	%/* *************** END COCHLEA OUTPUT *************** */

