Advertisement
toweber

IF_neuron_sinusoidal_input

Sep 19th, 2022
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import os
  2. import ipdb # ipdb.set_trace()
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5.  
  6.  
  7. InputCurrent_maxvalue = 8e-9
  8. C = 1e-9 #capacitance
  9. Vth = 0.3
  10. Vreset = 0
  11. tstep = 1e-3
  12. Ileak = 0
  13.  
  14.  
  15. times = np.arange(0,5,tstep)
  16. InputCurrent = 0.5*InputCurrent_maxvalue*(0.5+0.5*np.sin(2*np.pi*times))
  17. vmembrane = np.zeros(len(times))
  18. vmembrane[0] = 0
  19.  
  20. vout = np.zeros(len(times))
  21. vout[0] = 0
  22. for i, t in enumerate(times):
  23.     # I = C_M dV/dt + Il
  24.     # dV/dt = I/C
  25.     dV = InputCurrent[i]/C * tstep
  26.     vmembrane[i] = vmembrane[i-1] + dV
  27.     if vmembrane[i] > Vth:
  28.         vmembrane[i] = 0
  29.         vout[i] = 1
  30.     else:
  31.         vout[i] = 0
  32.  
  33. fig, axs = plt.subplots(3)
  34. fig.suptitle('Integrate and Fire (IF) Spiking Neuron')
  35.  
  36. axs[0].plot(times,InputCurrent)
  37.  
  38. axs[1].plot(times,vmembrane)
  39.  
  40. axs[2].plot(times,vout,'r',label="Voltage (V)" )
  41. plt.xlabel("Time (s)")
  42.  
  43.  
  44. plt.plot
  45. plt.show()
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement