Leaky integrate and fire model of neuron

"synaptic" input current

Isyn[t_] := 2+Cos[t] + 3Cos[Sqrt[2]t]- Cos[Sqrt[5]t];
τin = 2Pi/Sqrt[5];

Plot[
Isyn[t],{t,0,60},
AspectRatio->1/(4*GoldenRatio),
ImageSize->720
]

output current assuming integration and leakage

v0 = -70;
vthreshold = -55;
μ = 0.3;τleak = 1/μ;
k = 3;
v[t_,t0_] := 
 v0 + k*E^(-μ*t)*NIntegrate[E^(μ*s)Isyn[s],{s,t0,t}];

Plot[
v[t,0],{t,0,60},
PlotRange->All,
AspectRatio->1/(4*GoldenRatio),
ImageSize->720
]

output current assuming integration, leakage, and spiking

Δt = Min[{τin,τleak}]/32;
tmax = 64;

t0 = 0;
t = t0;
plotdata = {{t,v[t,t0]}};
spikes = {};
Do[
t = t + Δt;
membranepotential = v[t,t0];
If[membranepotential >vthreshold,
AppendTo[plotdata,{t,100}];
AppendTo[spikes,t];
t0 = t+Δt,
AppendTo[plotdata,{t,membranepotential}]
],
{count,1,Floor[tmax/Δt]}
];

threshold =
Graphics[
{Blue,Thick,
Line[{{0,vthreshold},{tmax,vthreshold}}]
}
];
output =
ListLinePlot[
plotdata,
PlotStyle->{Red,Thick},
AxesOrigin->{0,0},
PlotRange -> All,
AspectRatio->1/(4*GoldenRatio)
];

Show[
output,threshold,
AxesOrigin->{0,0},
PlotRange -> {All,{1.1*v0,0}},
AspectRatio->1/(4*GoldenRatio),
ImageSize->720
]

sinusoidal input current

Isyn[t_] := (1/k)*(vthreshold-v0)*Cos[t];
τin = 2Pi;

Plot[
v[t,0],{t,0,tmax},
PlotRange->All,
AspectRatio->1/(4*GoldenRatio),
ImageSize->720
]

output current assuming integration, leakage, and spiking

Δt = Min[{τin,τleak}]/32;
tmax = 64;

t0 = 0;
t = t0;
plotdata = {{t,v[t,t0]}};
spikes = {};
Do[
t = t + Δt;
membranepotential = v[t,t0];
If[membranepotential >vthreshold,
AppendTo[plotdata,{t,100}];
AppendTo[spikes,t];
t0 = t+Δt,
AppendTo[plotdata,{t,membranepotential}]
],
{count,1,Floor[tmax/Δt]}
];

threshold =
Graphics[
{Blue,Thick,
Line[{{0,vthreshold},{tmax,vthreshold}}]
}
];
output =
ListLinePlot[
plotdata,
PlotStyle->{Red,Thick},
AxesOrigin->{0,0},
PlotRange -> All,
AspectRatio->1/(4*GoldenRatio)
];

Show[
output,threshold,
AxesOrigin->{0,0},
PlotRange -> {All,{1.33*v0,0}},
AspectRatio->1/(4*GoldenRatio),
ImageSize->720
]

sinusoidal input current with white noise

ϵ = 0.1;
Isyn[t_] := 
(1/k)*(vthreshold-v0)*Cos[t]+ϵ*RandomReal[NormalDistribution[0,1]];
τin = 2Pi;

Plot[
v[t,0],{t,0,tmax},
PlotRange->All,
AspectRatio->1/(4*GoldenRatio),
ImageSize->720
]

output current assuming integration, leakage, and spiking

Δt = Min[{τin,τleak}]/64;
tmax = 128;

t0 = 0;
t = t0;
plotdata = {{t,v[t,t0]}};
spikes = {};
Do[
t = t + Δt;
membranepotential = v[t,t0];
If[membranepotential >vthreshold,
AppendTo[plotdata,{t,100}];
AppendTo[spikes,t];
t0 = t+Δt,
AppendTo[plotdata,{t,membranepotential}]
],
{count,1,Floor[tmax/Δt]}
];

threshold =
Graphics[
{Blue,Thick,
Line[{{0,vthreshold},{tmax,vthreshold}}]
}
];
output =
ListLinePlot[
plotdata,
PlotStyle->{Red,Thick},
AxesOrigin->{0,0},
PlotRange -> All,
AspectRatio->1/(4*GoldenRatio)
];

Show[
output,threshold,
AxesOrigin->{0,0},
PlotRange -> {All,{1.33*v0,0}},
AspectRatio->1/(4*GoldenRatio),
ImageSize->720
]

original input current with white noise

ϵ = 1;
Isyn[t_] := 
2+Cos[t] + 3Cos[Sqrt[2]t]- Cos[Sqrt[5]t]+ϵ*RandomReal[NormalDistribution[0,1]];
τin = 2Pi/Sqrt[5];

Plot[
v[t,0],{t,0,60},
PlotRange->All,
AspectRatio->1/(4*GoldenRatio),
ImageSize->720
]

output current assuming integration, leakage, and spiking

Δt = Min[{τin,τleak}]/32;
tmax = 64;

t0 = 0;
t = t0;
plotdata = {{t,v[t,t0]}};
spikes = {};
Do[
t = t + Δt;
membranepotential = v[t,t0];
If[membranepotential >vthreshold,
AppendTo[plotdata,{t,100}];
AppendTo[spikes,t];
t0 = t+Δt,
AppendTo[plotdata,{t,membranepotential}]
],
{count,1,Floor[tmax/Δt]}
];

threshold =
Graphics[
{Blue,Thick,
Line[{{0,vthreshold},{tmax,vthreshold}}]
}
];
output =
ListLinePlot[
plotdata,
PlotStyle->{Red,Thick},
AxesOrigin->{0,0},
PlotRange -> All,
AspectRatio->1/(4*GoldenRatio)
];

Show[
output,threshold,
AxesOrigin->{0,0},
PlotRange -> {All,{1.1*v0,0}},
AspectRatio->1/(4*GoldenRatio),
ImageSize->720
]