<div class="gmail_quote">On Tue, Oct 13, 2009 at 10:22 AM, Janto Dreijer <span dir="ltr"><<a href="mailto:jantod@gmail.com">jantod@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I'm looking for code that will calculate the running median of a<br>
sequence, efficiently. (I'm trying to subtract the running median from<br>
a signal to correct for gradual drift).<br></blockquote></div><br>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.<br>
<br>my_median = some_reasonable_default<br>step_size = some_value_depending_on_your_application<br><br>def adjust_median(value):<br> global my_median<br> if my_median < value:<br> my_median += step_size<br>
else:<br> my_median -= step_size<br><br>Let me know if you have any questions about it.<br><blockquote style="margin: 1.5em 0pt;">--<br>
Daniel Stutzbach, Ph.D.<br>
President, <a href="http://stutzbachenterprises.com">Stutzbach Enterprises, LLC</a>
</blockquote>