help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Vectorize a moving average calculation


From: Joshua Stults
Subject: Re: Vectorize a moving average calculation
Date: Mon, 3 Nov 2008 16:20:06 -0500

Hello,

I don't think you can really vectorize a calculation like that, but
it's pretty easy to recast it as a sparse matrix solve if you can
afford to fit all of the coefficients into memory.  For your problem
you just end up with a bi-diagonal system, so you need about 2*n of
extra storage beyond just storing your solution vector.  It's ~2
orders of magnitude faster than a for-loop too, and for more complex
operators you can use the built-in iterative solvers.  For your
problem you'd have alpha down the main diagonal and (1-alpha) down the
first sub-diagonal, if A is your sparse matrix, your solution is just

x = A\b;

I wrote up an example in my blog a few days ago on this exact thing,
it's in the last half of this post:
http://j-stults.blogspot.com/2008/10/is-octave-slow.html

Hope that helps.

Cheers!
Josh

On Mon, Nov 3, 2008 at 4:01 PM, babelproofreader
<address@hidden> wrote:
>
> I would like to calculate various moving averages, FIR filters etc. which
> rely on previously calculated values of said averages and filters e.g. an
> exponential moving average is of the form alpha*ValueToday +
> (1-alpha)*ValueYesterday. How does one use vectorized code to calculate such
> things?
> --
> View this message in context: 
> http://www.nabble.com/Vectorize-a-moving-average-calculation-tp20303346p20303346.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]