No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Moving variance

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.85714
4.9 | 7 ratings Rate this file 25 Downloads (last 30 days) File Size: 358 Bytes File ID: #8252 Version: 1.0

Moving variance

by

Aslak Grinsted (view profile)

 

09 Aug 2005 (Updated )

Calculates moving variance of a time series.

| Watch this File

File Information
Description

Moving variance
  
  v=movingvar(x,m)
 
  x is the timeseries.
  m is the window length.
  v is the variance.
 
  Aslak Grinsted 2005

Acknowledgements

This file inspired Downsample Ts and Scatstat2 2 D Local Statistics.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
11 Aug 2016 Paul Mellor

I believe n2 and m2 are the wrong way round: the longer sequence to remove is at the end not the start (try with a constant vector e.g. ones(1000,1)).

Also v can end up with a small negative value, which is not good for a variance. So I suggest:

v=filter2(f,x.^2)-filter2(f,x).^2;
n2=floor(m/2);
m2=ceil(m/2)-1;
v=max(0, v([zeros(1,m2)+m2+1,(m2+1):(n-n2),zeros(1,n2)+(n-n2)],:));

05 May 2016 Tyler Critchfield  
09 Apr 2015 Michel Allegue  
14 Feb 2014 Maty

Maty (view profile)

 
30 May 2012 Ilayda

Ilayda (view profile)

 
16 Jul 2008 xin wang  
08 Nov 2005 Jonathan Tinker

Excellent, does just what I needed, without using a loop. NB/ this is the biased variance.

Contact us