improved noiseficurves projects

This commit is contained in:
2017-01-22 16:09:16 +01:00
parent 5d2beb12eb
commit 4060b1bbae
8 changed files with 167 additions and 36 deletions

View File

@@ -0,0 +1,8 @@
function rates = ficurve(trials, inputs, tmax, D)
% compute f-I curve.
rates = zeros(length(inputs), 1);
for k=1:length(inputs)
spikes = lifspikes(trials, inputs(k), tmax, D);
rates(k) = firingrate(spikes, 0.0, tmax);
end
end

View File

@@ -0,0 +1,9 @@
function rate = firingrate(spikes, tmin, tmax)
% mean firing rate between tmin and tmax.
rates = zeros(length(spikes), 1);
for i = 1:length(spikes)
times= spikes{i};
rates(i) = length(times((times>=tmin)&(times<=tmax)))/(tmax-tmin);
end
rate = mean(rates);
end

View File

@@ -0,0 +1,11 @@
function isih(spikes, bins)
isis = [];
for i = 1:length(spikes)
times= spikes{i};
isis = [isis; diff(times(:))];
end
[h, b] = hist(isis, bins);
h = h / sum(h) / (bins(2)-bins(1));
bar(1000.0*b, h);
xlim([0 1000.0*b(end)])
end

View File

@@ -0,0 +1,33 @@
function spikes = lifspikes(trials, input, tmax, D)
% Generate spike times of a leaky integrate-and-fire neuron
% trials: the number of trials to be generated
% input: the stimulus either as a single value or as a vector
% tmax: 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;
dt = 1e-4;
n = ceil(tmax/dt);
spikes = cell(trials, 1);
for k=1:trials
times = [];
j = 1;
v = vreset;
noise = sqrt(2.0*D)*randn(n, 1)/sqrt(dt);
for i=1:n
v = v + (- v + noise(i) + input)*dt/tau;
if v >= vthresh
v = vreset;
times(j) = i*dt;
j = j + 1;
end
end
spikes{k} = times;
end
end

View File

@@ -0,0 +1,26 @@
%% general settings for the model neuron:
trials = 10;
tmax = 50.0;
%% f-I curves:
figure()
Ds = [0, 0.001, 0.01, 0.1];
for j = 1:length(Ds)
D = Ds(j);
inputs = 0.0:0.5:20.0;
rates = ficurve(trials, inputs, tmax, D);
plot(inputs, rates);
hold on;
end
hold off;
%% spike raster and CVs
input = 12.0;
for j = 1:length(Ds)
D = Ds(j);
spikes = lifspikes(trials, input, tmax, D);
subplot(4, 2, 2*j-1);
spikeraster(spikes, 0.0, 1.0);
subplot(4, 2, 2*j);
isih(spikes, [0:0.001:0.04]);
end

View File

@@ -0,0 +1,30 @@
function spikeraster(spikes, tmin, tmax)
% Display a spike raster of the spike times given in spikes.
%
% spikeraster(spikes, tmax)
% spikes: a cell array of vectors of spike times in seconds
% tmin: plot spike raster starting at tmin seconds
% tmax: plot spike raster upto tmax seconds
ntrials = length(spikes);
for k = 1:ntrials
times = spikes{k};
times = times((times>=tmin) & (times<=tmax));
if tmax < 1.5
times = 1000.0*times; % conversion to ms
end
for i = 1:length( times )
line([times(i) times(i)],[k-0.4 k+0.4], 'Color', 'k');
end
end
if (tmax-tmin) < 1.5
xlabel('Time [ms]');
xlim([1000.0*tmin 1000.0*tmax]);
else
xlabel('Time [s]');
xlim([tmin tmax]);
end
ylabel('Trials');
ylim([0.3 ntrials+0.7 ]);
end