-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChapter10.4.qmd
54 lines (43 loc) · 1.35 KB
/
Chapter10.4.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Ch. 10 – Perceptual
## Figure 10.4 Auditory nerve fibre model and inner hair cells spiking for the earlier example (a complex tone consisting of 400 + 600 + 1600 Hz sine waves).
For more information, see [Brian documentation](https://brian.readthedocs.io/en/stable/).
### Libraries
```{python}
#| echo: true
#| eval: true
#| label: libraries
#| code-fold: true
#| code-summary: "Show the code"
from brian2 import *
from brian2hears import *
import matplotlib.pyplot as plt
```
```{python}
#| echo: true
#| eval: true
#| label: brian
sound = loadsound('data/400_600_1600_hz.wav')
# Inner hair cell model
cfmin, cfmax, cfN = 20*Hz, 20*kHz, 3000 # was 3000
cf = erbspace(cfmin, cfmax, cfN)
gfb = Gammatone(sound, cf)
ihc = FunctionFilterbank(gfb, lambda x: 3*clip(x, 0, Inf)**(1.0/3.0))
# Leaky integrate-and-fire model with noise and refractoriness
eqs = '''
dv/dt = (I-v)/(1*ms)+0.2*xi*(2/(1*ms))**.5 : 1 (unless refractory)
I : 1
'''
G = FilterbankGroup(ihc, 'I', eqs, reset='v=0', threshold='v>1', refractory=5*ms)
# Run, and raster plot of the spikes
M = SpikeMonitor(G)
run(sound.duration)
# Plot the results
fig, ax = plt.subplots(figsize=(8.0, 4.0))
ax.plot(M.t/ms, M.i, '.', alpha=0.5, color='tab:blue', ms=3)
ax.set_xlabel('Time (ms)')
ax.set_ylabel('Neuron number (inner hair cell)')
ylim(0, 2000)
xlabel('Time (ms)')
ylabel('Neuron index');
plt.show()
```