You are here : matlab → Signal Processing → dct
# dct() - Signal Processing

### Syntax

### Example

### Output / Return Value

### Limitations

### Alternatives / See Also

### Reference

y = dct(x) returns the unitary discrete cosine transform of x,y(k)=w(k)∑n=1Nx(n)cos(π2N(2n−1)(k−1)), k=1,2,…,N,wherew(k)={1N,k=1,2N,2≤k≤N,N is the length of x, and x and y are the same size. If x is a matrix, dct transforms its columns. The series is 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.y = dct(x,n) pads or truncates x to length n before transforming.The DCT is closely related to the discrete Fourier transform. You can often reconstruct a sequence very accurately from only a few DCT coefficients, a useful property for applications requiring data reduction.

y = dct(x)y = dct(x,n)

Energy Stored in DCT CoefficientsOpen This Example Find how many DCT coefficients represent 99% of the energy in a sequence. x = (1:100) + 50*cos((1:100)*2*pi/40); X = dct(x); [XX,ind] = sort(abs(X),'descend'); i = 1; while norm(X(ind(1:i)))/norm(X)<0.99 i = i + 1; end Needed = i; Reconstruct the signal and compare to the original.X(ind(Needed+1:end)) = 0; xx = idct(X); plot([x;xx]') legend('Original',['Reconstructed, N = ' int2str(Needed)], ... 'Location','SouthEast') Related ExamplesDCT for Speech Signal Compression