0

This might be considered a repost of this question however I am seeking a much deeper explanation on this matter and how to properly solve this problem.

I want to study the PSF/SRF of a voxel in a 44x44 matrix. For that I create a matrix 100x bigger (4400x4400) so 1 voxel in the smaller matrix corresponds to 100x100 voxels in the bigger one. I set the values to 1 of those 100^2 voxels.

Now I do a FFT of the big matrix and an IFFT of only the center portion (44x44) of the frequency space. This is the code:

A = zeros(4400,4400); 
A(2201:2300,2201:2300) = 1;
B = fftshift(fft2(A));
C = ifft2(ifftshift(B(2179:2222,2179:2222)));
D = numel(C)/numel(B) * C;

figure, subplot(1,3,1), imshow(A), subplot(1,3,2), imshow(real(C)), subplot(1,3,3), imshow(real(D));

The problem is the following: I would expect the value in the voxel of the new 44x44 matrix to be 1. However, using this numel factor correction they decrease to 0.35. And if I don't apply the correction they go up to huge values.

Andre
  • 49
  • 1
  • 6

1 Answers1

0

For starters, let me try to clarify the scaling issue: For the DFT/IDFT there are various scaling conventions regarding the input size. You either need a factor of 1/N in the DFT or a factor of 1/N in the IDFT or a factor of 1/sqrt(N) in both. All have pros and cons and all are equally valid.

Matlab uses the 1/N in the IDFT convention, as you can see in the documentation.

In your example, the forward DFT has a size 4400, the backward IDFT a size of 44. Therefore the IDFT scaling is a factor 100 less than it should be to match the forward transformation and your values are a factor of 100 too large. Since you're doing a 2-D DFT/IDFT, the factor 100 is missing twice, so your rescaling should be 100^2. Your numel(C)/numel(B) does exactly that, I've just tried to give you the explanation for it.

A reason why you might not see the 1 is that you're plotting only the real part of the inverse DFT. Since you did some fftshifting you might have introduced a phase so that part of your signal is in the imaginary part.

edit: Another reason is that you truncate B to the central 44 by 44 window before transforming back. Since A is not bandlimited, B has energy also outside this window. By truncating you are losing a part of it. Therefore, it is not surprising that the resulting amplitude is lower.

Here is a zoom on the image of B to show this phenomenon:

Zoom on B

The red square is what you keep, everything else is truncated. Due to Parsevals theorem, the total energy in image and Fourier domain is equal so by truncation you must also reduce the energy of your signal in the image domain.

Florian
  • 1,804
  • 2
  • 9
  • 19
  • I understand your point. However in this example my data is a real integer (1) and the result from that process should be a complex number which imaginary part should be only residual. Regarding the fftshift part, I missed some explanation there, but I want to see truncation artifacts. That's why I only take the center portion of my frequency domain. – Andre Feb 17 '17 at 10:45
  • I looked at your data in more detail. The problem was not the imaginary part. I think it is mostly due to truncation. I've made an edit to clarify this point. – Florian Feb 17 '17 at 12:04