Skip to content

Instantly share code, notes, and snippets.

@Andy-P
Last active August 29, 2015 14:25
Show Gist options
  • Save Andy-P/d322bdc670646ddc2185 to your computer and use it in GitHub Desktop.
Save Andy-P/d322bdc670646ddc2185 to your computer and use it in GitHub Desktop.
using Dates
# set_default_plot_size(20cm, 10cm)
# simple Integrate and Fire Synapse Mode
type Synapse
Ω::Real # membrane resistance [MΩ]
τ::Real # membrane time constant [ms]
rV::Real # resting membrane potential [mV]
thV::Real # spike threshold [mV]
sV::Real # spike voltage [mV]
rsV::Real # reset voltage to after a spike [mV]
dt::DateTime # time stamp of last update
v::Real # tracks current voltage
function Synapse(;Ω::Real=10., τ::Real=10., rV::Real=-70.,
thV::Real=-55, sV::Real=-20, rsV::Real=-75,
dt::DateTime=now())
new(Ω, τ, rV, thV, sV, rsV, dt,rV)
end
end
nextDt(dt::DateTime, addMs::Int64) = dt + Millisecond(addMs)
function update!(s::Synapse, iV::Real, dt::DateTime)
Δdt = int(dt - s.dt)
V = s.rV + iV * s.Ω # current input voltage
V₁ = V + (s.v - V) * exp(-Δdt/s.τ)
s.v = V₁ >= s.thV? s.rsV:V₁
return s.v == s.rsV? s.sV : s.v
end
Δτ = 1 # in millesec
n = 1000
s = Synapse(Ω=10,τ=10)
data = zeros(n)
# V = copy(data)
V = max(randn(n) * 1.75 + .1,0)
for i = 1:n
v = update!(s, V[i], nextDt(s.dt, Δτ))
data[i] = v
end
vstack(plot(x=[1:n], y=data, Geom.line, Scale.y_continuous(minvalue=-80, maxvalue=10)), plot(x = [1:n],y=V, Geom.line))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment