# What is the fftfreq sampling frequency?

**URL:** <https://discourse.julialang.org/t/what-is-the-fftfreq-sampling-frequency/34406>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 10, 2020, 11:11am UTC](https://discourse.julialang.org/t/what-is-the-fftfreq-sampling-frequency/34406 "2020-02-10T11:11:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)\
**Post date:** [February 10, 2020, 11:11am UTC](https://discourse.julialang.org/t/what-is-the-fftfreq-sampling-frequency/34406/1 "2020-02-10T11:11:31Z")

</div>

From my understanding, the sampling frequency is the inverse distance between data points.  
Is this correct, or do I have to use something else?

Maybe an example can make my question a bit clearer.  
If I want to plot the fft spectrum what option would be correct?  
`sample_rate_1`, `sample_rate_2`,or something else?

```julia
using FFTW, Plots

periodic(x,wavelengths) = sum(map((wl)->exp(im*2*π/wl*x),wavelengths))

n_samples = 50
x = range(1,50,length=n_samples)
range_x = maximum(x)-minimum(x)
wavelengths = rand(3:10,2)
y = periodic.(x,Ref(wavelengths))
Y = fftshift(fft(y))
sample_rate_1 = (n_samples-1)/range_x
sample_rate_2 = (n_samples)/range_x
freq_1 = fftshift(fftfreq(length(Y),sample_rate_1))
freq_2 = fftshift(fftfreq(length(Y),sample_rate_2))
p1 = begin
            scatter(freq_1,abs.(Y),markersize=2,markershape=:x,title="frequency domain",label="option 1")
            scatter!(freq_2,abs.(Y),markersize=2,markershape=:+,label="option 2")
            vline!(1 ./wavelengths,legend=:left,label="peaks")
            limit = 1/minimum(abs.(wavelengths))*1.5
            xlims!(0,limit)
    end

plot(plot(x,y,title="space domain",legend=false),p1,layout=(:,1))

```

![index](https://global.discourse-cdn.com/julialang/original/3X/7/d/7d6e30e901bd4aa140d77ad73310881ec7c69af5.png)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 10, 2020, 1:35pm UTC](https://discourse.julialang.org/t/what-is-the-fftfreq-sampling-frequency/34406/2 "2020-02-10T13:35:08Z")

</div>

> [@feanor12](#):
>
> the sampling frequency is the inverse distance between data points.

Yes.
