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 was a previous challenge for DFT, now lets compute DCT! ;-)
Use the DCT-II definition from Wikipedia:
Your program takes a sequence xn as input, and must produce the corresponding sequence Xk. In this formula, the cosine is in radians.
- 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.