Last post I have written about DCT and iDCT transform of a 2D image which is also a 2D matrix. There is a A matrix which is used to calculate DCT transform Y of original matrix X. The A is provided by the book directly, but how A is calculated out? Today I will talk about the original of matrix A. This is the first part of the topic which will focus on 1D vector transform.

Consider the point signal s(n) as an N - dimensional vector, for example:

The inverse transform says that S can be represented as the sum of N basis vectors

where Uk corresponds to the k - th transform kernel:

The forward transform says that the expansion coefficient t can be determined by the inner product S of with U:

The U is the basis vectors named patterns of DCT transform, which can be considered “real” version of DFT. The U is calculated by following formula and the theory behind the formula is very complex which is out of the topic today.

I write some Python code to provide the process of DCT itself.

First, we provide the basis prefix of A:

[code lang=“python”] # init basis prefix A = np.zeros(N) A[0] = np.sqrt(1/N) for k in range(1, N): A[k] = np.sqrt(2/N)