File: examples-misc_spike_triggered_average.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 (68 lines) | stat: -rw-r--r-- 1,951 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
.. currentmodule:: brian

.. index::
   pair: example usage; plot
   pair: example usage; run
   pair: example usage; figure
   pair: example usage; show
   pair: example usage; spike_triggered_average
   pair: example usage; PoissonGroup
   pair: example usage; SpikeMonitor
   pair: example usage; linspace
   pair: example usage; exp
   pair: example usage; ylabel
   pair: example usage; convolve
   pair: example usage; xlabel
   pair: example usage; legend
   pair: example usage; norm

.. _example-misc_spike_triggered_average:

Example: spike_triggered_average (misc)
=======================================

Example of the use of the function spike_triggered_average. A white noise  is filtered
by a gaussian filter (low pass filter) which output is used to generate spikes (poission process)
Those spikes are used in conjunction with the input signal to retrieve the filter function.

::

    from brian import *
    from brian.hears import *
    from numpy.random import randn
    from numpy.linalg import norm
    from matplotlib import pyplot
    
    dt = 0.1*ms
    defaultclock.dt = dt
    stimulus_duration = 15000*ms
    stimulus = randn(int(stimulus_duration/     dt))
    
    #filter
    n=200
    filt = exp(-((linspace(0.5,n,n))-(n+5)/2)**2/(n/3));
    filt = filt/norm(filt)*1000;
    filtered_stimulus = convolve(stimulus,filt)
    
    
    neuron = PoissonGroup(1,lambda t:filtered_stimulus[int(t/dt)])
    
    spikes = SpikeMonitor(neuron)
    run(stimulus_duration,report='text')
    spikes = spikes[0] #resulting spikes
    
    max_interval = 20*ms #window duration of the spike triggered average
    onset = 10*ms
    sta,time_axis = spike_triggered_average(spikes,stimulus,max_interval,dt,onset=onset,display=True)
    
    
    figure()
    plot(time_axis,filt/max(filt))
    plot(time_axis,sta/max(sta))
    xlabel('time axis')
    ylabel('sta')
    legend(('real filter','estimated filter'))
    
    show()