~ubuntu-branches/ubuntu/wily/brian/wily

« back to all changes in this revision

Viewing changes to docs_sphinx/examples-misc_spike_triggered_average.txt

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2014-07-30 11:29:44 UTC
  • mfrom: (6.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20140730112944-ln0ogbq0kpyyuz47
Tags: 1.4.1-2
* Forgotten upload to unstable
* debian/control
  - policy boost to 3.9.5
  - updated Vcs- fields given migration to anonscm.d.o and provided -b
    debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
.. currentmodule:: brian
2
 
 
3
 
.. index::
4
 
   pair: example usage; run
5
 
   pair: example usage; PoissonGroup
6
 
   pair: example usage; spike_triggered_average
7
 
   pair: example usage; SpikeMonitor
8
 
   pair: example usage; exp
9
 
 
10
 
.. _example-misc_spike_triggered_average:
11
 
 
12
 
Example: spike_triggered_average (misc)
13
 
=======================================
14
 
 
15
 
Example of the use of the function spike_triggered_average. A white noise  is filtered
16
 
by a gaussian filter (low pass filter) which output is used to generate spikes (poission process)
17
 
Those spikes are used in conjunction with the input signal to retrieve the filter function.
18
 
 
19
 
::
20
 
 
21
 
    from brian import *
22
 
    from brian.hears import *
23
 
    from numpy.random import randn
24
 
    from matplotlib import pyplot
25
 
    
26
 
    dt = 0.1*ms
27
 
    defaultclock.dt = dt
28
 
    stimulus_duration = 15000*ms
29
 
    stimulus = randn(int(stimulus_duration/     dt))
30
 
    
31
 
    #filter
32
 
    n=200
33
 
    filt = exp(-((linspace(0.5,n,n))-(n+5)/2)**2/(n/3));
34
 
    filt = filt/norm(filt)*1000;
35
 
    filtered_stimulus = convolve(stimulus,filt)
36
 
    
37
 
    
38
 
    neuron = PoissonGroup(1,lambda t:filtered_stimulus[int(t/dt)])
39
 
    
40
 
    spikes = SpikeMonitor(neuron)
41
 
    run(stimulus_duration,report='text')
42
 
    spikes = spikes[0] #resulting spikes
43
 
    
44
 
    max_interval = 20*ms #window duration of the spike triggered average
45
 
    onset = 10*ms
46
 
    sta,time_axis = spike_triggered_average(spikes,stimulus,max_interval,dt,onset=onset,display=True)
47
 
    
48
 
    
49
 
    figure()
50
 
    plot(time_axis,filt/max(filt))
51
 
    plot(time_axis,sta/max(sta))
52
 
    xlabel('time axis')
53
 
    ylabel('sta')
54
 
    legend(('real filter','estimated filter'))
55
 
    
56
 
    show()
57
 
    
58
 
 
 
1
.. currentmodule:: brian
 
2
 
 
3
.. index::
 
4
   pair: example usage; run
 
5
   pair: example usage; PoissonGroup
 
6
   pair: example usage; spike_triggered_average
 
7
   pair: example usage; SpikeMonitor
 
8
   pair: example usage; exp
 
9
 
 
10
.. _example-misc_spike_triggered_average:
 
11
 
 
12
Example: spike_triggered_average (misc)
 
13
=======================================
 
14
 
 
15
Example of the use of the function spike_triggered_average. A white noise  is filtered
 
16
by a gaussian filter (low pass filter) which output is used to generate spikes (poission process)
 
17
Those spikes are used in conjunction with the input signal to retrieve the filter function.
 
18
 
 
19
::
 
20
 
 
21
    from brian import *
 
22
    from brian.hears import *
 
23
    from numpy.random import randn
 
24
    from numpy.linalg import norm
 
25
    from matplotlib import pyplot
 
26
    
 
27
    dt = 0.1*ms
 
28
    defaultclock.dt = dt
 
29
    stimulus_duration = 15000*ms
 
30
    stimulus = randn(int(stimulus_duration/     dt))
 
31
    
 
32
    #filter
 
33
    n=200
 
34
    filt = exp(-((linspace(0.5,n,n))-(n+5)/2)**2/(n/3));
 
35
    filt = filt/norm(filt)*1000;
 
36
    filtered_stimulus = convolve(stimulus,filt)
 
37
    
 
38
    
 
39
    neuron = PoissonGroup(1,lambda t:filtered_stimulus[int(t/dt)])
 
40
    
 
41
    spikes = SpikeMonitor(neuron)
 
42
    run(stimulus_duration,report='text')
 
43
    spikes = spikes[0] #resulting spikes
 
44
    
 
45
    max_interval = 20*ms #window duration of the spike triggered average
 
46
    onset = 10*ms
 
47
    sta,time_axis = spike_triggered_average(spikes,stimulus,max_interval,dt,onset=onset,display=True)
 
48
    
 
49
    
 
50
    figure()
 
51
    plot(time_axis,filt/max(filt))
 
52
    plot(time_axis,sta/max(sta))
 
53
    xlabel('time axis')
 
54
    ylabel('sta')
 
55
    legend(('real filter','estimated filter'))
 
56
    
 
57
    show()
 
58
    
 
59