Vector.DCT Method

Overload List

#SignatureDescription
1function DCT: TVec;The forward discrete cosine transform (DCT).
2function DCT(const Vec: TVec): TVec;Calculates the forward discrete cosine transform (DCT) of the Vec.
3function DCT(const Vec: TMtxVec; VecIndex: Integer; Index: Integer; Len: Integer): TMtxVec;The forward discrete cosine transform (DCT).

Overload 1: function DCT: TVec;

The forward discrete cosine transform (DCT).

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

Remarks:

Calculates the forward discrete cosine transform (DCT) of all calling vector elements in-place. If vector Vector.Length is a power of 2, the function uses an efficient algorithm that is significantly faster than the direct computation of DCT. For different lengths 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 vector:

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: Vector;
begin
    a.SetIt(False,[1,-2,3,4]);
    b.DCT(a);
end;
See Also: Vector.IDCT, Vector.FFT

Overload 2: function DCT(const Vec: TVec): TVec;

Calculates the forward discrete cosine transform (DCT) of the Vec.

#NameTypeDescription
1VecTVec

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

Remarks:

Writes the result in the calling vector. 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.

Overload 3: 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 vector. 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 vector:

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: Vector;
begin
    a.SetIt(False,[1,-2,3,4]);
    b.DCT(a);
end;
See Also: Vector.IDCT, Vector.FFT