Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
technical:sliding_window [2019/09/25 14:25] – created chunchung | technical: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, | def sliding_window(ts, | ||
Line 6: | Line 7: | ||
Parameters | Parameters | ||
---------- | ---------- | ||
- | ts: | + | ts: |
- | wsz: window | + | wsz: Window |
+ | |||
+ | Returns | ||
+ | ------- | ||
+ | tss: Array of time points | ||
+ | rates: | ||
''' | ''' | ||
- | tw = ts[0]-wsz | + | tw = ts[0]-wsz |
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/ | + | return np.array(tts)+wsz/ |
+ | </ | ||
+ | ====Example==== | ||
+ | <code python> | ||
+ | a = np.array([1, | ||
+ | tts,rrs = sliding_window(a) | ||
+ | plt.plot(tts, | ||
+ | plt.plot(a, | ||
</ | </ | ||
+ | {{ : |