Linear Convolution with DFT

3.4.2 Linear Convolution with DFT

As discussed in the previous section, circular translation/convolution is natural with the DFT/DFS. However, in most applications of digital signal processing, linear convolution is necessary. As will be seen later, very efficient algorithms called FFT are available for computing the DFT of a finite-duration sequence. For this reason, it can be computationally advantageous to use the FFT algorithm for computing a convolution in such a way that the linear convolution corresponds to a single period of a circular convolution.

Specifically, suppose the signals x[n] and y[n] are of finite duration N x and N y , and defined on n = 0 : N x − 1 and on n = 0 : N y − 1, respectively. Then, the

procedure for computing the linear convolution z[n] = x[n] ∗ y[n] is as below (see Fig. 3.9):

0) Extend the given sequences x[n] and y[n] to the duration of N ≥ N x +N y −1 by zero-padding where N x +N y − 1 is the expected length of the linear

convolution of the two sequences (see Remark 1.5(1)). (cf.) Zero-padding a sequence means appending zeros to the end of the sequence.)

1) Compute X (k) = DFT N {x[n]} and Y (k) = DFT N {y[n]}. (3.4.17a)

2) Multiply the two DFT sequences Z (k) = X(k)Y (k) for k = 0 : N − 1.

(3.4.17b)

3) Compute z[n] = IDFT N {Z(k)} where z[n] = x[n] ∗ y[n]. (3.4.17c) Example 3.13 Linear Convolution Using the DFT

We want to find the linear convolution z[n] = x[n] ∗ y[n] of the two sequences depicted in Fig. 3.10(a), where

⎪ ⎨ 1 for n = 0 ⎨ ⎪ 0.5 for n = 0 x [n] = 0.5 for n = 1

and y [n] = 1 for n = 1 (E3.13.1) ⎩ ⎪

0 ⎪ elsewhere ⎩ 0 elsewhere

x [n] Zero-padding

N – point X(k) = DFT N {x [n]}

to duration N

DFT

length N x N≥N x +N y – 1 Z(k) = X(k)Y(k) N – point DFT

z [n] y [n]

Zero-padding

N – point

to duration N

DFT

Y(k) = DFT {y [n]}

length N

Fig. 3.9 Linear convolution using the DFT

3.4 Discrete Fourier Transform (DFT) 153 (a) Time-domain approach (Fig. 3.10(a)) z [n] = 0 for n < 0 or n ≥ 3(= N x +N y − 1 = 2 + 2 − 1)

z [0] = x [0] y[0] + x[1] y[−1] = 0.5 z [1] = x [0] y[1] + x[1] y[0] = 1.25

(E3.13.2) z [2] = x [0] y[2] + x[1] y[1] = 0.5 z [3] = x [0] y[3] + x[1] y[2] = 0

(b) Frequency-domain approach with 2-point DFT (Fig. 3.10(b)) We can use the DFT formula (3.4.2) with N = 2 to get the DFTs of the two

sequences as

0.5 for k = 0, 1 Y 2 (k) = 2−1 n=0 y [n]e − j2πkn/2

X 2 (k) = 2−1 n=0 x [n]e − j2πkn/2

= 1 + 0.5(−1) k = 1.5,

−0.5 for k = 0, 1 so that

= 0.5 + (−1) k = 1.5,

Z 2 (k) = X 2 (k) Y 2 (k) = 2.25, −0.25 for k = 0, 1 (E3.13.3) Then we use the IDFT formula (3.4.3) to get

1 2−1 z 2 [n] =

Z 2 (k)e j 2π kn/2

–5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 n z [n ] = x [n ]∗y [n ] 1.25 z ∼ 2 [n ] z ∼ 3 [n ]

(a) Linear convolution (b) Circular convolution with 2-point DFT (c) Circular convolution with 3-point DFT

Fig. 3.10 Linear and circular convolutions with DFT

154 3 Discrete-Time Fourier Analysis This corresponds to one period of the periodic extension of z[n] (obtained in part

(a)) with period N = 2 and is not equal to z[n]. This illustrates that time-aliasing effect might occur if the DFT size N is not sufficiently large.

(c) Frequency-domain approach with 3-point DFT (Fig. 3.10(c)) We can use the DFT formula (3.4.2) with N = 3 to get the DFTs of the two

sequences as

= 1 + 0.5e − j2πk/3 = 1.5,

X 3 (k) =

x [n]e − j2πkn/3

n=0

1 + 0.5e − j2π/3 ,

1 + 0.5e − j4π/3 for k = 0, 1, 2

Y 3 (k) =

− j2πk/3 n=0

y [n]e − j2πkn/3

= 0.5 + e

0.5 + e − j4π/3 for k = 0, 1, 2 so that Z 3 (k) = X 3 (k)Y 3 (k) = 0.5 + 1.25e − j2πk/3 + 0.5e − j4πk/3

0.5 + e − j2π/3 ,

(E3.13.5) We can match this with the IDFT formula (3.4.3) to get z 3 [n] = 0.5, 1.25, 0.5 for n = 0, 1, 2

(E3.13.6) This agrees with the linear convolution z[n] obtained in part (a) for n = 0 ∼ 2.

(d) MATLAB Program We can run the following program “sig03e13.m” to apply the above procedure to get the linear convolution using the DFT. Note the following:

- The built-in MATLAB functions “ fft(x,N)” and “ifft(X,N)” are used to compute the N-point DFT X (k) = DFT N {x[n]} and IDFT x[n] =

IDFT N {X(k)}, respectively. - Depending on whether the length of the sequence given as the first input argument of “ fft(x,N)” or “ifft(X,N)” is less or greater than the sec- ond input argument N, the sequence will be zero-padded or truncated so that its resulting length will be N.

- Note that, to exploit the computational efficiency of FFT (fast Fourier trans- form), the DFT size N should be chosen as a power of two greater than or equal to the length of the sequence.

%sig03e13.m % Use 2-point/3-point DFT for computing a (linear) convolution clear, clf x= [1 0.5]; y= [0.5 1]; z= conv(x,y) % Linear convolution N= 3; % DFT size

3.4 Discrete Fourier Transform (DFT) 155

XN= fft(x,N); YN=fft(y,N); ZN= XN. ∗ YN; zN= ifft(ZN) % Circular convolution expected to agree with the linear one % Sometimes, you had better take the real part of IDFT result % by using real(ifft(ZN)) to make sure of its being real-valued.

(cf.) The above procedure, which is depicted in Fig. 3.9 and illustrated in Example 3.13, paves the way to use the DFT for computing the linear convolution of two finite-duration sequences.

Remark 3.5 How to Choose the DFT Size N in Connection with Zero Padding (1) In computing the DFT of a given sequence x[n] of length M, we are free to

choose the DFT size N , i.e., the number of sampled frequency points over [0, 2π ) (one period of digital frequency) as long as it is greater than or equal to M . Choosing N > M corresponds to increasing the length of x[n] by appending it with additional zero-valued samples - padding with zeros. This procedure called zero padding may be used to fill out the sequence length so that an

N=2 L -point FFT (fast Fourier transform) algorithm could be applied (see Sect. 3.6) or a linear convolution of two sequences could be performed with-

out causing a time-aliasing problem (see Example 3.13). It can also be used to provide a better-looking display of the frequency contents of a finite-duration sequence by decreasing the digital frequency spacing (resolution frequency) 2π/N so that the discrete DFT spectrum X (k) can look close to the continuous DTFT spectrum X (Ω) (see Example 3.14).

(2) As can be seen from the DTFT formula (3.1.1), zero padding does not alter the continuous spectrum X (Ω), but just decreases the interval width between suc- cessive discrete frequencies in the DFT spectrum. However, when the signal is not of finite duration, zero padding can lead to erroneous results. Conclusively, zero padding is justified only when a signal is of finite duration and has already been sampled over the entire range where it is nonzero.