All problems
8-Point DCT
Problem
Compute the orthonormal 8-point DCT-II of a row of length 8:
X_k = c_k * sum_{i=0}^{7} x_i * cos(pi * (2i + 1) * k / 16)
with c_0 = sqrt(1/8) and c_k = sqrt(2/8) for k > 0. Return the list of 8 coefficients.
Hint
The DC coefficient is the average value scaled by sqrt(8).
Test cases
case 1
in: [[1,1,1,1,1,1,1,1]]
expected: [2.8284271247461903,3.3306690738754696e-16,-2.220446049250313e-16,3.3306690738754696e-16,5.551115123125783e-17,-2.220446049250313e-16,-2.1649348980190553e-15,3.…
case 2
in: [[1,0,0,0,0,0,0,0]]
expected: [0.3535533905932738,0.4903926402016152,0.46193976625564337,0.4157348061512726,0.3535533905932738,0.27778511650980114,0.19134171618254492,0.09754516100806417]
case 3
in: [[1,2,3,4,5,6,7,8]]
expected: [12.727922061357857,-6.4423230227051365,-1.3322676295501878e-15,-0.6734548009039383,-4.440892098500626e-16,-0.20090290373599817,-1.5765166949677223e-14,-0.05070…
case 4
in: [[1,-1,1,-1,1,-1,1,-1]]
expected: [0,0.5097955791041591,4.440892098500626e-16,0.6013448869350442,2.220446049250313e-16,0.899976223136416,9.43689570931383e-16,2.562915447741505]
Starter codePython
import math
def dct8(row):
# Your code here
pass4 test cases · run your code against them in the editor