function filter,d,c,u ; An implementation of a discrete linear filter that is described ; by the weight vectors a and b. ; ; CALCULATION ; y(n)=b(0)x(n)+b(1)x(n-1)+...+b(Q)x(n-Q)-a(1)y(n-1)-a(2)y(n-2)-... ; -a(P)y(n-P) ; This construction assumes that a(0)=1. ; Harvey E. Rhody ; January, 1997 ; Change the names of the parameters to protect their values. b=d & a=c & x=u P=N_ELEMENTS(a)-1 IF (P GT 0) THEN begin z=FLTARR(P) ; History of past outputs array. a=a(1:P) ; Drop the a(0) element, assumed to be 1. endif n=N_ELEMENTS(x) Q=N_ELEMENTS(b) IF Q GT 1 THEN BEGIN x=[FLTARR(Q-1),x] ; Augment the input array with zeros ; so the full output can be generated. ENDIF y=fltarr(n) ; Create an array for the output values. b=ROTATE(b,2) ; Flip b end for end b=TRANSPOSE(b) ; Make b a column vector IF (P GT 1) THEN BEGIN a=TRANSPOSE(a) ; Make a into a column vector. for k=0,n-1 do begin y(k)=x(k:k+Q-1)##b-z##a z=[y(k),z(0:P-2)] endfor ENDIF ELSE $ IF P EQ 1 THEN BEGIN FOR k=0,n-1 DO BEGIN y(k)=x(k:k+Q-1)##b-z*a z=y(k) ENDFOR ENDIF ELSE BEGIN FOR k=0,n-1 DO BEGIN y(k)=x(k:k+Q-1)##b ENDFOR ENDELSE return,y end