help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

address@hidden: address@hidden: Re:]]


From: Przemek Klosowski
Subject: address@hidden: address@hidden: Re:]]
Date: Tue, 28 Mar 2006 14:59:59 -0500 (EST)

  >for which matlab/octave is relevant, one of my questions is:
  >
  >how would you calculate a 10 sample running average on a 100 element vector?

This is actually an interesting case; two 'vector' approaches that I could
think of are:

 N=100;n=3;a=rand(N,1); 
 result=shift(conv(a,ones(1,n)),-fix(n/2))(1:N)/n;
 result=filter([ones(1,n),zeros(1,N-n)],eye(1,N),a)/n; 

I'd argue that the vectorized formulation is not so obvious, because
it has to deal with the issue of filtering at the edges of the data
vector. The loop implementation sounds simple, until you start
thinking about implementing reasonable behavior at the start and end
of the data vector. 

When I thought about the vector approach, it forced me to think
about the meaning of the boundary conditions, rather than thinking
in terms of loop indexing tricks that need to be done. So maybe it
is good that vectorizing requires thinking different from writing
loop code? Plus, the filter() approach forced me to re-read the 
description of filter() and ponder on all the neat things that 
digital filters can do.

     p



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]