User Tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
technical:sliding_window [2019/09/25 14:25] – created chunchungtechnical:sliding_window [2021/10/12 15:15] (current) chunchung
Line 1: Line 1:
 =====Sliding window time histogram===== =====Sliding window time histogram=====
 +Given the spike time, plot the event rate within a sliding window.
 <code python> <code python>
 def sliding_window(ts,wsz=10): def sliding_window(ts,wsz=10):
Line 6: Line 7:
     Parameters     Parameters
     ----------     ----------
-    ts:  array time points +    ts:  Array of time points 
-    wsz: window size+    wsz: Window size 
 +     
 +    Returns 
 +    ------- 
 +    tss:    Array of time points 
 +    rates:  Firing rates at the time points
     '''     '''
-    tw = ts[0]-wsz+    tw = ts[0]-wsz # initialized with the time when the first event hits the window
     i0 = 0     i0 = 0
     i1 = 0     i1 = 0
Line 36: Line 42:
     tts.append(tw)     tts.append(tw)
     rrs.append(0)     rrs.append(0)
-    return np.array(tts)+wsz/2,np.array(rrs)/bsize+    return np.array(tts)+wsz/2,np.array(rrs)/wsz 
 +</code> 
 +====Example==== 
 +<code python> 
 +a = np.array([1,3,6,11,24,33,36,44,44,52,54,55,55,55,59,64]) 
 +tts,rrs = sliding_window(a) 
 +plt.plot(tts,rrs,'-'
 +plt.plot(a,np.zeros_like(a),'x')
 </code> </code>
 +{{ :technical:sliding_window_example.svg |}}

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information