dct
-
constexpr std::vector<Complex> dct(const std::vector<Complex> &X, int type = 2) noexcept
Calculates the discrete cosine transform [1] of a complex sequence.
Parameters
Returns
The discrete cosine transform performs the following operation:
\[\DeclareMathOperator\H{H}
X_k = \sum_{n = 0}^{N - 1}x_n \cos[\frac{\pi}{N}(n + \frac{1}{2})k] \quad k = 0, \ldots, n-1,\]
The formula slightly modified depending on the type. DCT type 4 was implemented using the algorithm described here [2].
Example
std::vector<Complex> X = {1 + 2_j, 2 + 3_j, 3, 4, 5};
std::vector<Complex> Y = dct(X, 2); // it's 2 by default.
for(int i = 0; i < Y.size(); i++){
std::cout << Y[i] << "\n";
}
Output:
30 + 10j
-9.95959 + 7.33094j
2.61516e-15 + 1.38197j
-0.898056 - 3.3552j
-2.94604e-15 - 3.61803j
References