Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!o80g2000hse.googlegroups.com!not-for-mail
From:  Eric C <eric.forum@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Moving averages over a vector in MatLAB?
Date: Fri, 02 Nov 2007 13:09:24 -0700
Organization: http://groups.google.com
Lines: 23
Message-ID: <1194034164.958839.178170@o80g2000hse.googlegroups.com>
References: <fgcuei$32r$1@fred.mathworks.com>
NNTP-Posting-Host: 68.253.230.180
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Trace: posting.google.com 1194034165 28335 127.0.0.1 (2 Nov 2007 20:09:25 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 2 Nov 2007 20:09:25 +0000 (UTC)
In-Reply-To: <fgfubi$hmg$1@fred.mathworks.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: o80g2000hse.googlegroups.com; posting-host=68.253.230.180;
Xref: news.mathworks.com comp.soft-sys.matlab:435866



On Nov 2, 3:38 pm, "Erik Carlsten" <ecarl...@gmail.com> wrote:
> Thanks very much to everyone that responded. I ended up
> using filter() for my solution and it decreased the time
> in my running average by over a factor of 200. Needless to
> say this is exactly what I was looking for!
>
> windowSize = avgWin*2+1;
> avgFFTNoise = filter(ones(1,windowSize)/windowSize, 1, ...
>         rangeMinusNoiseY(cutIndexRange+avgWin));
>
> Thanks Randy for the suggestion to use filter() to take
> the running average it worked great!

If I understand correctly this can be implemented very efficiently.
Think of it this way, after you've computed the mean of all the
samples in your window you then move it one point forward. All that
really does is add a new sample to your mean and subtract the last
one. That means you've got an integrating filter and a differencing
filter, with a delay, and no multiplies. This is the basic idea behind
CIC filters, just without the decimation. Look up CIC filters and you
should get the idea, I found part of Fred Harris' Multirate book
online had the best explanation, but I can't find it now.