Compute FFT Peak Frequency

Medium Python DSP Asked at Analog Devices
Solve this problem

Given a sampled signal, find the dominant frequency using an FFT and refine it with parabolic interpolation so the answer is not quantised to the bin spacing.

Constraints

  • Input is a list of floats plus a sample rate in Hz.
  • Use numpy's rfft.
  • Ignore the DC bin.
  • Apply parabolic interpolation across the peak and its two neighbours.
  • Return the frequency in Hz as a float.
  • A signal shorter than 4 samples must raise ValueError.
Starter codePython
1import numpy as np2 3def peak_frequency(samples, sample_rate):4    # TODO5    return 0.0