4
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.
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.
2Mind including an explanation on what DCT is? – numbermaniac – 2017-05-13T00:32:40.677
The Wikipedia page shows several different versions. Can you please clarify? Voting to close for now.
– Nick Clifford – 2017-05-13T01:04:10.347@Nick Clifford lets assume DCT-II from that wikipedia page, as it clearly says: The DCT-II is probably the most commonly used form, and is often simply referred to as "the DCT" – None – 2017-05-13T01:35:12.363
@FryAmTheEggman lets use definition for DCT-II – None – 2017-05-13T01:35:33.170
@numbermaniac it is DCT-II – None – 2017-05-13T01:41:34.307
10Please add some test cases. – Shaggy – 2017-05-13T02:33:33.850
@Shaggy Producing test cases requires working code, which i, unfortunately, dont have by hand right now. – None – 2017-05-13T06:10:16.183
@xakepp35 Why not put it into a CAS system like https://www.symbolab.com/ and get test cases from that?
– numbermaniac – 2017-05-16T08:11:31.263@numbermaniac too hard to be a challenge. better close it. – None – 2017-05-18T00:56:24.960
very low people even knows what is it, consider it is kind of alchemistry) its almost impossible to compute DCT, as is impossible to get Au from Hg ;-) – None – 2017-05-18T00:57:27.990
please, post test cases as you get ones, from working algorithm, i have none by hand and is too silly for using so hard maths. and we could discuss these cases, if that will be actually required ;-) – None – 2017-05-18T01:00:07.867
3@xakepp35 how do we know if our program is correct, if we don't have at least two test cases to test it against? Specifically,
as long as you produce the same results
as what? – Stephen – 2017-05-18T01:13:09.997