On Sep 11, 10:19 am, "John Deas" <john.deas.smash.s...@gmail.com>
wrote:
> Hi, I need to write my own version of a 2d dft algorithm. I
> wanted to compare the results with Matlab's fft2d
> algorithm, but I can not find why they give different
> bidimensional spectrums.
> Here is my code, with some graphical outputs to underline
> the differences.
>
> %  beginning code
>
> % user input variables
> N=10;
> x=zeros(N,N);
>
> % 2D function to be analyzed
> for i=1:N
> for j=1:N
> x(i,j)=((iN/2)^2+(jN/2)^2)^(1/2);
> end
> end
>
> c=N/10/(2*(2*log(2))^1/2);
>
> for i=1:N
> for j=1:N
> x(i,j)=exp(((x(i,j)N/4)^2)/(2*c^2));
> end
> end
>
> mesh(x);
> title('Function to be analyzed');
> pause;
>
> % actual dft computation
> fftx=zeros(N,N);
>
> for k=1:N
> for l=1:N
> for n=1:N
> for m=1:N
> fftx(k,l)=fftx(k,l)+x(n,m)*exp(j*2*pi*((k
> 1)*(n1)/N+(l1)*(m1)/N));
> end
> end
> end
> end
>
> mesh(abs(fftx));
> title('User produced 2D dft');
> pause;
>
> mesh(abs(fft(x)));
> title('Matlab fft2d result');
> pause;
>
> % comparison with Matlab result
> Err=norm(fftxfft(x));
>
> %  end code
>
> Any help would be appreciated as I am stuck on this for
> some times without much results...
>
> Thanks,
>
> J.D.
Perhaps using matrix notation would help. See my post
in the thread "inverse fft without ifft".
Hope this helps.
Greg
