comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » algorithm question. Can I get rid of the for loop?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
algorithm question. Can I get rid of the for loop? [message #83759] Thu, 21 March 2013 14:32
Søren Frimann is currently offline  Søren Frimann
Messages: 13
Registered: November 2010
Junior Member
Hi All.

I have an implementation of a hampel filter (see e.g. http://exploringdatablog.blogspot.dk/2012/01/moving-window-f ilters-and-pracma.html) in IDL.

My implementation looks like this:

##############################################
FUNCTION hampel, x, y, dx, THRESHOLD=threshold

Compile_Opt idl2

IF N_Elements(threshold) EQ 0 THEN $
threshold = 3

;initialize arrays
s0 = FltArr(N_Elements(y))
y0 = FltArr(N_Elements(y))
yy = y

FOR i=0,N_Elements(y)-1 DO BEGIN
index = Where((x GE x[i] - dx) AND (x LE x[i] + dx))
y0[i] = Median(y[index]) ; Median filtering
s0[i] = 1.4826*Median(Abs(y[index] - y0[i])) ;estimating uncertainty
ENDFOR

ol = Where(Abs(y - y0) GE threshold*s0) ;Index of outliers
yy[ol] = y0[ol]

result = Create_Struct('y',yy, $
'sigma',s0)

RETURN, result

END
##############################################

the filter runs a moving window of width 2*dx measured in the same units as x.
x is generally not uniformly spaced (so there's not a constant number of points inside the window as it moves).
x and y can be quite long vectors so the filter takes a long time to run.
Can anyone see any method for speeding the code up?
Any help would be much appreciated!

Cheers,
Søren
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: setting text in editable combobox widgets
Next Topic: cgblendimage without a window? - a bit stuck!

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:44:44 PDT 2025

Total time taken to generate the page: 0.19433 seconds