2.83333

2.8 | 6 ratings Rate this file 150 downloads (last 30 days) File Size: 1.43 KB File ID: #8251

Moving averages

by Aslak Grinsted

 

09 Aug 2005 (Updated 07 Jul 2008)

No BSD License  

Calculates moving averages of timeseries.

Download Now | Watch this File

File Information
Description

MOVING will compute moving averages of order n (best taken as odd)
 
 Usage: y=moving(x,n[,fun])
 where x is the input vector (or matrix) to be smoothed.
       m is number of points to average over (best odd, but even works)
       y is output vector of same length as x
       fun (optional) is a custom function rather than moving averages
 
  Note:if x is a matrix then the smoothing will be done 'vertically'.
  
 
  Example:
 
  x=randn(300,1);
  plot(x,'g.');
  hold on;
  plot(moving(x,7),'k');
  plot(moving(x,7,'median'),'r');
  plot(moving(x,7,@(x)max(x)),'b');
  legend('x','7pt moving mean','7pt moving median','7pt moving max','location','best')

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
03 Oct 2005 N. Schneebly

use Matlabs smooth function

06 Oct 2005 Aslak Grinsted

moving can handle multiple columns at once which smooth can not. Smooth always uses an odd size window, even if you ask for an even sized one. They also handle edges a little differently. With moving.m it is very easy to spot where the edge is affecting the average.

So, i think smooth does not make moving obsolete.

22 Feb 2006 kývanç kýlýç

not work

01 Mar 2006 Aslak Grinsted

Just delete it then. I'll still use it myself.

21 Jun 2006 Felix Jose

The script is excellent for wave data smoothing

31 Aug 2006 Matteo De Felice

not work

21 Feb 2007 Johannes Driessen

Error in ==> moving at 27
y=y([zeros(1,m2)+m2+1,(m2+1):(n-n2),zeros(1,n2)+(n-n2)],:);

21 Feb 2007 Johannes Driessen

(Sorry - error reported is as follows:)

??? Subscript indices must either be real positive integers or logicals.

07 Jul 2008 Aslak Grinsted

Hi. I've updated the script to make it much more flexible. You can now easily calculate things like the moving 90th percentile.

For people with errors: i would appreciate if you email me your problems directly so that i can improve the code.

27 Jul 2008 P. Strömholm

works great and is very fast. thanks

22 Jul 2009 Daniel Høyer Iversen  
Please login to add a comment or rating.
Updates
07 Jul 2008

Made more flexible and more robust.

Tag Activity for this File
Tag Applied By Date/Time
time frequency Aslak Grinsted 22 Oct 2008 07:55:32
wavelets Aslak Grinsted 22 Oct 2008 07:55:32
moving averages Aslak Grinsted 22 Oct 2008 07:55:32
boxcar Aslak Grinsted 22 Oct 2008 07:55:32
rectangle Aslak Grinsted 22 Oct 2008 07:55:32
lowpass Aslak Grinsted 22 Oct 2008 07:55:32
timeseries Aslak Grinsted 22 Oct 2008 07:55:32
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com