Fast data smoothing using a running average

In the lab, we preprocess eye position data using a running average. We previously used the matlab smooth function, with the ‘moving’ argument. This matlab function implements very generic data smoothing, and is therefore unoptimized and slow. You can download a better running average function from matlab central called runmean. For a window size of 5, it is about 5-fold faster than the generic algorithm. Here’s an example:

eyep = rand(1,1000000);
tic;
eyeps1 = smooth(eyep,’moving’,5);
toc;

tic;
eyeps2 = runmean(eyep,2)’;
toc;

plot(1:1000,eyeps1(1:1000),1:1000,eyeps2(1:1000))

The outputs of the two functions are the same except for edges, and on my computer the builtin function takes 0.33 seconds to run while runmean takes 0.07 seconds, so it’s worth the trouble.


One thought on “Fast data smoothing using a running average

  1. Sounds like it’s computing a running mean by way of a Fast Fourier Transform. A running mean is just a convolution after all.

    Nice blog, keep up the good work.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s