File: examples-hears-tan_carney_2003_tan_carney_simple_test.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 (150 lines) | stat: -rw-r--r-- 5,827 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
.. currentmodule:: brian

.. index::
   pair: example usage; subplot
   pair: example usage; tone
   pair: example usage; Network
   pair: example usage; figure
   pair: example usage; sequence
   pair: example usage; text
   pair: example usage; TanCarney
   pair: example usage; ylim
   pair: example usage; plot
   pair: example usage; xlim
   pair: example usage; title
   pair: example usage; show
   pair: example usage; click
   pair: example usage; ylabel
   pair: example usage; SpikeMonitor
   pair: example usage; set_global_preferences
   pair: example usage; nanmax
   pair: example usage; StateMonitor
   pair: example usage; Sound
   pair: example usage; run
   pair: example usage; ZhangSynapse
   pair: example usage; reinit_default_clock
   pair: example usage; get_samplerate
   pair: example usage; ones
   pair: example usage; xlabel
   pair: example usage; set_default_samplerate
   pair: example usage; MiddleEar
   pair: example usage; silence

.. _example-hears-tan_carney_2003_tan_carney_simple_test:

Example: tan_carney_simple_test (hears/tan_carney_2003)
=======================================================

Fig. 1 and 3 (spking output without spiking/refractory period) should
reproduce the output of the AN3_test_tone.m and AN3_test_click.m
scripts, available in the code accompanying the paper Tan & Carney (2003).
This matlab code is available from
http://www.urmc.rochester.edu/labs/Carney-Lab/publications/auditory-models.cfm

Tan, Q., and L. H. Carney.
"A Phenomenological Model for the Responses of Auditory-nerve Fibers.
II. Nonlinear Tuning with a Frequency Glide".
The Journal of the Acoustical Society of America 114 (2003): 2007.

::

    
    import numpy as np
    import matplotlib.pyplot as plt
    
    from brian.stdunits import kHz, Hz, ms
    from brian.network import Network
    from brian.monitor import StateMonitor, SpikeMonitor
    from brian.globalprefs import set_global_preferences
    
    #set_global_preferences(useweave=True)
    from brian.hears import (Sound, get_samplerate, set_default_samplerate, tone,
                             click, silence, dB, TanCarney, MiddleEar, ZhangSynapse)
    from brian.clock import reinit_default_clock
    
    
    set_default_samplerate(50*kHz)
    sample_length = 1 / get_samplerate(None)
    cf = 1000 * Hz
    
    print 'Testing click response'
    duration = 25*ms    
    levels = [40, 60, 80, 100, 120]
    # a click of two samples
    tones = Sound([Sound.sequence([click(sample_length*2, peak=level*dB),
                                   silence(duration=duration - sample_length)])
               for level in levels])
    ihc = TanCarney(MiddleEar(tones), [cf] * len(levels), update_interval=1)
    syn = ZhangSynapse(ihc, cf)
    s_mon = StateMonitor(syn, 's', record=True, clock=syn.clock)
    R_mon = StateMonitor(syn, 'R', record=True, clock=syn.clock)
    spike_mon = SpikeMonitor(syn)
    net = Network(syn, s_mon, R_mon, spike_mon)
    net.run(duration * 1.5)
    for idx, level in enumerate(levels):
        plt.figure(1)
        plt.subplot(len(levels), 1, idx + 1)
        plt.plot(s_mon.times / ms, s_mon[idx])
        plt.xlim(0, 25)
        plt.xlabel('Time (msec)')
        plt.ylabel('Sp/sec')
        plt.text(15, np.nanmax(s_mon[idx])/2., 'Peak SPL=%s SPL' % str(level*dB));
        ymin, ymax = plt.ylim()
        if idx == 0:
            plt.title('Click responses')
    
        plt.figure(2)
        plt.subplot(len(levels), 1, idx + 1)
        plt.plot(R_mon.times / ms, R_mon[idx])
        plt.xlabel('Time (msec)')
        plt.xlabel('Time (msec)')
        plt.text(15, np.nanmax(s_mon[idx])/2., 'Peak SPL=%s SPL' % str(level*dB));
        plt.ylim(ymin, ymax)
        if idx == 0:
            plt.title('Click responses (with spikes and refractoriness)')
        plt.plot(spike_mon.spiketimes[idx] / ms,
             np.ones(len(spike_mon.spiketimes[idx])) * np.nanmax(R_mon[idx]), 'rx')
    
    print 'Testing tone response'
    reinit_default_clock()
    duration = 60*ms    
    levels = [0, 20, 40, 60, 80]
    tones = Sound([Sound.sequence([tone(cf, duration).atlevel(level*dB).ramp(when='both',
                                                                             duration=10*ms,
                                                                             inplace=False),
                                   silence(duration=duration/2)])
                   for level in levels])
    ihc = TanCarney(MiddleEar(tones), [cf] * len(levels), update_interval=1)
    syn = ZhangSynapse(ihc, cf)
    s_mon = StateMonitor(syn, 's', record=True, clock=syn.clock)
    R_mon = StateMonitor(syn, 'R', record=True, clock=syn.clock)
    spike_mon = SpikeMonitor(syn)
    net = Network(syn, s_mon, R_mon, spike_mon)
    net.run(duration * 1.5)
    for idx, level in enumerate(levels):
        plt.figure(3)
        plt.subplot(len(levels), 1, idx + 1)
        plt.plot(s_mon.times / ms, s_mon[idx])
        plt.xlim(0, 120)
        plt.xlabel('Time (msec)')
        plt.ylabel('Sp/sec')
        plt.text(1.25 * duration/ms, np.nanmax(s_mon[idx])/2., '%s SPL' % str(level*dB));
        ymin, ymax = plt.ylim()
        if idx == 0:
            plt.title('CF=%.0f Hz - Response to Tone at CF' % cf)
    
        plt.figure(4)
        plt.subplot(len(levels), 1, idx + 1)
        plt.plot(R_mon.times / ms, R_mon[idx])
        plt.xlabel('Time (msec)')
        plt.xlabel('Time (msec)')
        plt.text(1.25 * duration/ms, np.nanmax(R_mon[idx])/2., '%s SPL' % str(level*dB));
        plt.ylim(ymin, ymax)
        if idx == 0:
            plt.title('CF=%.0f Hz - Response to Tone at CF (with spikes and refractoriness)' % cf)
        plt.plot(spike_mon.spiketimes[idx] / ms,
             np.ones(len(spike_mon.spiketimes[idx])) * np.nanmax(R_mon[idx]), 'rx')
    
    plt.show()