Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-217

Haar Wavelet Step

Problem

Apply one level of the orthonormal Haar wavelet transform to a vector of even length:

coarse[i] = (x[2i] + x[2i+1]) / sqrt(2), detail[i] = (x[2i] - x[2i+1]) / sqrt(2)

Return the coarse coefficients followed by the detail coefficients.

Hint

The transform is orthogonal, so energy is preserved between the coarse and detail parts.

Test cases

case 1
in: [[1,1,1,1]]
expected: [1.4142135623730951,1.4142135623730951,0,0]
case 2
in: [[1,0]]
expected: [0.7071067811865476,0.7071067811865476]
case 3
in: [[1,2,3,4]]
expected: [2.1213203435596424,4.949747468305833,-0.7071067811865476,-0.7071067811865476]
case 4
in: [[0,0,0,0]]
expected: [0,0,0,0]
Starter codePython
def haar_step(x):
    # Your code here
    pass

4 test cases · run your code against them in the editor