Engee documentation

dct

Discrete cosine transform.

Library

EngeeDSP

Syntax

Function call

  • y = dct(x) — returns the unitary discrete cosine transform of the input array x. Size of the output array y matches the size of x. If x it has several dimensions, the function dct performs an operation on the first dimension of an array, the size of which is larger 1.

  • y = dct(x,n) — adds zeros or truncates the corresponding dimension x up to length n before the conversion.

Arguments

Input arguments

# x — input array

+ vector | the matrix | An N-dimensional array

Details

An input array specified as a vector, matrix, or multidimensional array with real or complex values.

Типы данных

Float32, Float64

Support for complex numbers

Yes

# n is the length of the conversion

+ a positive integer scalar

Details

The length of the transformation, specified as a positive integer scalar.

Типы данных

Float32, Float64

Output arguments

# y is a discrete cosine transform

+ vector | the matrix | An N-dimensional array

Details

A discrete cosine transform returned as a real or complex vector, matrix, or multidimensional array.

Examples

Energy stored in PREP coefficients

Details

Let’s determine how many DCT coefficients represent 99% of the energy in the sequence.

import EngeeDSP.Functions: dct, norm

x = (1:100) .+ 50 .* cos.((1:100) .* 2π / 40) .^ 3
X = dct(x)
XX = sort(abs.(X), rev = true)
ind = sortperm(abs.(X), rev = true)

i = 1
while (norm(X[ind[1:i]]) / norm(X))^2 < 0.99
   global i += 1
end
needed = i

Let’s restore the signal and compare it with the original one.

import EngeeDSP.Functions: idct

X[ind[needed+1:end]] .= 0
xx = idct(X)

plot(1:100, x, label = "Original", legend = :bottomright)
plot!(1:100, xx, label = "Reconstructed, N = $needed")

dct 1

Additional Info

Discrete cosine transform

Details

The discrete cosine transform (DCT) is closely related to the discrete Fourier transform. Often, the sequence can be very accurately reconstructed using only a few PREP coefficients. This property is useful for applications that require data processing.

PREP has four standard options. Only the DKP-2 type is implemented for this function. For the signal lengths and the Kronecker symbol transformations are defined as follows:

  • PREP-1:

  • PREP-2:

  • PREP-3:

  • PREP-4:

The rows are indexed from and instead of the usual ones and since the Engee vectors vary from before , not from before .

All PREP variants are unitar (or, equivalently, _orthogonal): to find their inverse values, swap them and in every definition. DKP-1 and DKP-4 are the opposite of each other. DKP-2 and DKP-3 are the opposite of each other.

Literature

  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.