All problems
Periodogram Bin
Problem
Compute the periodogram at a single frequency bin k: I(k) = (1/n) * abs(sum over t of x[t] * exp(-2*pi*i*k*t/n))^2.
Return 0.0 if k is outside the range 0 to n-1.
Hint
For a constant series all nonzero bins are (numerically) zero.
Test cases
case 1
in: [[1,0,0,0],0]
expected: 0.25
case 2
in: [[1,1,1,1],1]
expected: 7.498798913309287e-33
case 3
in: [[1,2,3,4],1]
expected: 2
case 4
in: [[1,2,3],0]
expected: 12
Starter codePython
import math
def periodogram_bin(series, k):
# Your code here
pass4 test cases · run your code against them in the editor