Vectorize a moving average calculation

Ozzy Lash ozzy.lash at gmail.com
Mon Nov 3 15:26:31 CST 2008


On Mon, Nov 3, 2008 at 3:01 PM, babelproofreader
<babelproofreader at gmail.com> 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?

I think the filter function will do what you want.  For your example
you should be able to use:

y=filter(alpha,[1,-(1-alpha)],x)


More information about the Help-octave mailing list