I am assuming that you want to apply FFT shift to a 2D FFT to get the zero-frequency (DC) component at the centre of the spectrum. Also, the highest frequencies should be at the corners. Please find some relevant changes below to the code provided in the question which can help us achieve the same-
- Meshgrid for Frequency Mapping- The code provided in the question is not centered correctly for even-sized images. For even m, zero-frequency is between pixels (m/2, m/2) and (m/2+1, m/2+1), as mentioned in the code below-
[XX, YY] = meshgrid( (-m/2):(m/2-1), (-m/2):(m/2-1) );
- Radial Profile Binning- The binning in the code may not be robust. Instead, we can use the “accumarray” function in MATLAB for radial averaging, as follows-
R = sqrt(XX.^2 + YY.^2);
R = round(R); % integer radius
maxR = max(R(:));
profile = accumarray(R(:)+1, w(:), [maxR+1 1], @mean, NaN);
For more information on the usage of “accumarray” function, please refer to the documentation link below-https://www.mathworks.com/help/releases/R2024b/matlab/ref/accumarray.html
- Frequency Axis- The frequency axis calculation in the code provided can be modified. For a pixel size of 0.68 mm, the frequency step is:
dx = 0.68; % mm
freq_step = 1/(m*dx);
frequencies = (0:maxR) * freq_step;
After incorporating the above changes, we can visualise the frequencies as follows-

I hope the above explanation helps to solve the question.
