All problems
Spectral Density Value
Problem
Evaluate the truncated spectral density at frequency f from an autocorrelation list acf = [rho(0), ..., rho(K)]: S(f) = rho(0) + 2 * sum over k = 1..K of rho(k) * cos(2 * pi * f * k).
Return the value as a number.
Hint
The density at frequency 0 is the sum of all autocorrelations with weight 2 on positive lags.
Test cases
case 1
in: [[1,0.5],0]
expected: 2
case 2
in: [[1,0.5],0.5]
expected: 0
case 3
in: [[1,0.25,0.1],0.25]
expected: 0.8
case 4
in: [[1],0.3]
expected: 1
Starter codePython
import math
def spectral_density(acf, f):
# Your code here
pass4 test cases · run your code against them in the editor