Re: Sliding Time Window Function

• To: mathgroup at smc.vnet.net
• Subject: [mg122134] Re: Sliding Time Window Function
• From: Vince Virgilio <blueschi at gmail.com>
• Date: Sun, 16 Oct 2011 07:05:53 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <j79151\$i46\$1@smc.vnet.net>

```I have something which might suit. I use it for sliding window averages over non-uniformly sampled time series.

binWin[seq_, f_, intervals_, g_:Identity] :=
Module[{sorted = SortBy[seq, f], order = Ordering@intervals[[All, 1]]},
Function[{tLo, tHi},
sorted = Drop[sorted, LengthWhile[sorted, f@# < tLo &] ];
g @ TakeWhile[sorted, f@# < tHi &]
] @@@ intervals[[order]] // #[[Ordering@order]]&
];

'seq' is the list of (x,y) pairs, where y may be scalar or vector. 'f' picks the sort-by or key field (say, time). Usually, it is 'First'. 'intervals' is a sequence of time (key) intervals which may overlap. And 'g' is your reduction, which is applied to each window (bin). binWin will take unordered series and window specs and return the windowed results ordered according to the lower bound of the intervals.

I think it's fairly performant. But I'd appreciate any improvements.

Vince

```

• Prev by Date: Re: How to create this kind of list
• Next by Date: Re: How to create this kind of list
• Previous by thread: Sliding Time Window Function
• Next by thread: Help with manipulate and 3D plotting