<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251197</link>
    <title>MATLAB Central Newsreader - Nonuniform time moving window average</title>
    <description>Feed for thread: Nonuniform time moving window average</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 12 May 2009 19:20:02 -0400</pubDate>
      <title>Nonuniform time moving window average</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251197#649333</link>
      <author>Ben </author>
      <description>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.&lt;br&gt;
&lt;br&gt;
time = 0:0.1:10;&lt;br&gt;
time([5 25:28 45 60:62 90]) = []; %Simulated data drops&lt;br&gt;
data = rand(size(time));&lt;br&gt;
%Calc 1 second moving window average of the data.&lt;br&gt;
windowAve = zeros(size(data));&lt;br&gt;
for i = 1:length(time)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;windowAve(i) = mean(data(find(time &amp;gt;=time(i) &amp; time&amp;lt; time(i)+1)));&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
Can anyone help me with a more efficient method.&lt;br&gt;
&lt;br&gt;
Thanks</description>
    </item>
    <item>
      <pubDate>Tue, 12 May 2009 19:50:18 -0400</pubDate>
      <title>Re: Nonuniform time moving window average</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251197#649341</link>
      <author>Bruno Luong</author>
      <description>Please try this:&lt;br&gt;
&lt;br&gt;
% Data&lt;br&gt;
time = 0:0.1:10;&lt;br&gt;
time([5 25:28 45 60:62 90]) = []; %Simulated data drops&lt;br&gt;
data = rand(size(time));&lt;br&gt;
dt =1;&lt;br&gt;
&lt;br&gt;
% Engine&lt;br&gt;
n=length(time);&lt;br&gt;
lastfirst = n; % alternatively: find(time&amp;lt;=time(end)-dt,1,'last');&lt;br&gt;
first=1:lastfirst;&lt;br&gt;
tlast = time(first)+dt;&lt;br&gt;
last = interp1(time,1:n,tlast,'linear','extrap');&lt;br&gt;
last = max(min(floor(last),n),first);&lt;br&gt;
%&lt;br&gt;
csdata = cumsum([0 data]);&lt;br&gt;
windowAve = (csdata(last+1)-csdata(first))./(last-first+1)&lt;br&gt;
&lt;br&gt;
% Bruno</description>
    </item>
    <item>
      <pubDate>Wed, 13 May 2009 00:35:02 -0400</pubDate>
      <title>Re: Nonuniform time moving window average</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251197#649381</link>
      <author>Chaos </author>
      <description>&quot;Ben&quot; &amp;lt;basburywvu.nospam@hotmail.com&amp;gt; wrote in message &amp;lt;guci52$fku$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; time = 0:0.1:10;&lt;br&gt;
&amp;gt; time([5 25:28 45 60:62 90]) = []; %Simulated data drops&lt;br&gt;
&amp;gt; data = rand(size(time));&lt;br&gt;
&amp;gt; %Calc 1 second moving window average of the data.&lt;br&gt;
&amp;gt; windowAve = zeros(size(data));&lt;br&gt;
&amp;gt; for i = 1:length(time)&lt;br&gt;
&amp;gt;     windowAve(i) = mean(data(find(time &amp;gt;=time(i) &amp; time&amp;lt; time(i)+1)));&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Can anyone help me with a more efficient method.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&lt;br&gt;
you need to be more specific on data that &quot;drops out&quot;. what is output? seldom does a device output &quot;nothing&quot;, 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.</description>
    </item>
    <item>
      <pubDate>Wed, 13 May 2009 12:08:01 -0400</pubDate>
      <title>Re: Nonuniform time moving window average</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251197#649490</link>
      <author>Ben </author>
      <description>&quot;Chaos&quot; &amp;lt;rothko.fan@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; you need to be more specific on data that &quot;drops out&quot;. what is output? seldom does&lt;br&gt;
&amp;gt; a device output &quot;nothing&quot;, either blank spaces, Inf, etc, etc.   you are essentially &lt;br&gt;
&amp;gt; doing a poor man's integration but have not accounted for the situation where the&lt;br&gt;
&amp;gt; data is unavailable for more than a timeframe.  i would directly access the hardware &lt;br&gt;
&amp;gt; data stream and hex/string parse it out to find the correct codes the machine gives&lt;br&gt;
&amp;gt; for non-existant data.&lt;br&gt;
&lt;br&gt;
No there really is no data in a &quot;drop out&quot;.  The data is from an RF telemetry acquisition system so when there is interference the frame sync pattern is lost and the data recorders have a gap in the time tagged (IRIG-B) output.  Also there are times when a individual minor frame of telemetry becomes corrupt.  We have certain methods to determine when this happens and discard that minor frame which in general removes a single sample in a data item creating another gap in time. (More than 1 sample if super-commutated)&lt;br&gt;
&lt;br&gt;
This particular data item has a mandatory requirement that a moving window average of a particular time interval (lets say 1 second) be less than a certain value.  This has been interpreted as all data samples within that time window (not 100 samples if it is 100Hz) because of the data dropout issue described above.&lt;br&gt;
&lt;br&gt;
To the other poster I will try what you described and post back here later today.  Plus I will try to mex the code to see if it speeds it up to a reasonable runtime.</description>
    </item>
  </channel>
</rss>

