[sorry for repost: maybe my original post gave an impression that
I am not asking seriously, but I think it's an important and
frequent use case, so here it is again]

Often, I need to smooth/average a data vector. I usually do a
running average using filter(), e.g. for 5-value average:

filter(ones(1:5)/5,eye(5,1),x)

I've been doing this for years, so I got used to it even though I
have to think a little every time I need to do again, but maybe
there's a better way? What do y'all use?

By the way, sometimes I'd use a Savitzky-Golay
peak/moment-preserving filter coefficients instead of a simple
rectangular averaging window:

# Copyright (C) 1993 Przemek Klosowski ; licensed under GPL

#

# You should have received a copy of the GNU General Public
License

# along with Octave; see the file COPYING. If not, write to the
Free

# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

function retval = savgol (m,nl,nr)

# usage: savgol (m,n) or (m,nl,nr)

# m - order -nl..nr - smoothing window

#

# Return the Savitzky-Golay filter coeffs for 2n window, order m.

# Ref.: Num.Rec. (2nd edition) p. 650

# Try plot([savgol(2,8);savgol(4,8);savgol(6,8)]'); sometime

# filter coeffs are in first row of (A'*A)^-1 * A'

if (nargin == 2)

nr = nl; nl = nl;

elseif (nargin!=3)

error ("usage: savgol (n,m)");

endif

nmax = length(nl) * length(nr) * length(m);

if (nmax == 1)

if (nl<0 || nr<0 )

error (" n must be positive in savgol()");

endif

ii = -nl:nr;

jj = 0:m;

A = repmat(ii',1,m+1).^repmat(jj,nl+nr+1,1) ;

A=(A'*A)^-1 * A';

retval=A(1,:);

else

error ("savgol: expecting scalar arguments, found something
else");

endif

endfunction

_______________________________________________

Help-octave mailing list

[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave