Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5643 > unrolled thread

Sliding Time Window Function

Started bynorthern_flicker <max_kip@hotmail.com>
First post2011-10-14 09:58 +0000
Last post2011-10-16 11:09 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Sliding Time Window Function northern_flicker <max_kip@hotmail.com> - 2011-10-14 09:58 +0000
    Re: Sliding Time Window Function Vince Virgilio <blueschi@gmail.com> - 2011-10-16 11:09 +0000

#5643 — Sliding Time Window Function

Fromnorthern_flicker <max_kip@hotmail.com>
Date2011-10-14 09:58 +0000
SubjectSliding Time Window Function
Message-ID<j79151$i46$1@smc.vnet.net>
Dear Forum

This problem is quite similar to a moving average, but it has two differences, which I am struggling to overcome.  It is applicable to a heterogeneous time series with dependent x and y values, i.e., {time, x, y}, where the temporal variations in x and y are of interest.

1) It would be preferable to have a sliding window based on a time interval rather than the number of data, e.g., 0.5 s, 5 min., 50 years, etc.
2) Instead of a moving average I would like to apply some expression over the moving time interval that uses both x and y, e.g.,

Total[Cos(x)*Sin(y)]/Total[Cos(x)*Cos(y)]

A fresh approach would be much appreciated

[toc] | [next] | [standalone]


#5667

FromVince Virgilio <blueschi@gmail.com>
Date2011-10-16 11:09 +0000
Message-ID<j7ee1f$ehu$1@smc.vnet.net>
In reply to#5643
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web