Hints for Lab 6

Neuron Firing Simulation:

Write a function like this:

```    function neuron(dis, tot_time, timestep, Mean)
...
end
```
The parameter dis is 0 if the value of Vcc will be fixed at 5 and the threshold voltage Vthr will be fixed at 1; is 1 if the threshold voltage Vthr will be 1 plus a number determined randomly (recalculated for each spike) from a uniform distribution with mean Mean no greater than 1.5, and Vcc will be fixed at 5 (simulates a leaky neuron); is 2 if Vcc will be 5 plus a number determined randomly for each spike from an exponential distribution of mean Mean, and Vthr will be fixed at 1; and is 3 if Vthr will be fixed at 1, Vcc will be fixed at 5, and the start time of a spike will be 5 plus a number determined randomly from the continuous version of the geometric distribution of mean Mean.

The parameter tot_time is the total time for the simulation in milliseconds.

The parameter timestep is the interval between simulation calculations in milliseconds.

The parameter Mean is in milliseconds when dis is 3 and volts otherwise. The first letter is upper case to prevent conflict with the Matlab function called mean.

Write functions to set Vcc, Vth, and ISI from the input parameters. For example,

```   function res = getVth(dis,Mean)
if dis ~= 1
res = 1;
else
res = min(Mean,1.5)*rand(1) + 1;
end
end
```
and
```   function res = getVcc(dis,Mean)
if dis ~= 2
res = 5;
else
res = log(rand(1))/log(1-(1/Mean)) + 5;
end
end
```
and put these functions into separate files with name prefixes that match the function names. Then the first few lines of the neuron function will look like this:
```   RC = 70;                  % 70 millisecond time constant
Vcc = getVcc(dis,Mean);   % neuron target voltage
Vth = getVth(dis,Mean);   % neuron threshold voltage
ISI = getISI(dis,Mean);   % interspike interval in milliseconds
```

Let q be the most recent iteration on which a neuron spike began. Then the voltage on the ith iteration is

```   Vneuron(i) = (1-exp(-timestep*(i-q)/RC))*Vcc;
```
unless this voltage becomes greater than Vth or if the time since the last peak is less than the ISI period - in both cases Vneuron(i) = 0.

Use a variable, say p, to record the time at which the last peak occurred. Then the time since the last peak is

```   timestep*(i-p)
```