File: examples-audition_filterbank.txt

package info (click to toggle)
brian 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 23,436 kB
  • sloc: python: 68,707; cpp: 29,040; ansic: 5,182; sh: 111; makefile: 61
file content (63 lines) | stat: -rw-r--r-- 1,695 bytes parent folder | download
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
55
56
57
58
59
60
61
62
63
.. currentmodule:: brian

.. index::
   pair: example usage; subplot
   pair: example usage; plot
   pair: example usage; run
   pair: example usage; show
   pair: example usage; PoissonThreshold
   pair: example usage; xlabel
   pair: example usage; linspace
   pair: example usage; ylabel
   pair: example usage; SpikeMonitor
   pair: example usage; NeuronGroup
   pair: example usage; SpikeCounter
   pair: example usage; gain

.. _example-audition_filterbank:

Example: filterbank (audition)
==============================

An auditory filterbank implemented with Poisson neurons

The input sound has a missing fundamental (only harmonics 2 and 3)

::

    from brian import *
    
    defaultclock.dt = .01 * ms
    
    N = 1500
    tau = 1 * ms # Decay time constant of filters = 2*tau
    freq = linspace(100 * Hz, 2000 * Hz, N) # characteristic frequencies
    f_stimulus = 500 * Hz # stimulus frequency
    gain = 500 * Hz
    
    eqs = '''
    dv/dt=(-a*w-v+I)/tau : Hz
    dw/dt=(v-w)/tau : Hz # e.g. linearized potassium channel with conductance a
    a : 1
    I = gain*(sin(4*pi*f_stimulus*t)+sin(6*pi*f_stimulus*t)) : Hz
    '''
    
    neurones = NeuronGroup(N, model=eqs, threshold=PoissonThreshold())
    neurones.a = (2 * pi * freq * tau) ** 2
    
    spikes = SpikeMonitor(neurones)
    counter = SpikeCounter(neurones)
    run(100 * ms)
    
    subplot(121)
    CF = array([freq[i] for i, _ in spikes.spikes])
    timings = array([t for _, t in spikes.spikes])
    plot(timings / ms, CF, '.')
    xlabel('Time (ms)')
    ylabel('Characteristic frequency (Hz)')
    subplot(122)
    plot(counter.count / (300 * ms), freq)
    xlabel('Firing rate (Hz)')
    show()