# How to calculate the Fourier transform of a mean filter in Matlab?

In Matlab, how can I calculate the discrete-space Fourier transform of a mean which takes the average of 4 adjacent points, with this kernel

$$\begin{pmatrix} 0 &1& 0\\ 1 &0& 1\\ 0 &1& 0\\ \end{pmatrix}$$

• not quite sure what you mean, here. Assuming you mean the 2D-DFT: Matlab documentation, "2D-DFT", will lead you to the right function. NB: probably not the info you're looking for, unless you're only planning to average 3×3 images. – Marcus Müller Nov 21 '18 at 18:36

Then if you create a 3x3 matrix h = [0,1,0 ; 1,0,1; 0,1,0] in matlab and you wish to perform a 2D-DFT on that matix h, then the following function call H = fft2(h) will return you the 3x3 discrete Fourier transform $$H[k_1,k_2]$$ (k1 rows, k2 columns) samples of the filter $$h[n_1,n_2]$$ as:
$$H[k_1,k_2] = e^{ -j \frac{2\pi}{3} k_1} + e^{ -j \frac{2\pi}{3} k_2} + e^{ -j \frac{2\pi}{3} 2 k_1}e^{ -j \frac{2\pi}{3} k_2} + e^{ -j \frac{2\pi}{3} k_1}e^{ -j \frac{2\pi}{3} 2 k_2}$$ for $$k_1,k_2 = 0,1,2$$.
If you want to compute a larger $$N \times N$$ 2D-DFT on $$h[n_1,n_2]$$, then the following call H = fft2(h,N,N) will return you an $$N \times N$$ result as: $$H[k_1,k_2] = e^{ -j \frac{2\pi}{N} k_1} + e^{ -j \frac{2\pi}{N} k_2} + e^{ -j \frac{2\pi}{N} 2 k_1}e^{ -j \frac{2\pi}{N} k_2} + e^{ -j \frac{2\pi}{N} k_1}e^{ -j \frac{2\pi}{N} 2 k_2}$$ for $$k_1,k_2 = 0,1,...,N-1$$.