Discrete Cosine Transform Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

What this Discrete Cosine Transform (DCT-II) calculator does

This calculator takes a finite sequence of real numbers and computes its type-II discrete cosine transform (DCT-II). The output is a list of coefficients that show how much each cosine "frequency" contributes to your original data. This is the same core operation used in JPEG image compression and many audio codecs.

You can use the tool to:

Formula for the DCT-II

For a sequence of length N, written as

x[0], x[1], ..., x[N − 1],

the DCT-II produces coefficients X[0], X[1], ..., X[N − 1] defined by

X[k] = α[k] n=0 N-1 x[n] cos π (2n+1)k 2N

with normalization factors

This is a common "orthonormal" convention: with these factors, the transform is energy-preserving, and you can recover the original sequence using the corresponding inverse DCT (type III) with the same scaling.

What each coefficient means

In the calculator output, the value at row k is exactly X[k] from the formula above.

Interpreting the DCT-II output from this calculator

After you enter a comma-separated sequence and run the calculation, you will see one coefficient per line or table row. Use the output as follows:

If you are comparing results to a textbook or another software package, check the normalization. Some references use α[0] = 1/2 or α[k] = 1 without orthonormal scaling. In that case, coefficients will differ by simple constant factors, but their relative shapes will match.

Worked example (matching the calculator)

Consider the sequence

1, 2, 0, -1

Here, N = 4. Using the orthonormal DCT-II formula above, the calculator computes approximately:

How to read these values:

If you type 1, 2, 0, -1 into the calculator, your DCT-II coefficients should match these values up to rounding. Small differences (for example, in the fourth or fifth decimal place) are normal due to floating-point arithmetic.

How the DCT-II relates to other transforms

The DCT-II is closely related to the discrete Fourier transform (DFT) and to other cosine and sine transforms. The table below summarizes some key differences that matter in practice.

Transform Input type Output type Symmetry / basis Typical uses
DCT-II (this calculator) Real, finite sequence Real coefficients Even-symmetric cosine basis Image and video compression (JPEG), audio coding, feature extraction
DFT Real or complex sequence Complex coefficients Complex exponentials (sines and cosines) General spectral analysis, filter design, convolution via FFT
DCT-I Real, finite sequence Real coefficients Even symmetry including endpoints Some PDE solvers, specific boundary conditions
DCT-III Real, finite sequence Real coefficients Cosine basis dual to DCT-II Inverse transform for DCT-II (reconstruction)
Discrete Sine Transform (DST) Real, finite sequence Real coefficients Odd-symmetric sine basis PDEs with different boundary conditions, some signal models

Because the DCT-II uses only cosines and assumes even symmetry, it often provides better energy compaction for real-world signals than the DFT applied directly to the same-length real data.

Applications of the DCT-II

Image and video compression

In JPEG and many video codecs, images are split into small blocks (for example, 8 × 8 pixels). Each block is transformed with a 2D DCT (built from 1D DCTs along rows and columns). Most of the block's visual information concentrates in a few low-frequency coefficients, which can be stored with higher precision, while many high-frequency coefficients are heavily quantized or set to zero.

Audio and speech processing

Audio codecs and analysis tools apply the DCT or related transforms to short overlapping frames of audio samples. The resulting coefficients can be shaped according to perceptual models of human hearing. Variants of the DCT are also used to compute Mel-frequency cepstral coefficients (MFCCs), a standard feature set in speech recognition.

Numerical methods and pattern recognition

Because the DCT-II diagonalizes certain differential operators under even boundary conditions, it appears in spectral methods for solving partial differential equations. In pattern recognition and computer vision, truncated DCT coefficient vectors act as compact descriptors of shape or texture.

How to use this calculator effectively

  1. Prepare your data: Arrange your 1D sequence as real numbers. You can include integers or decimals (e.g., 0.5, -3.2).
  2. Enter the sequence: Type values separated by commas, for example 0, 1, 0, -1. Spaces are allowed and will be ignored.
  3. Run the calculation: Submit the form to compute the DCT-II. The tool validates the input and reports an error if any entry is not a number.
  4. Study the coefficients: Focus first on the lowest indices (k = 0, 1, 2, 3). These usually carry most of the structure.
  5. Experiment: Try adding noise, changing one sample, or lengthening the sequence to see how the spectrum changes.

Assumptions and limitations

Next steps and related tools

If you are exploring signal processing more broadly, it is useful to compare the DCT-II with the discrete Fourier transform on the same data. Many workflows use both: the DCT for real-valued compression tasks and the DFT for general spectral analysis and filter design.

Enter a sequence to begin.

Embed this calculator

Copy and paste the HTML below to add the Discrete Cosine Transform Calculator - Explore Frequency Components to your website.