% 2-d averaging lowpass filter using the DFT
clear
x=[1 -1 3 2;
   2 1 2 4;
   1 -1 2 -2;
   3 1 2 2]; % input
h=[1 1 0 0 0 0 0 1]; % decomposed filter coefficients
H=fft(h); % dft of filter
X=fft2(x,8,8); % dft of input
%
Y=zeros(8);
for k=1:8
  Y(1:8,k)=X(1:8,k) .* H'; % column filtering
end
for k=1:8
  Y(k,1:8)=Y(k,1:8) .* H; % row filtering
end
%
disp('scaled output')
y=real(ifft2(Y)); % idft is the output
round(y(1:4,1:4))

 


 
 

