For a task for university, I need to calculate in matlab a partial derivative using the 2D Fourier transform. Using equation (13) on pg 3 in , we have the formula $$\mathbb{F}_2 ( \frac{df(u,v)}{du} )= i 2 \pi u f(u, v)$$ So when implement it in matlab (so then we use the discrete version of the fourier transform), It went a bit wrong. Based on I have following code where we use the function $f(x,y) = \sin(x2 \pi)$ as test function, so the derivative is $\cos(x2 \pi)2 \pi$
N = 64; dkx = 1/N; dky = 1/N; kx = -1/2: dkx : 1/2-dkx; % x-wavenumber ky = -1/2 : dky : 1/2-dky; % y-wavenumber [X,Y] = meshgrid(kx,ky); data_spacedomain = sin(X*2*pi); % Compute 2D FFT data_wavenumberdomain = fft2(data_spacedomain); % Compute grid of wavenumbers [KX, KY] = meshgrid(ifftshift(kx),ifftshift(ky)); % Compute 2D derivative data_wavenumberdomain_differentiated = 1i*2*pi*KX.*data_wavenumberdomain; % Convert back to space domain data_spacedomain_differentiated = ifft2(data_wavenumberdomain_differentiated ); figure(1) surf( X,Y,real(data_spacedomain_differentiated )) figure(2) surf( X,Y, cos(X*2*pi)*2*pi)Then the derivative ( equal to $\cos(x2 \pi)2 \pi$) is
but the derivative I get from my program, is
Has someone an idea where in my code it went wrong?
1 Answer
$\begingroup$you need to multiply with $N$, so you need to plot real(data_spacedomain_differentiated*N ) , If you do so , it is exactly the same !!
$\endgroup$ 1