Skip to content
DeepForgeby svx
All problems
EasyCalculusca-153

Hann Window Value

Problem

The Hann window of length size is w[n] = 0.5 - 0.5 * cos(2*pi*n / (size - 1)) for n = 0, ..., size - 1.

Given the index n and the window length size > 1, return w[n]. The window tapers to zero at both endpoints.

Hint

The window is symmetric and reaches its maximum at the center index.

Test cases

case 1
in: [0,5]
expected: 0
case 2
in: [4,5]
expected: 0
case 3
in: [2,5]
expected: 1
case 4
in: [1,5]
expected: 0.49999999999999994
Starter codePython
def hann_window(n, size):
    # Your code here
    pass

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