Code covered by the BSD License  

Highlights from
Moving averages / Moving median etc

3.55556

3.6 | 9 ratings Rate this file 147 Downloads (last 30 days) File Size: 1.66 KB File ID: #8251
image thumbnail

Moving averages / Moving median etc

by Aslak Grinsted

 

09 Aug 2005 (Updated 16 Jun 2011)

Calculates moving averages (or median/fun) of a timeseries.

| 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 (15)
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  
13 May 2010 Z Izham

Better than Matlab's moving average function, simple and does the trick

02 Nov 2011 Sherif

Works well, thanks.

14 Feb 2012 Olesya

Works great, thanks so much for posting!

14 Feb 2012 Olesya  
Please login to add a comment or rating.
Updates
07 Jul 2008

Made more flexible and more robust.

16 Jun 2011

added Screenshot, updated description

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
moving median Aslak Grinsted 16 Jun 2011 08:46:52
running median Aslak Grinsted 16 Jun 2011 08:46:52
running mean Aslak Grinsted 16 Jun 2011 08:46:52
smoothing Aslak Grinsted 16 Jun 2011 08:46:52
windows Aslak Grinsted 16 Jun 2011 08:46:52
moving maximum Aslak Grinsted 16 Jun 2011 08:46:52
statistics Aslak Grinsted 16 Jun 2011 09:47:44
smooth Aslak Grinsted 01 Jul 2011 06:41:03
wavelets Ri 02 Aug 2011 15:35:15
convolution Aslak Grinsted 04 Aug 2011 07:04:57
nlfilter Aslak Grinsted 18 Aug 2011 06:03:28
colfilt Aslak Grinsted 18 Aug 2011 06:05:06
blockfilt Aslak Grinsted 18 Aug 2011 06:05:26
wavelets Alexander Zimin 17 Apr 2012 07:15:12
moving averages Matti Tähtinen 23 Apr 2012 08:40:47

Contact us at files@mathworks.com