# MATLAB- 2D DFT very slow

I have to wrie my own 2D DFT and I'm currently using this

for l=0:1:m-1 for k=0:1:n-1 for x=0:1:n-1 for y=0:1:m-1 a=x+1;b=y+1; c= im3(a,b) * exp(-1i*2*pi*(k*x/n + l*y/m)); c1=c1+c; end end aa=l+1;bb=k+1; im(bb,aa)=c1; c1=0; end end

It works fine for smaller images but when the pixel dimensions or the array gets bigger it gets insanely slow. Can anyone help?

the im3is the array that has the pixel values stored and im is the one that stores the values after the algorithm executes

## Answers

To compute 2D DFT you need to compute DFT for rows, and then for cols. Try out this code

f1=imread('Lady.tif') [M1,N1]=size(f1) DFT=exp(sqrt(-1)*2*pi*(n).*(k)./512); %img=x.'; F1R=zeros(M1,N1); F1RC=zeros(M1,N1); for row=1:M1; x=f1(row,:)'; F1R(row,:)=((DFT*x)'); end %%part one for col=1:N; x=F1R(:,col); F1RC(:,col)=((DFT'*x)); end

Btw, fft2 should get you 2D DFT too

Check out this link http://www.mathworks.com/help/signal/ug/discrete-fourier-transform.html