How can I implement a 2D DFT?

8 ビュー (過去 30 日間)
Carmen Alabart Gutierrez del Olmo
Carmen Alabart Gutierrez del Olmo 2016 年 12 月 10 日
コメント済み: SA 2022 年 2 月 4 日
I have been trying to implement a 2D DFT but the code is not working properly and I cannot find the bug. Can anyone help me?
im = zeros(8,8);
im(1,1) = 1;
[r_im, c_im] = size(im);
S_2 = zeros (size(im));
values = zeros(size(im));
for ky = 1:8
for kx = 1:8
for y = -3:4
for x = -3:4
values(y+4,x+4) = im(y+4,x+4)*exp(((-2i)*pi)*((kx*x/c_im)+(ky*y/r_im)));
end
end
S_2(ky,kx) = sum(sum(values));
values(:,:) = 0;
end
end
S_2 = fftshift(S_2);
MRI_im_2 = abs(ifft(S_2));
figure,
subplot(1,3,1),imshow(im), title('Original Image');
subplot(1,3,2),imshow(S_2,[]),title('FFT Simulation');
subplot(1,3,3),imshow(MRI_im_2,[]), title('IFFT Simulation');
  2 件のコメント
Image Analyst
Image Analyst 2016 年 12 月 10 日
It runs without error. What do you think it's not working? Supply more information about what you think is not right. It's just doing what you told it to.
SA
SA 2022 年 2 月 4 日
@Image Analyst, I've also experienced problems implementing 2d DFT for spatial spectrum. Can you please help me regarding that link https://www.mathworks.com/matlabcentral/answers/1609940-problems-to-plot-2d-wave-vector-versus-spatial-spectrum-obtained-from-cross-spectral-densities-of-se

サインインしてコメントする。

回答 (2 件)

Kushagr Gupta
Kushagr Gupta 2016 年 12 月 20 日
It might also help to compare the result of code written with the inbuilt MATLAB 2D FFT function 'fft2'.
Documentation for the 'fft2' function is available at the following link:

Image Analyst
Image Analyst 2016 年 12 月 20 日
Attached are my 2D fft demos.

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by