ECL – S7 – Waves in Fluids 1
Homework 1 – Fourier’s transform using Matlab
1. Write a Matlab script to compute the Fourier transform ĝ0 (k1 ) of
1
g0 ( x 1 ) =
1 + ( x1 /l )2
Verify your result with the analytical solution ĝ0 (k1 ) = (l/2) exp (−l |k1 |), and plot the two func-
tions. Verify also Parseval’s identity.
Take the inverse Fourier transform to retrieve g0 ( x1 ).
Study two cases corresponding to a low and a high frequency resolution, by justifying your choice.
A tutorial is provided in the next page.
2. Write a short report to document your Matlab script. Note that the script will be used in the next
classroom to calculate solutions based on Fourier integrals.
Definition of the Fourier transform
Z +∞ Z +∞
1 −ik1 x1 −1
ĝ0 (k1 )eik1 x1 dk1
ĝ0 (k1 ) = F [ g0 ( x1 )] = g0 ( x 1 ) e dx1 g0 ( x 1 ) = F ĝ0 (k1 ) =
2π −∞ −∞
Parseval’s identity
Z +∞ Z +∞
g02 ( x1 )dx1 = 2π | ĝ0 (k1 )|2 dk1
−∞ −∞
fft ifft
N N
1
∑ g0n e−i2π (n−1)(l −1)/N ∑ ĝ0l ei2π(n−1)(l−1)/N
ĝ0l = 1≤l≤N [ g0n ] = 1≤n≤N
n =1
N l =1
dx 2π 1
× 1
ĝ0l = ĝ0l g0n = [ g0n ] × dk1 = 2π ×
2π dx1 Ndx1
TABLE 1 – FFT using Matlab. Note that fftshift and ifftshift are exactly the same for N even : it is recom-
mended to choose N even (and it just doesn’t matter !)
ECL – S7 – Waves in Fluids 2
Tutorial for a Gaussian function g0
x 2 b (bk1 )2
g0 ( x1 ) = e− ln 2( b )
1
ĝ0 (k1 ) = √ e− 4 ln 2
2 π ln 2
%.. Fourier transform of a Gaussian function g0 with nfft even 1.0
nfft = 64; nf = nfft/2;
0.8
x = linspace(-12,12,nfft+1);
g0 ref (x1 )
0.6
nx = length(x); nx2 = (nx+1)/2;
0.4
dx = x(2)-x(1); 0.2
dk = 2*pi/(nfft*dx);
0.0
−12 −8 −4 0 4 8 12
x1
%.. analytical solution g0ref and g0kref
b = 3.;
g0ref = exp(-log(2.)*(x/b).^2);
kx = -nf*dk:dk:nf*dk;
g0kref = b/(2.*sqrt(pi*log(2.))) * exp(-(kx*b).^2/(4*log(2.)));
%.. Fourier transform 1.0
x1 = 0:dx:(nfft-1)*dx;
0.8
g1 = fftshift(g0ref(1:nfft));
0.6
g1 (x1 )
0.4
0.2
0.0
−12 −6 0 6 12 18 24
x1
g0 ref ◦ g1
kx1 = 0:dk:(nfft-1)*dk;
1.0
gk1 = fft(g1) * dx/(2*pi);
× Im(ĝ2 )
0.8
kx2 = -nf*dk:dk:(nf-1)*dk; 0.6
gk2 = fftshift(gk1); 0.4
+Re(ĝ2 )
0.2
0.0
−4 −2 0 2 4
k1
+ℜ( gk2 ) ×ℑ( gk2 ) ◦ gk0 ref
%.. Inverse Fourier transform 1.0
gk2 = ifftshift(gk2);
0.8
gdef = ifft(gk2);
g0 ref (x1 )
0.6
gdef = gdef *2*pi/dx;
0.4
xdef = -nf*dx:dx:(nf-1)*dx; 0.2
gdef = fftshift(gdef);
0.0
−12 −8 −4 0 4 8 12
x1
g0 ref ◦ gdef