Matrix.DCT Method

function DCT(const Vec: TMtxVec; VecIndex: Integer; Index: Integer; Len: Integer): TMtxVec;

The forward discrete cosine transform (DCT).

#NameTypeDescription
1VecTMtxVec
2VecIndexInteger
3IndexIntegerstart index
4LenIntegerelement count

Result: stored in self (calling object), returns self for chaining

Remarks:

Calculates the forward discrete cosine transform (DCT) of the Vec and writes the result in the calling Matrix. If Vec.Length is a power of 2, the function uses an efficient algorithm that is significantly faster than the direct computation of DCT. For other values of Vec Length, this function uses the direct formulas given below; however, the symmetry of cosine function is taken into account, which allows to perform about half of the multiplication operations in the formulas. In the following definition of DCT, N=Vec.Length and V is the calling Matrix:

C(k)={1Nk=02Nk>0V[k]=C(k)n=0N1Vec[n]cos((2n+1)kπ2N)\begin{aligned} C(k) &= \begin{cases} \sqrt{\frac{1}{N}} & k=0 \\ \sqrt{\frac{2}{N}} & k > 0 \end{cases} \\ \text{V}[k] &= C(k)\cdot \sum _{n=0} ^{N-1} \text{Vec}[n]\cdot \cos \left( \frac{(2n+1)k\pi}{2N}\right) \end{aligned}
Examples
var a,b: Matrix;
begin
    a.SetIt(1,4,False,[1,-2,3,4]);
    b.DCT(a,0,0,4);
end;
See Also: Matrix.IDCT, Matrix.FFT