On Tue, Oct 13, 2009 at 10:22 AM, Janto Dreijer <[email protected]> wrote:
> I'm looking for code that will calculate the running median of a
> sequence, efficiently. (I'm trying to subtract the running median from
> a signal to correct for gradual drift).
>
In the past, I've used the following algorithm which approximates the
running median. I got it from an article in a peer-reviewed journal, but I
can't locate the reference at the moment.
my_median = some_reasonable_default
step_size = some_value_depending_on_your_application
def adjust_median(value):
global my_median
if my_median < value:
my_median += step_size
else:
my_median -= step_size
Let me know if you have any questions about it.
--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
--
http://mail.python.org/mailman/listinfo/python-list