Inverse discrete cosine transform
x = idct(y)
x = idct(y,n)
x = idct(y,n,dim)
y = idct(___,'Type',dcttype)
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.
rng('default') 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.
subplot(2,1,1) plot(t,x) yl = ylim; title('Original') subplot(2,1,2) plot(t,z) ylim(yl) title('Reconstructed')
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); max(abs(dct1-idt1))
ans = 1.3323e-15
dct4 = dct(s,'Type',4); idt4 = idct(s,'Type',4); max(abs(dct4-idt4))
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); max(abs(dct2-idt2))
ans = 4.4409e-16
dct3 = dct(s,'Type',3); idt3 = idct(s,'Type',2); max(abs(dct3-idt3))
ans = 1.1102e-15
y— Input discrete cosine transform
Input discrete cosine transform, specified as a real-valued or complex-valued vector, matrix,
N-D array, or
the discrete cosine transform of a sinusoid.
the discrete cosine transform of a two-channel sinusoid.
Complex Number Support: Yes
n— Inverse transform length
Inverse transform length, specified as a positive integer scalar.
dim— Dimension to operate along
Dimension to operate along, specified as a positive integer scalar.
dcttype— Inverse discrete cosine transform type
Inverse discrete cosine transform type, specified as a positive integer scalar from 1 to 4.
x— Inverse discrete cosine transform
Inverse discrete cosine transform, returned as a real-valued
or complex-valued vector, matrix, N-D array, or
The inverse discrete cosine transform reconstructs
a sequence from its discrete cosine transform (DCT) coefficients.
idct function is the inverse of the
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. In particular, DCT-1 and DCT-4 are their own inverses, and DCT-2 and DCT-3 are inverses of each other.
 Jain, A. K. Fundamentals of Digital Image Processing. Englewood Cliffs, NJ: Prentice-Hall, 1989.
 Pennebaker, W. B., and J. L. Mitchell. JPEG Still Image Data Compression Standard. New York: Van Nostrand Reinhold, 1993.
 Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. 2nd Ed. Upper Saddle River, NJ: Prentice Hall, 1999.
Usage notes and limitations:
C and C++ code generation for
dct requires DSP System
The length of the transform dimension must be a power of two. If specified, the pad or truncation value must be constant. Expressions or variables are allowed if their values do not change.
Inputs must be double precision.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).