Path: news.mathworks.com!not-for-mail
From: "Erik Carlsten" <ecarlste@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Moving averages over a vector in MatLAB?
Date: Thu, 1 Nov 2007 16:21:38 +0000 (UTC)
Organization: Montana State University
Lines: 34
Message-ID: <fgcuei$32r$1@fred.mathworks.com>
Reply-To: "Erik Carlsten" <ecarlste@yahoo.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1193934098 3163 172.30.248.35 (1 Nov 2007 16:21:38 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 1 Nov 2007 16:21:38 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1169484
Xref: news.mathworks.com comp.soft-sys.matlab:435671



Hi everyone, recently I have been doing some analysis on 
some FFTS trying to find and analyze regions with peaks. 
One thing we have been doing to make this process easier 
is to take a moving average of the FFT before analyzing 
the peaks to ensure that rogue spikes in our FFTs do not 
mislead our signal processing. However, one problem I am 
forseeing is just how slow our current moving average is. 
Currently we are simply looking at x points on the left 
side and x points on the right side of our current point 
and taking a mean of that data and then setting the same 
index in our new smoothed out FFT vector to be that mean 
value. I would like to see if anyone knows a slick way to 
accomplish this with either a built in toolbox function or 
if there is a way to apply a custom written function to 
each index in a vector without a for loop.

Below is some code that is similar to what we are 
currently using to accomplish our FFT smoothing process. 
FFTVect represents our intensity values at a given 
frequency. We are simply trying to build a new "smoothed 
out" FFT that does not show any thin but tall spikes that 
our original FFT shows. This averaging process eliminates 
this issue previous to our peak analysis but the way we 
are currently doing it seems very slow and clunky. Any 
suggestions?

avgWin = 10;

avgFFT = FFTvect;

for index = avgWin+1:length(avgFFT)-avgWin
    avgFFT(index) = mean(FFTVect(index-
avgWin:index+avgWin));
end