Fourier transform of a sine wave, width of the spectral peak

Hello all! I was wondering, if I’ve got the Fourier transform of a sine wave, how would I calculate the width of that Fourier transform in Julia? Is there a package that does that written in Julia? An example from SciPy is|

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

Assuming that the FFT of the sine wave exhibits spectral leakage as in figure below, a very simple procedure produces the approximate width of the spectral peak (no bells and whistles):

  • Compute the magnitude of the FFT (may taper the original signal and pad it with zeros for better spectral definition)
  • find both the peak frequency and max spectral amplitude with findmax()
  • count the frequency bins above a given threshold from that maximum with count()

The example below looks for amplitudes above -20dB from spectral maximum, which was normalized to 0 dB: