2d DFT using 1D DFT twice
Show older comments
How can I do 2D DFT by doing the fourier transform in the X direction first and then the Y direction. Basically what fft2 does but without using fft and using for loop? I am sure I have made many fundamental mistakes.
M=100;
N=100;
X=zeros(M,N);
wm=exp((-1j.*2.*pi)./M);
wn=exp((-1j.*2.*pi)./N);
xm=sin(4*pi.*(1:M))+cos(6*pi.*(1:M));
for u=1:M
X(u)=0;
for m=1:M
X(u,:)=X(u,:)+xm(m)*wm*u*m;
end
end
for v=1:N
X(:,v)=0;
for n=1:N
X(:,v)=X(:,v)+xm(n)*wn*v*n;
end
end
plot(abs(X));
1 Comment
Matt J
on 1 Feb 2013
Your xm doesn't look 2D, so it's not clear in what way you wish to apply a 2D DFT to it.
Answers (1)
xm=rand(M,N); %some 2D image
fft1D=@(z) fft(z,[],1).';
X=fft1D(fft1D(xm));
Categories
Find more on Discrete Fourier and Cosine Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!