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.

### Like this:

Like Loading...

*Related*

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.