All problems
Dominant Frequency
Problem
Find the dominant frequency of a series by scanning the periodogram bins k = 0, ..., n//2 and returning the normalized frequency k/n at the bin with the largest power. Ties keep the smallest k.
Return 0.0 for a series with fewer than two points.
Hint
A value of 0.5 corresponds to the Nyquist frequency.
Test cases
case 1
in: [[0,1,0,1]]
expected: 0
case 2
in: [[5,5,5,5]]
expected: 0
case 3
in: [[1,2,3,4]]
expected: 0
case 4
in: [[1,-1,1,-1]]
expected: 0.5
case 5
in: [[1,0,-1,0]]
expected: 0.25
Starter codePython
import math
def dominant_frequency(series):
# Your code here
pass5 test cases · run your code against them in the editor