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

**URL:** <https://discourse.julialang.org/t/fourier-transform-of-a-sine-wave-width-of-the-spectral-peak/56342>\
**Category:** General Usage\
**Tags:** question, dsp\
**Created:** [March 2, 2021, 3:32pm UTC](https://discourse.julialang.org/t/fourier-transform-of-a-sine-wave-width-of-the-spectral-peak/56342 "2021-03-02T15:32:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [March 2, 2021, 3:32pm UTC](https://discourse.julialang.org/t/fourier-transform-of-a-sine-wave-width-of-the-spectral-peak/56342/1 "2021-03-02T15:32:14Z")

</div>

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  
[https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.peak\_widths.html|https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.peak\_widths.html](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.peak_widths.html%7Chttps://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.peak_widths.html)

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:)](https://julialang.slack.com/archives/C6A044SQH/p1614699118210500?thread_ts=1614699118.210500&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [March 2, 2021, 11:00pm UTC](https://discourse.julialang.org/t/fourier-transform-of-a-sine-wave-width-of-the-spectral-peak/56342/2 "2021-03-02T23:00:04Z")

</div>

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:

 ![Spectral_leakage_width](https://global.discourse-cdn.com/julialang/original/3X/6/5/658687b745af6764374d6a7bbf97299e64a9d822.png)
