Encyclopedia > Discrete cosine transform

  Article Content

Discrete cosine transform

The discrete cosine transform (DCT) is a frequency transform similar to the discrete Fourier transform (DFT), but using only real numbers. It is equivalent to a DFT of roughly twice the length, operating on real data with even symmetry (since the Fourier transform of a real and even function is real and even), where in some variants the input and/or output data are shifted by half a sample. (See below for its properties and applications.)

A related transform is the discrete sine transform (DST), which is equivalent to a DFT of real and odd functions.

Table of contents

Definition

Formally, the discrete cosine transform is a linear, invertible function F : Rn -> Rn (where R denotes the set of real numbers). There are several variants of the DCT with slightly modified definitions. The n real numbers x0, ..., xn-1 are transformed into the n real numbers f0, ..., fn-1 according to one of the formulas:

DCT-I

<math>f_j = \frac{1}{2} (x_0 + (-1)^j x_{n-1})
     + \sum_{k=1}^{n-2} x_k \cos \left[\frac{\pi}{n-1} j k \right]</math>

A DCT-I of n=5 real numbers abcde is exactly equivalent to a DFT of eight real numbers abcdedcb (even symmetry). (In contrast, DCT types II-IV involve a half-sample shift in the equivalent DFT.) Note, however, that the DCT-I is not defined for n less than 2. (All other DCT types are defined for any positive n.)

Thus, the DCT-I corresponds to the boundary conditions: xk is even around k=0 and even around k=n-1; similarly for fj.

DCT-II

<math>f_j =
   \sum_{k=0}^{n-1} x_k \cos \left[\frac{\pi}{n} j (k+1/2) \right]</math>

The DCT-II is probably the most commonly used form, and is often simply referred to as "the DCT".

Some authors further multiply the f0 term by 1/√2 (see below for the corresponding change in DCT-III); this does not affect the basic properties, but breaks the direct correspondence with a real-even DFT of half-shifted input.

The DCT-II implies the boundary conditions: xk is even around k=-1/2 and even around k=n-1/2; fj is even around j=0 and odd around j=n.

DCT-III

<math>f_j = \frac{1}{2} x_0 +
   \sum_{k=1}^{n-1} x_k \cos \left[\frac{\pi}{n} (j+1/2) k \right]</math>

Because it is the inverse of DCT-II (up to a scale factor, see below), this form is sometimes simply referred to as "the inverse DCT" ("IDCT").

Some authors further multiply the x0 term by √2 (see above for the corresponding change in DCT-II); this does not affect the basic properties, but breaks the direct correspondence with a real-even DFT of half-shifted output.

The DCT-III implies the boundary conditions: xk is even around k=0 and odd around k=n; fj is even around j=-1/2 and odd around j=n-1/2.

DCT-IV

<math>f_j =
   \sum_{k=0}^{n-1} x_k \cos \left[\frac{\pi}{n} (j+1/2) (k+1/2) \right]</math>

A variant of the DCT-IV, where data from different transforms are overlapped, is called the modified discrete cosine transform (MDCT).

The DCT-IV implies the boundary conditions: xk is even around k=-1/2 and odd around k=n-1/2; similarly for fj.

DCT V-VIII

In principle, there are actually four additional types of discrete cosine transform (Martucci, 1994), corresponding to real-even DFTs of logically odd order, which have factors of n+1/2 in the denominators of the cosine arguments. However, these variants seem to be rarely used in practice.

(The trivial real-even array, a length-one DFT (odd length) of a single number a, corresponds to a DCT-V of length n=1.)

Inverse Transforms

The inverse of DCT-I is DCT-I multiplied by 2/(n-1). The inverse of DCT-IV is DCT-IV multiplied by 2/n. The inverse of DCT-II is DCT-III multiplied by 2/n (and vice versa).

Like for the DFT, the normalization factor in front of these transform definitions is merely a convention and differs between treatments. For example, some authors multiply the transforms by <math>\sqrt{2/n}</math> so that the inverse does not require any additional multiplicative factor.

Computation

Although the direct application of these formulas would require O(n2) operations, as in the fast Fourier transform (FFT) it is possible to compute the same thing with only O(n log n) complexity by factorizing the computation. (One can also compute DCTs via FFTs combined with O(n) pre- and post-processing steps.)

Applications

The DCT, and in particular the DCT-II, is often used in signal and image processing, especially for lossy data compression, because it has a strong "energy compaction" property: most of the signal information tends to be concentrated in a few low-frequency components of the DCT, approaching the optimal Karhunen-Loeve transform[?] for signals based on certain limits of Markov processes.

For example, the DCT is used in JPEG image compression, MJPEG video compression, and MPEG video compression. There, the two-dimensional DCT-II of 8x8 blocks is computed and the results are filtered to discard small (difficult-to-see) components. That is, n is 8 and the DCT-II formula is applied to each row and column of the block. The result is an array in which the top left corner is the DC (zero-frequency) component and lower and rightmore entries represent larger vertical and horizontal spatial frequencies. For the chrominance components, n is 16 but the frequency components beyond the first 8 are discarded.

A related transform, the modified discrete cosine transform (MDCT), is used in AAC, Vorbis, and MP3 audio compression.

DCTs are also widely employed in solving partial differential equations by spectral methods, where the different variants of the DCT correspond to slightly different even/odd boundary conditions at the two ends of the array.


References:
  • K. R. Rao and P. Yip, Discrete Cosine Transform: Algorithms, Advantages, Applications (Academic Press, Boston, 1990).
  • A. V. Oppenheim, R. W. Schafer, and J. R. Buck, Discrete-Time Signal Processing, second edition (Prentice-Hall, New Jersey, 1999).
  • S. A. Martucci, "Symmetric convolution and the discrete sine and cosine transforms," IEEE Trans. Sig. Processing SP-42, 1038-1051 (1994).
  • Matteo Frigo and Steven G. Johnson: FFTW, http://www.fftw.org/. A free (GPL) C library that can compute fast DCTs (types I-IV) in one or more dimensions, of arbitrary size.



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
List of biology topics

... - hybridization[?] -nucleosome - histone - promoter - enhancer - mutation computational biology - bioinformatics genomics proteomics Techniques: gel electrophoresis ...