       Re: Moving average type process

• To: mathgroup at smc.vnet.net
• Subject: [mg18227] Re: [mg18221] Moving average type process
• From: Maarten.vanderBurgt at icos.be
• Date: Thu, 24 Jun 1999 14:24:13 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Virgil,

Try the following:
First partition your inlist  in vectors of length 3 ( = Length[wtlist])
with an offset of one.
Then make the scalar product of each of these vectors with vector wtlist.
This gives you the moving average with weights. It is implemted in the
function movave below. As shown in Out, it is also fairly fast.

In:= movave[wtlist_, inlist_]:= (wtlist . #1)& /@ Partition[inlist,
Length[wtlist], 1]

In:= movave[{w1,w2,w3},{a,b,c,d,e}]
Out= {a w1+b w2+c w3,b w1+c w2+d w3,c w1+d w2+e w3}

In:= w={1.3,5.2,3.2};
in = Table[Random[Real,{-10,10}],{10000}];

In:= movave[w,in];//Timing
Out= {0.211 Second,Null}

Maarten

_______________________________________________________________

Maarten van der Burgt
ICOS Vision Systems
Esperantolaan 9
B-3001 Leuven, Belgium
tel. + 32 16 398220; direct + 32 16 398316; fax. + 32 16 400067
e-mail: maarten.vanderburgt at icos.be
_______________________________________________________________

Virgil Stokes <virgil.stokes at neuro.ki.se> on 23-06-99 02:41:14 AM

Subject: [mg18227]  [mg18221] Moving average type process

I wish to perform the following "moving average" type process on
a list to generate a new list:

Inputs:
wtlist = {w1,w2,w3}     -- weight list
inlist = {a,b,c,d,e,f}  -- any other list (>= 3 elements)

Output:
outlist = {w1*a+w2*b+w3*c, w1*b+w2*c+w3*d, w1*c+w2*d+w3*e,
w1*d+w2*e+w3*f}

Note, outlist will always contain 2 less (Length[wtlist]/2) elements
than in the input list (inlist).

If w1=w2=w3=x, then
the following works fine:

outlist = x*Drop[Plus@@NestList[RotateRight,inlist,2],2]

This is a weighted (from wtlist) sum over another list of arbitrary
length (inlist). I would like to get a "fast" function for doing this when
the weights are not equal.

-- Virgil

```

• Prev by Date: Re: Forcing Re[]'s to be Real
• Next by Date: Re: Forcing Re[]'s to be Real
• Previous by thread: Re: Moving average type process
• Next by thread: Re: Moving average type process