Lecture 13 Discrete Fourier Transforms (Cont'd)
Total Page:16
File Type:pdf, Size:1020Kb
Lecture 13 Discrete Fourier Transforms (cont’d) The Discrete Cosine Transform (DCT) Here we briefly examine the DCT. It actually exists in several forms, one of which provides the basis of the standard “JPEG” compression method. First recall the standard definition of the DFT which is employed in this course. Let f RN ∈ denote a set of data points f[n],n = 0, 1, , N 1, with the understanding that f is part of an · · · − N-periodic sequence, i.e., f[n + N] = f[n], n Z. Then the Discrete Fourier Transform F = f is ∈ F defined as follows, N 1 − i2πkn F [k]= f[n]exp , k = 0, 1, , N 1. (1) − N · · · − nX=0 The inverse DFT is given by N 1 1 − i2πkn f[n]= F [k]exp , n = 0, 1, , N 1. (2) N N · · · − Xk=0 Recall from our discussion of the Fourier series representations of functions f(x) of a continuous variable π x π, that the series actually defines the 2π-periodic extension of f(x) for all x R. If − ≤ ≤ ∈ f(π) = f(π), then the 2π-periodic extension of f(x) is not continuous at these points. As we saw, such 6 a discontinuity introduces convergence problems at the endpoints, i.e., Gibbs phenomenon. One way to overcome such problems was to consider the signal function f(x) as defined over the half-interval [0,π]. It was also assumed to be an even function, i.e., f( x)= f(x). The resulting 2π-extension of − f(x) is now continuous at π. ± This same complication arises with data sequences. The N-point DFT assumes an N-point periodization of the data set f[n],n = 0, 1, , N 1, as mentioned earlier. This implies that f[0] = · · · − f[N], but it does not imply that f[N 1] is close to f[N], as sketched in the figure below. In such − situations, there will be convergence problems near the endpoints. (And, as we have already seen, these problems manifest themselves over the entire data set, slowing down the overall convergence.) So the idea is to perform an even periodic extension of the N-point data set f[n],n = 0, 1, , N 1. · · · − Before we get to the actual construction of such a data set, let us examine the implications on the form of the discrete transform that will be associated with this set. Since it will be even, we shall not require the sine functions that comprise part of the complex exponential in the DFT. As such, we 142 o o o o o o o o o o o N 2N 1 0 1 2 N 2N 10 1 2 − − − − periodic extension N-point data set periodic extension N-point data set f[n] and the periodic extension f[n + N]= f[n] implicit in the discrete Fourier transform. might expect that the transform will assume the form, N 1 − 2πkn F [k]= f[n] cos , k = 0, 1, , N 1. (3) N · · · − nX=0 This is almost correct – one slight modification must be made. This would be the transform for N points over an interval centered at N = 0. But really want this transform to correspond to a signal of N points only on one side of N = 0. Remember that these N points would then be “flipped” onto the other side to create the even data set. As such – modulo one other technical consideration to be addressed in a moment – the above formula should have N changed to 2N. The resulting transform, N 1 − πkn F [k]= f[n] cos , k = 0, 1, , N 1. (4) N · · · − Xn=0 is known as a discrete cosine transform (DCT). Note the use of the article “a” again! This is actually one of several versions, and is commonly referred to as “DCT-I”, i.e., DCT Version 1. Let’s now address the “technical consideration” referred to above. Consider the “flipping” of the N-point data set f[n],n = 0, 1, , N 1 to produce an even data set, f[n] = f[ n], as sketched in · · · − − the figure below. In this process, we have produced a data set of length 2N 1 and not 2N since the data point − f[0] has not been repeated. Essentially, we have “lost” one data point. This might not seem like a big deal, and it isn’t in some considerations. But studies have shown that this transform is not ideal – that convergence is improved if we preserve the point f[0] to produce a 2N-point data set. The question is, “How do we do it?” The answer is to “flip” the data set f[n],n = 0, 1, , N 1 with · · · − respect to the line n = 1/2, as sketched in the figure below. − 143 o o o o o o o o o o o N + 1N + 2 2 1 0 1 2 N 2 N 1 − − − − − − even extension N-point data set Even extension of N-point data set f[n] obtained by inverting the set about f[0] so that f[ n]= f[n]. This is − the basis of the “DCT-I” method. The resulting 2N-point data set is now even with respect to n = 1/2, and may be periodically − extended. Note that f[0] = f[ 1], f[N 1] = f[N], etc.. In other words, repetition of data values − − has been introduced at points n = pN, p Z: f[pN]= f[pN 1]. ∈ − o o o o o o o o o o o o N N + 1 2 1 0 1 2 N 2 N 1 − − − − − − -1/2 N-point data set N-point data set even extension Even extension of N-point data set f[n] obtained by inverting and copying the entire set f[n], including f[0]. The result is a 2N-point data set. This is the basis of the “DCT-II” method. The remaining question, “What will be the proper form of the associated discrete cosine transform for this data set?” First of all, because we are now working with a 2N-point data set – the set is 2N-periodic and not N-periodic – the N in the argument of the cosine function must be replaced by 2N. Second, because the data set is even with respect to n = 1/2, we must shift the n parameter in − 144 Eq. (4) by one-half to the left, i.e., replace n with n + 1/2. The result, N 1 − π 1 F [k]= f[n] cos n + k , k = 0, 1, , N 1. (5) N 2 · · · − nX=0 will define what we shall call Version 1.1 of the discrete cosine transform, or “DCT-I.I”. Before discussing this version of the DCT in more mathematical detail, we mention that a com- parison of the two figures above indicates why the DCT-I.I method may perform better in signal processing that DCT-I. The copying of the f[0] data value in DCT-I.I produces a kind of “flattening” of the resulting signal at n = 1 and n = 0, as opposed to a potential cusp produced by DCT-I. − And now for the mathematical details. First of all, we claim that the set of N-vectors uk, k = 0, 1, 2, , N 1, with components defined as follows, · · · − π 1 u [n] = cos n + k , n = 0, 1, , N 1, (6) k N 2 · · · − form an orthogonal set in RN . The first basis vector, k = 0, is an easy one: u [n] = cos(0) = 1, implying that u = (1, 1, , 1). (7) 0 0 · · · It follows immediately that N 1 − u , u = 1= N. (8) h 0 0i nX=0 For k = 0, we have 6 N 1 − π 1 u , u = cos2 n + k h k ki N 2 nX=0 N 1 − 1 1 (2n + 1)π = + cos k 2 2 N nX=0 N = . (9) 2 The fact that the sum of the discrete cosine functions is zero may be verified by expressing the cosine in terms of complex exponentials. The sums over both exponentials are finite geometric series which vanish, in the same way that they did for the discrete Fourier transform. Finally, for k = l, we simply state that 6 N 1 − π 1 π 1 u , u = cos n + k cos n + l h k li N 2 N 2 nX=0 145 N 1 N 1 1 − π 1 1 − π 1 = cos n + (k + l) + cos n + (k l) 2 N 2 2 N 2 − nX=0 nX=0 = 0. (10) Once again, the fact that each of the sums is zero may be shown by expressing the cosine functions in terms of complex exponentials. From the above results, it follows that the family of N-vectors, ek, defined below, forms an orthonormal basis on RN : 2 π 1 e [n]= λ cos n + k , n = 0, 1, , N = 1, (11) k krN N 2 · · · where 1 , k = 0 √2 λk = (12) 1, k = 0. 6 The special normalization required for the cos(0) function reminds us of the situation with Fourier cosine series. In the figure below are presented plots of the N = 8-point orthonormal functions ek[n], k = 0, 1, , 7. These functions are rather special since they form the basis of the JPEG compression · · · standard. Given any f RN , its expansion in the orthonormal basis e will be given by ∈ k N 1 − f = ckek, (13) nX=0 where the Fourier coefficients ck are given by N 1 − 2 π 1 c = f, e = f[n]λ cos n + k .