// genesis
// stimulus for molecular layer
// rmaex  March 2017
// include sine.g (already included in Parallel_fiber.g // include Stell_layer_const.g



echo creating rectangular grating

include rectangular-grating.g

float sagittal_span = {ylength_mollayer}
float spatial_wavelength = {sagittal_span} * 0.5 
float temporal_wavelength = 100000 // 10 // 0.25

make_rectangulargrating  {sagittal_span} {spatial_wavelength} {temporal_wavelength}

echo   {sagittal_span} {spatial_wavelength} {temporal_wavelength}

// activate all parallel fibers at a specified position
  int  i
  int  cell_index

   for (i = 0; i < {number_parallel_fibers}; i = i + 1)

       cell_index = {round {{getfield  /molecular_layer/parallel_fiber[{i}] y} / {sagittal_span} * {number_PF_cells}}}

       addmsg /rectangulargrating[{cell_index}]  /molecular_layer/parallel_fiber[{i}] RATE output
   end // for


/*  this is used for sinusoidal stimulation of a parallel fibre beam   */

echo  creating second sine

   create sine /sine2
   setfield /sine2 period {2.048} 
   setfield /sine2 phase 0  background_level 0 // {parallel_fiber_firing_rate}
   setfield /sine2 amplitude 1 

// here one or more beams is to be selected [0 - 127]
  addmsg /sine2 /rectangulargrating[24] PLUS output
//  addmsg /sine2 /rectangulargrating[12] PLUS output
//  addmsg /sine2 /rectangulargrating[28] PLUS output
   useclock /sine2 1



/*  the following is used for pulse stimulation of a parallel fibre beam   */

/*
// single pulse

   create pulsegen /pulse_E
     setfield ^ delay1 1.0  \
                width1 0.05 \
                level1 49 \
                baselevel 0
  addmsg /pulse_E /rectangulargrating[24] PLUS output

*/


/*
// doublet

   create pulsegen /pulse_E
     setfield ^ delay1 1  \
                width1 0.005 \
                level1 39 \
                delay2 0.015 \
                level2 39 \
                width2 0.005 \
                baselevel 0
  addmsg /pulse_E /rectangulargrating[32] PLUS output
*/

/*
// bipolar
   create pulsegen /pulse_E
     setfield ^ delay1 2  \
                width1 0.005 \
                level1 19 \
                delay2 0.005 \
                level2 -1 \
                width2 0.095 \
                baselevel 0
  addmsg /pulse_E /rectangulargrating[32] PLUS output
*/