Skip to content

Commit ef682e5

Browse files
committed
Update docstrings for fftfreq and rfftfreq
1 parent 9372553 commit ef682e5

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

src/definitions.jl

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,34 @@ Base.copy(x::Frequencies) = x
419419
fftfreq(n, fs=1)
420420
Return the discrete Fourier transform (DFT) sample frequencies for a DFT of length `n`. The returned
421421
`Frequencies` object is an `AbstractVector` containing the frequency
422-
bin centers at every sample point. `fs` is the sample rate of the
423-
input signal.
422+
bin centers at every sample point. `fs` is the sampling rate of the
423+
input signal, which is the reciprocal of the sample spacing.
424+
425+
Given a window of length `n` and a sampling rate `fs`, the frequencies returned are
426+
427+
```julia
428+
[0, 1, ..., n/2 - 1, -n/2, ..., -1] * fs/n # if n is even
429+
[0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] * fs/n # if n is odd
430+
```
431+
432+
# Examples
433+
434+
```jldoctest; setup=:(using AbstractFFTs)
435+
julia> fftfreq(4, 1)
436+
4-element Frequencies{Float64}:
437+
0.0
438+
0.25
439+
-0.5
440+
-0.25
441+
442+
julia> fftfreq(5, 2)
443+
5-element Frequencies{Float64}:
444+
0.0
445+
0.4
446+
0.8
447+
-0.8
448+
-0.4
449+
```
424450
"""
425451
fftfreq(n::Int, fs::Number=1) = Frequencies((n+1) >> 1, n, fs/n)
426452

@@ -429,7 +455,33 @@ fftfreq(n::Int, fs::Number=1) = Frequencies((n+1) >> 1, n, fs/n)
429455
Return the discrete Fourier transform (DFT) sample frequencies for a real DFT of length `n`.
430456
The returned `Frequencies` object is an `AbstractVector`
431457
containing the frequency bin centers at every sample point. `fs`
432-
is the sample rate of the input signal.
458+
is the sampling rate of the input signal, which is the reciprocal of the sample spacing.
459+
460+
Given a window of length `n` and a sampling rate `fs`, the frequencies returned are
461+
462+
```julia
463+
[0, 1, ..., n/2] * fs/n # if n is even
464+
[0, 1, ..., (n-1)/2] * fs/n # if n is odd
465+
```
466+
467+
!!! note
468+
The Nyquist-frequency component is considered to be positive, unlike [`fftfreq`](@ref).
469+
470+
# Examples
471+
472+
```jldoctest; setup=:(using AbstractFFTs)
473+
julia> rfftfreq(4, 1)
474+
3-element Frequencies{Float64}:
475+
0.0
476+
0.25
477+
0.5
478+
479+
julia> rfftfreq(5, 2)
480+
3-element Frequencies{Float64}:
481+
0.0
482+
0.4
483+
0.8
484+
```
433485
"""
434486
rfftfreq(n::Int, fs::Number=1) = Frequencies((n >> 1)+1, (n >> 1)+1, fs/n)
435487

0 commit comments

Comments
 (0)