Fourier series and discretization
Given a -periodic function we can define the Fourier series representation of by
where the Fourier coefficients are given by
We can discretize the integral defining the Fourier transform by chosing a grid of points
Note that and more generally . By the assumed periodicity of , we have . Discretizing the integrals defining the Fourier coefficients, we get
The quantity defined by the sum on the right hand side is called the discrete Fourier transform (DFT) of the sequence , and we have the approximation . Of course, for this approximation to be good, we need that the integrand not vary rapidly on the scale of the grid spacing. For a fixed function , the exponential factor varies on a length scale as , while for a given , the grid spacing is fixed at . Consequently, we cannot approximate all the Fourier coefficients by this discretization. Rather, we only get good approximations for . It is also easy to see that, as a function of , is periodic, with . However, there is no reason for the Fourier coefficients of a periodic function to also be periodic. This again illustrates that the approximation can only hold for for a few values of , if at all.
With an appropriate rescaling, the Discrete Fourier Transform and its inverse are given by the matlab functions
fft
andifft
. In terms of these functions, the (approximate) computation of the Fourier coefficients and the inverse operation of(approximately) reconstituting the function from (finitely many of) its Fourier coefficients are
F = fft(f)/M; f = ifft(F)*M;
This above discussion gives one interpretation of the Discrete Fourier transform and its inverse. An alternate interpretation is in terms of Fourier representation of functions on finitely many points (i.e. the functions are discrete "from the very beginning") in which case they can be represented exactly by finitely many Fourier coefficients, so there is really no "approximation".
Contents
Example 1: A sine wave
Example 2: A square pulse
l
f
(
x
)
f
f
(
x
) =
∑
(
k
)
k=−∞∞
f
ˆ
e
2πikx/l(
k
)
f
ˆ
(
k
) =
f
(
x
)
dx
.
f
ˆ
1
l
∫
l0
e
−2πikx/l
M
=
,
i
= 0, 1, 2, … ,
M
−
1,
=
f
( ).
xi
il
M
fi
xi
=
l
XM
xi
+M= +
xi
l
f
fi
+M=
fi
(
k
)
≈
F
(
k
)
≡
.
f
ˆ
1
M
∑
j=0 M−1f
ie
−2πikj/MF
(
k
)
{ ,
fi
i
= 0, 1, … ,
M
−
1}
f
ˆ
(
k
)
≈
F
(
k
)
f
e
−2πikx/ll
/|
k
|
→
0 |
k
|
→ ∞
M
l
/
M
|
k
|
≪
M
k F
(
k
)
F
(
k
+
M
) =
F
(
k
)
(
k
)
≈
F
(
k
)
f
ˆ
Page 2 of 8 file:///Users/shankar/Google%20Drive/Math583/html/DFT.html
Fourier multipliers and windowing
Example 1: A sine wave
M = 16;
xx = 2*pi*(0:M-1)/M; % Discretization of [0,2*pi]
f = 2*sin(2*xx); F = fft(f)/M; disp(F);
Columns 1 through 4
-0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 1.0000i 0.0000 - 0.0000i
Columns 5 through 8
0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i
Columns 9 through 12
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i
Columns 13 through 16
0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 1.0000i -0.0000 - 0.0000i
Note that F(3) = - i, F(15) = i and the rest of the coefficients are zero. Of course so we have and the rest of the coefficients are zero. This suggests that so there is a re-indexing of in the
fft
routine. The first entry in the output offft
corresponds to , the second entry to and so on until the M/2 + 1 th entry is and then by the periodicity of the DFT coefficients, the rest of the coefficients are for negative .kk = [(0:M/2) (-M/2+1:-1)]; disp(kk);
Columns 1 through 13
0 1 2 3 4 5 6 7 8 -7 -6 -5 -4
Columns 14 through 16
-3 -2 -1
2 sin(2
x
) =
i
e
−2ix−
i
e
2ix(2) =
−
i
, (
−
2) =
i
f
ˆ
f
ˆ
f
(2) =
F
(3),
f
(
−
2) =
f
(15)
k
k
= 0
k
= 1
The vector kk contains the appropriate indexing to connect the output of fft to the Fourier coefficients.
Example 2: A square pulse
M = 32;
xx = 2*pi*(0:M-1)/M; % Discretization of [0,2*pi] f = [0 ones(1,M/2-1) 0 -ones(1,M/2-1)];
plot(xx,f);
axis([0 2*pi -1.2 1.2]);
This is a discretization of the idealized square pulse
Computing the Fourier coefficients, we get
The following figure plots the "exact" Fourier coefficients and also the DFT coefficients for the discretized square pulse.
f
(
x
) =
⎧
⎩
⎨⎪⎪
1
−
1
0
0 <
x
<
π
π
<
x
< 2
π
x
= 0,
π
(
k
) =
f
(
x
)
dx
=
{
f
ˆ
1
2
π
∫
2π
0
e
−ikx
−
π2ki0
Page 4 of 8 file:///Users/shankar/Google%20Drive/Math583/html/DFT.html
F = fft(f)/M; % DFT coefficients
kk = [(0:M/2) (-M/2+1:-1)]; % indexing of k fhat = -1i*(1-(-1).^kk)./(pi*kk);
plot(kk,imag(F),'ro',kk,imag(fhat),'b*');
Note that the coefficients for close to zero are approximated very well, but the coefficients for are approximated comparatively poorly.
Fourier multipliers and windowing
We will now compute for the square pulse for . The Fourier coefficients for are certainly well
approximated by the DFT coefficients. Consequently, we can obtain by using a Fourier multiplier that is for and 0 otherwise.
Lambda = (abs(kk) <= 4); display([kk;Lambda]);
ans =
Columns 1 through 13
k
|
k
|
∼
M
/2
[
f
]
S
NN
= 4
f
ˆ
(
k
)
|
k
|
≤
4
[
f
]
0 1 2 3 4 5 6 7 8 9 10 11 12 1 1 1 1 1 0 0 0 0 0 0 0 0
Columns 14 through 26
13 14 15 16 -15 -14 -13 -12 -11 -10 -9 -8 -7 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 27 through 32
-6 -5 -4 -3 -2 -1 0 0 1 1 1 1
We indeed have the right definition of . Now we compute by
S4f = M*ifft(Lambda.*F);
plot([xx 2*pi],[f 0;S4f 0],'-o');
The Gibbs phenomenon is clearly evident. We can also estimate the error by approximating the integral by a sum
Λk
SN
[
f
]
Page 6 of 8 file:///Users/shankar/Google%20Drive/Math583/html/DFT.html
For our function and we chose above so that
err = sqrt(2*pi/M)*norm(f-S4f); display(err);
err =
0.5448
As a check, this quantity depends only on and should therefore be independent of provided is sufficiently large so that the Fourier coefficients with are estimated accurately.
M = 256;
xx = 2*pi*(0:M-1)/M; % Discretization of [0,2*pi] f = [0 ones(1,M/2-1) 0 -ones(1,M/2-1)];
F = fft(f)/M; % DFT coefficients kk = [(0:M/2) (-M/2+1:-1)];
Lambda = (abs(kk) <= 4); S4f = M*ifft(Lambda.*F); plot([xx 2*pi],[f 0;S4f 0]); err = sqrt(2*pi/M)*norm(f-S4f); display(err);
err =
0.7591
(
f
−
[
f
]
dx
≈
(
−
( [
f
]
.
∫
l
0
S
4)
2
l
M
∑
i=0 M−1f
iS
4)
i)
2l
= 2
π
M
= 32
[
f
]
SN
M
M
≫
N
M = 1024;
xx = 2*pi*(0:M-1)/M; % Discretization of [0,2*pi] f = [0 ones(1,M/2-1) 0 -ones(1,M/2-1)];
F = fft(f)/M; % DFT coefficients kk = [(0:M/2) (-M/2+1:-1)];
Lambda = (abs(kk) <= 4); S4f = M*ifft(Lambda.*F); plot([xx 2*pi],[f 0;S4f 0]); err = sqrt(2*pi/M)*norm(f-S4f); display(err);
err =
Page 8 of 8 file:///Users/shankar/Google%20Drive/Math583/html/DFT.html
Exercise: Show that the error in the approximation is
This value can be computed exactly. It equals
Published with MATLAB® R2014b
L
2S
4[
f
]
≈
f
∥
f
−
S
4[
f
]
∥
2L2=
16
π
∑
k=2∞
1
(2
k
+ 1)
2