Path: news.mathworks.com!newsfeed-00.mathworks.com!news.mv.net!news.glorb.com!news2.glorb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!216.196.98.140.MISMATCH!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!backlog2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 19 Aug 2009 23:45:54 -0500
Date: Thu, 20 Aug 2009 00:45:54 -0400
From: MZ <mark@nospam.void>
User-Agent: Thunderbird 2.0.0.22 (Windows/20090605)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: moving average
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <PJOdnZryi-afSBHXnZ2dnUVZ_sKdnZ2d@giganews.com>
Lines: 21
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-egML8sYLk/Fl7FQsenHADzVyJhTXLU0c/xXIlGhojJCnLuDCNaS7kFnUlsKbqIEKNu2cD1vR/uQiNzB!TXXQXUixcZbHA+uzYbE2aX8F4OO+9zIwM+DV+dd52GHchkob75tsO3Rl1Nce9OUpFMY7lvuSr7RT!TQ==
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.39
X-Original-Bytes: 1914
Xref: news.mathworks.com comp.soft-sys.matlab:564655


I have paired (x,y) data.  I want to compute a sort of moving average on 
it, and I want values returned at the same values of x.  The kink is 
that the x data is not equally spaced.

I've solved the problem this way:

y = 
ksdensity(x,x,'kernel','box','weights',y)./ksdensity(x,x,'kernel','box');

But it's dreadfully slow.  I have to call ksdensity twice, once with 
weighting and once without.  The first one is to basically sum the 
points within a kernel and the second one is to count the points within 
a kernel.  (ie. mean=sum/N)

[The size of the kernel isn't terribly important, so I've stuck with the 
defaults.]

Is there a better way to do this?  I thought about rounding + 
convolution, but it would require interpolation and I'm not sure how 
willing I am to put up with roundoff error.  Although at this stage, it 
might be worth it...