Matrix.DCT Method

TMtxVec DCT(TMtxVec Vec, Int32 VecIndex, Int32 Index, Int32 Len)

The forward discrete cosine transform (DCT).

#NameTypeDescription
1VecTMtxVecsource TVec or TMtx
2VecIndexInt32
3IndexInt32start index
4LenInt32element 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
Matrix a;
Matrix b;
a.SetIt(1,4,false,new double[] {1,-2,3,4});
b.DCT(a,0,0,4);
See Also: Matrix.IDCT, Matrix.FFT