From b698144eb6cf0af32fa5bc3d8cbaabfca23b29d6 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sat, 21 Jan 2017 12:25:14 +0100 Subject: [PATCH] added lifspikes.m to fano time project --- projects/project_fano_time/lifadaptspikes.m | 53 --------------------- projects/project_fano_time/lifspikes.m | 35 ++++++++++++++ 2 files changed, 35 insertions(+), 53 deletions(-) delete mode 100644 projects/project_fano_time/lifadaptspikes.m create mode 100644 projects/project_fano_time/lifspikes.m diff --git a/projects/project_fano_time/lifadaptspikes.m b/projects/project_fano_time/lifadaptspikes.m deleted file mode 100644 index 2ef1874..0000000 --- a/projects/project_fano_time/lifadaptspikes.m +++ /dev/null @@ -1,53 +0,0 @@ -function spikes = lifadaptspikes( trials, input, tmaxdt, D, tauadapt, adaptincr ) -% Generate spike times of a leaky integrate-and-fire neuron -% with an adaptation current -% trials: the number of trials to be generated -% input: the stimulus either as a single value or as a vector -% tmaxdt: in case of a single value stimulus the duration of a trial -% in case of a vector as a stimulus the time step -% D: the strength of additive white noise -% tauadapt: adaptation time constant -% adaptincr: adaptation strength - - tau = 0.01; - if nargin < 4 - D = 1e0; - end - if nargin < 5 - tauadapt = 0.1; - end - if nargin < 6 - adaptincr = 1.0; - end - vreset = 0.0; - vthresh = 10.0; - dt = 1e-4; - - if max( size( input ) ) == 1 - input = input * ones( ceil( tmaxdt/dt ), 1 ); - else - dt = tmaxdt; - end - spikes = cell( trials, 1 ); - for k=1:trials - times = []; - j = 1; - v = vreset; - a = 0.0; - noise = sqrt(2.0*D)*randn( length( input ), 1 )/sqrt(dt); - for i=1:length( noise ) - v = v + ( - v - a + noise(i) + input(i))*dt/tau; - a = a + ( - a )*dt/tauadapt; - if v >= vthresh - v = vreset; - a = a + adaptincr/tauadapt; - spiketime = i*dt; - if spiketime > 4.0*tauadapt - times(j) = spiketime - 4.0*tauadapt; - j = j + 1; - end - end - end - spikes{k} = times; - end -end diff --git a/projects/project_fano_time/lifspikes.m b/projects/project_fano_time/lifspikes.m new file mode 100644 index 0000000..c1bec46 --- /dev/null +++ b/projects/project_fano_time/lifspikes.m @@ -0,0 +1,35 @@ +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(1); + 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