5.2 Discrete Cosine Transform

dct(X[, type=2])

Replaces the columns of a dense real matrix with their discrete cosine transforms. The second argument, an integer between 1 and 4, denotes the type of transform (DCT-I, DCT-II, DCT-III, DCT-IV). The DCT-I transform requires that the row dimension of X is at least 2. These transforms are defined as follows (for a matrix with n rows).

                                 k            n∑- 2
 DCT -I:   X [k,:] :=  X [0,:]+ (- 1)X [n - 1,:]+ 2    X[j,:]cos(πjk∕(n - 1)),   k = 0,...,n - 1.
                                               j=1
                       n∑-1
DCT -II:   X [k,:] :=  2   X [j,:]cos(π(j + 1∕2)k∕n),  k = 0,...,n - 1.
                       j=0
                               n∑-1
DCT -III:   X [k,:] :=  X [0,:]+ 2    X [j,:]cos(πj(k + 1∕2)∕n),    k = 0,...,n - 1.
                               j=1
                       n∑-1
DCT -IV:    X [k,:] :=  2   X [j,:]cos(π(j + 1∕2)(k + 1∕2)∕n),   k = 0,...,n- 1.
                       j=0

idct(X[, type=2])

Replaces the columns of a dense real matrix with the inverses of the discrete cosine transforms defined above.

The module also includes a discrete N-dimensional cosine transform. The input matrix is interpreted as an N-dimensional matrix stored in column-major order. The discrete N-dimensional cosine transform computes the corresponding one-dimensional transform along each dimension. For example, the two-dimensional transform applies a one-dimensional transform to all the rows of the matrix, followed by a one-dimensional transform to all the columns of the matrix.

dctn(X[, dims=X.size[, type=2]])

Replaces a dense real matrix with its N-dimensional discrete cosine transform. The dimensions of the N-dimensional matrix are given by the N-tuple dim. The two-dimensional transform is computed as dctn(X, X.size).

idctn(X[, dims=X.size[, type=2]])

Replaces a dense real N-dimensional matrix with its inverse N-dimensional discrete cosine transform. The dimensions of the matrix are given by the tuple dim. The two-dimensional inverse transform is computed as idctn(X, X.size).