0
$\begingroup$

I have a certain 2-D function. More properly, I have not the function itself, but the matrices $[X,Y,Z]$, where $X,Y$ are $1\times n$, and $Z$ is $n \times n$.

Now, I want to calculate a a new matrix, $\hat Z$, whose value at each point is the average of $Z$-values from a small region around that point. In other words, $\hat Z(p) = \frac{\int_{B(p,r)} Z(x,y)dxdy}{\pi r^2}$ for some small fixed $r$.

The way I have decide to do this is via convolution with a $\delta$ -like function, and thus via multiplication of the respected FFT transforms.

I find the FFT of $Z$, as well as the FFT of a cylinder with base $B(0,r)$, and volume $1$. Then I take the product of the FFT transforms, and then take the absolute value of the inverse transform to be $\hat Z$.

Visually, the result looks correct, i.e. when plotting $\hat Z$ it does look like the original, only more "smoothed-out". When I increase $r$, the result becomes further flatter and flatter.

But the are some scaling issues, by which I mean that the scaling of the end result is completely off (orders of magnitude), whereas for small $r$ I expect the range to be roughly the same. I suspect that to be a known issue with the FFT transform, but I do not manage to find the proper scaling factor.

$\endgroup$

1 Answer 1

1
$\begingroup$

You have to normalize by the number of elements in the FFT. That is if the size of your matrix is $(NxM)$ you must normalize your FFT by $(NxM)$. You can check this is valid by looking at the energy content of the two matrices.

$\endgroup$
4
  • $\begingroup$ The FFT, or the IFFT? Or both? $\endgroup$
    – Aahz
    Nov 11, 2014 at 5:03
  • $\begingroup$ Also, it seems that matlab routines already perform some scaling. For instance, ifft2(fft2(z)) returns the matrix z itself, no scaling needed. However, it seems what I needed to do was making the cylinder (actually, a box in my case) of height $1$, and the normalizing it by the amount of non-zero elements. $\endgroup$
    – Aahz
    Nov 11, 2014 at 7:33
  • 1
    $\begingroup$ The normalization convention is consistent in Matlab and all other packages I know (ifft(fft(z)) == z is True), though typically it is not such that the transform preserves energy. Scaling factors of sqrt(N) for each dimension would be typical here. You only have to think about normalization when you use a Fourier transform computed analytically instead of numerically. The numerics will get it right automatically. $\endgroup$
    – AlexE
    Nov 11, 2014 at 8:22
  • $\begingroup$ Yes, so apparrently I need to scale the $\delta$ function somehow. Currently I choose the height to be the number of non-zero points, and it seems to work (though I am not sure entirely). If I go by "volume = 1", the scaling is way off. $\endgroup$
    – Aahz
    Nov 11, 2014 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.