Implement the Discrete Cosine Transform (DCT). This may implemented as either a function or a program and the sequence can be given as either an argument or using standard input. Your program must be able to handle sequences of any length (assuming a hypothetical version of your language which has no limits on things like memory and integer size).
There is a previous challenge for the DFT, now let’s compute the DCT! Use the DCT‑II definition from Wikipedia:
$$ X_{k} = \sum_{n \, = \, 0}^{N - 1} x_{n} \, \cos \left[ \frac{\pi}{N} \, \left( n + \frac{1}{2} \right) \, k \right] \quad\quad k = 0, \, \ldots, N - 1 $$
Your program takes a sequence xn as input, and must produce the corresponding sequence Xk. In this formula, the cosine is in radians.
Rules
- This is code-golf so the shortest solution wins.
- Builtins that compute the DCT in forward or backward (also known as inverse) directions are not allowed.
- Floating‐point inaccuracies will not be counted against you.
- You don’t have to use the exact algorithm shown here, as long as you produce the same results.
as long as you produce the same resultsas what? \$\endgroup\$