All problems
Formant Estimate (Lite)
Problem
Estimate formants by picking local maxima of the magnitude spectrum. Index i is a peak when spectrum[i] is greater than its left neighbor and at least its right neighbor.
Take the n highest peaks, breaking ties by frequency, and return their frequencies sorted ascending. Return an empty list when n is not positive or no peak exists.
Hint
Endpoints are never local maxima because they lack two neighbors.
Test cases
case 1
in: [[1,3,2,5,4],[100,200,300,400,500],2]
expected: [200,400]
case 2
in: [[1,2,3],[10,20,30],1]
expected: []
case 3
in: [[5,4,3,2],[10,20,30,40],2]
expected: []
case 4
in: [[1,5,1,5,1],[10,20,30,40,50],2]
expected: [20,40]
case 5
in: [[1,5,1],[10,20,30],0]
expected: []
Starter codePython
def formant_estimate_lite(spectrum, freqs, n):
# Your code here
pass5 test cases · run your code against them in the editor