function y=filt2d(x,n,f);
% FILT2D:  applies 2-D filter to matrix by filtering rows and columns
% usage:   y=filt2d(x,n,f)
%	   Applies 1-D Butterworth filter to all columns and then to all
%	   rows. Since these filters are linear, order of filtering does not
%	   matter and symmetry of matrices is preserved.
%	   n+1 is the length of the filter
%	   f the cutoff frequency, in units of Nyquist (1/2 sample frequency).
%	   (To filter out point-to-point ripples, n=2, f=.5-.75 suffices).
%	   The columnwise filter routine is MATLAB's filtfilt, which preserves
%	   phase and works well at ends of interval

%	Uwe Send, IfM/Kiel, Feb 1991	 	

[b,a]=butter(n,f)
[m,n]=size(x);
for i=1:n;
	x(:,i)=filtfilt(b,a,x(:,i));
end;
for j=1:m;
	x(j,:)=(filtfilt(b,a,(x(j,:))'))';
end;
y=x;
