36 lines
904 B
Matlab
36 lines
904 B
Matlab
function spikes = lifspikes(trials, input, tmax)
|
|
% Generate spike times of a leaky integrate-and-fire neuron.
|
|
% trials: the number of trials to be generated
|
|
% input: the stimulus intensity
|
|
% tmax: the duration of a trial
|
|
% D: the strength of additive white noise
|
|
|
|
tau = 0.01;
|
|
if nargin < 4
|
|
D = 1e0;
|
|
end
|
|
vreset = 0.0;
|
|
vthresh = 10.0;
|
|
D = 0.01;
|
|
dt = 5e-5;
|
|
|
|
n = ceil(tmax/dt);
|
|
spikes = cell(trials, 1);
|
|
for k=1:trials
|
|
times = [];
|
|
j = 1;
|
|
v = vreset + (vthresh-vreset)*rand();
|
|
noise = sqrt(2.0*D)*randn(n, 1)/sqrt(dt);
|
|
for i=1:length(noise)
|
|
v = v + (- v + noise(i) + input)*dt/tau;
|
|
if v >= vthresh
|
|
v = vreset;
|
|
spiketime = i*dt;
|
|
times(j) = spiketime;
|
|
j = j + 1;
|
|
end
|
|
end
|
|
spikes{k} = times;
|
|
end
|
|
end
|