Advertisement
toweber

LIF_neuron_sinusoidal_input

Sep 19th, 2022
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 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. InputCurrent_maxvalue = 8e-9
  7. C = 1e-9 #capacitance
  8. Vth = 0.3
  9. Vreset = 0
  10. tstep = 1e-3
  11. Ileak = 1e-9
  12.  
  13.  
  14. times = np.arange(0,5,tstep)
  15. #InputCurrent = 0.5*InputCurrent_maxvalue*(0.5+0.5*np.sin(2*np.pi*times))
  16. InputCurrent = InputCurrent_maxvalue*(np.sin(2*np.pi*times))
  17. InputCurrent = np.where(InputCurrent > 0, InputCurrent, 0)
  18. vmembrane = np.zeros(len(times))
  19. vmembrane[0] = 0
  20.  
  21. vout = np.zeros(len(times))
  22. vout[0] = 0
  23. for i, t in enumerate(times):
  24.     # I = C_M dV/dt + Il
  25.     # dV/dt = I/C
  26.     dV = InputCurrent[i]/C * tstep
  27.  
  28.     # Ileak = C * dVl/dT
  29.     # dV_l/dT = Ileak/C
  30.     dV -= Ileak/C * tstep
  31.  
  32.     vmembrane[i] = vmembrane[i-1] + dV
  33.     vout[i] = 0
  34.     if vmembrane[i] > Vth:
  35.         vmembrane[i] = 0
  36.         vout[i] = 1
  37.     elif vmembrane[i] < 0:
  38.         vmembrane[i] = 0
  39.  
  40.  
  41. fig, axs = plt.subplots(3)
  42. fig.suptitle('Integrate and Fire (IF) Spiking Neuron')
  43.  
  44. axs[0].plot(times,InputCurrent,label="Input Current")
  45. axs[0].set(xlabel="Time (s)")
  46. axs[0].set(ylabel="Input Current (A)")
  47. axs[0].legend()
  48.  
  49. axs[1].plot(times,vmembrane,label="Voltage Membrane")
  50. axs[1].plot(times,Vth*np.ones(len(times)),'--y',label="threshold")
  51. axs[1].set(xlabel="Time (s)")
  52. axs[1].set(ylabel="Membrane Voltage (V)")
  53. axs[1].legend()
  54.  
  55. axs[2].plot(times,vout,'r',label="Output Voltage (V)" )
  56. axs[2].set(xlabel="Time (s)")
  57. axs[2].set(ylabel="Output Voltage (V)")
  58. axs[2].legend()
  59.  
  60. plt.plot
  61. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement