Main Content


Inverse discrete cosine transform



x = idct(y) returns the inverse discrete cosine transform of input array y. The output x has the same size as y. If y has more than one dimension, then idct operates along the first array dimension with size greater than 1.

x = idct(y,n) zero-pads or truncates the relevant dimension of y to length n before transforming.

x = idct(y,n,dim) computes the transform along dimension dim. To input a dimension and use the default value of n, specify the second argument as empty, [].


y = idct(___,'Type',dcttype) specifies the type of inverse discrete cosine transform to compute. See Inverse Discrete Cosine Transform for details. This option can be combined with any of the previous syntaxes.


collapse all

Generate a signal that consists of a 25 Hz sinusoid sampled at 1000 Hz for 1 second. The sinusoid is embedded in white Gaussian noise with variance 0.01.


Fs = 1000;
t = 0:1/Fs:1-1/Fs;
x = sin(2*pi*25*t) + randn(size(t))/10;

Compute the discrete cosine transform of the sequence. Determine how many of the 1000 DCT coefficients are significant. Choose 1 as the threshold for significance.

y = dct(x);

sigcoeff = abs(y) >= 1;

howmany = sum(sigcoeff)
howmany = 17

Reconstruct the signal using only the significant components.

y(~sigcoeff) = 0;

z = idct(y);

Plot the original and reconstructed signals.

yl = ylim;


Verify that the different variants of the discrete cosine transform are orthogonal, using a random signal as a benchmark.

Start by generating the signal.

s = randn(1000,1);

Verify that DCT-1 and DCT-4 are their own inverses.

dct1 = dct(s,'Type',1);
idt1 = idct(s,'Type',1);

ans = 1.3323e-15
dct4 = dct(s,'Type',4);
idt4 = idct(s,'Type',4);

ans = 1.3323e-15

Verify that DCT-2 and DCT-3 are inverses of each other.

dct2 = dct(s,'Type',2);
idt2 = idct(s,'Type',3);

ans = 4.4409e-16
dct3 = dct(s,'Type',3);
idt3 = idct(s,'Type',2);

ans = 1.1102e-15

Input Arguments

collapse all

Input discrete cosine transform, specified as a real-valued or complex-valued vector, matrix, or N-D array.

Example: dct(sin(2*pi*(0:255)/4)) specifies the discrete cosine transform of a sinusoid.

Example: dct(sin(2*pi*[0.1;0.3]*(0:39))') specifies the discrete cosine transform of a two-channel sinusoid.

Data Types: single | double
Complex Number Support: Yes

Inverse transform length, specified as a positive integer scalar.

Data Types: single | double

Dimension to operate along, specified as a positive integer scalar.

Data Types: single | double

Inverse discrete cosine transform type, specified as a positive integer scalar from 1 to 4.

Data Types: single | double

Output Arguments

collapse all

Inverse discrete cosine transform, returned as a real-valued or complex-valued vector, matrix, or N-D array.

More About

collapse all

Inverse Discrete Cosine Transform

The inverse discrete cosine transform reconstructs a sequence from its discrete cosine transform (DCT) coefficients. The idct function is the inverse of the dct function.

The DCT has four standard variants. For a transformed signal y of length N, and with δkℓ the Kronecker delta, the inverses are defined by:

  • Inverse of DCT-1:


  • Inverse of DCT-2:


  • Inverse of DCT-3:


  • Inverse of DCT-4:


The series are indexed from n = 1 and k = 1 instead of the usual n = 0 and k = 0, because MATLAB® vectors run from 1 to N instead of from 0 to N – 1.

All variants of the DCT are unitary (or, equivalently, orthogonal): To find the forward transforms, switch k and n in each definition. DCT-1 and DCT-4 are their own inverses. DCT-2 and DCT-3 are inverses of each other.


[1] Jain, A. K. Fundamentals of Digital Image Processing. Englewood Cliffs, NJ: Prentice-Hall, 1989.

[2] Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. 2nd Ed. Upper Saddle River, NJ: Prentice Hall, 1999.

[3] Pennebaker, W. B., and J. L. Mitchell. JPEG Still Image Data Compression Standard. New York: Van Nostrand Reinhold, 1993.

Extended Capabilities

Version History

Introduced before R2006a

See Also

| (Image Processing Toolbox) | (Image Processing Toolbox) |