Path: news.mathworks.com!not-for-mail
From: "Chaos" <rothko.fan@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Nonuniform time moving window average
Date: Wed, 13 May 2009 00:35:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 17
Message-ID: <gud4jm$4er$1@fred.mathworks.com>
References: <guci52$fku$1@fred.mathworks.com>
Reply-To: "Chaos" <rothko.fan@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1242174902 4571 172.30.248.37 (13 May 2009 00:35:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 13 May 2009 00:35:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 293962
Xref: news.mathworks.com comp.soft-sys.matlab:539445


"Ben" <basburywvu.nospam@hotmail.com> wrote in message <guci52$fku$1@fred.mathworks.com>...
> I need to create a 1-second moving window average on a data array with a nonuniform time series.  The data and time vectors have dropouts (i.e no data recorded) and there are slight variations in the sampling rate (~100Hz).  So the number of points in each window should vary.  Below is a simplified example of what I am trying to do.  However this does not scale well and takes entirely to long when the data sets get large.  On average this would need to work on arrays ~200,000 samples in length.
> 
> time = 0:0.1:10;
> time([5 25:28 45 60:62 90]) = []; %Simulated data drops
> data = rand(size(time));
> %Calc 1 second moving window average of the data.
> windowAve = zeros(size(data));
> for i = 1:length(time)
>     windowAve(i) = mean(data(find(time >=time(i) & time< time(i)+1)));
> end
> 
> Can anyone help me with a more efficient method.
> 
> Thanks

you need to be more specific on data that "drops out". what is output? seldom does a device output "nothing", either blank spaces, Inf, etc, etc.   you are essentially doing a poor man's integration but have not accounted for the situation where the data is unavailable for more than a timeframe.  i would directly access the hardware data stream and hex/string parse it out to find the correct codes the machine gives for non-existant data.