@@ -400,15 +400,20 @@ end
400400
401401
402402struct Frequencies{T<: Number } <: AbstractVector{T}
403- nreal :: Int
403+ n_nonnegative :: Int
404404 n:: Int
405405 multiplier:: T
406+
407+ Frequencies (n_nonnegative:: Int , n:: Int , multiplier:: T ) where {T<: Number } = begin
408+ 1 ≤ n_nonnegative ≤ n || error (" Condition 1 ≤ n_nonnegative ≤ n isn't satisfied." )
409+ return new {T} (n_nonnegative, n, multiplier)
410+ end
406411end
407412
408413unsafe_getindex (x:: Frequencies , i:: Int ) =
409- (i- 1 + ifelse (i <= x. nreal , 0 , - x. n))* x. multiplier
410- function Base. getindex (x:: Frequencies , i:: Int )
411- (i >= 1 && i <= x . n) || throw ( BoundsError () )
414+ (i- 1 + ifelse (i <= x. n_nonnegative , 0 , - x. n))* x. multiplier
415+ @inline function Base. getindex (x:: Frequencies , i:: Int )
416+ @boundscheck Base . checkbounds (x, i )
412417 unsafe_getindex (x, i)
413418end
414419
@@ -420,23 +425,23 @@ Base.step(x::Frequencies) = x.multiplier
420425
421426"""
422427 fftfreq(n, fs=1)
423- Return discrete fourier transform sample frequencies. The returned
424- Frequencies object is an AbstractVector containing the frequency
428+ Return the discrete Fourier transform (DFT) sample frequencies for a DFT of length `n` . The returned
429+ ` Frequencies` object is an ` AbstractVector` containing the frequency
425430bin centers at every sample point. `fs` is the sample rate of the
426431input signal.
427432"""
428- fftfreq (n:: Int , fs:: Number = 1 ) = Frequencies (((n - 1 ) >> 1 ) + 1 , n, fs/ n)
433+ fftfreq (n:: Int , fs:: Number = 1 ) = Frequencies ((n + 1 ) >> 1 , n, fs/ n)
429434
430435"""
431436 rfftfreq(n, fs=1)
432- Return discrete fourier transform sample frequencies for use with
433- `rfft`. The returned Frequencies object is an AbstractVector
437+ Return the discrete Fourier transform (DFT) sample frequencies for a real DFT of length `n`.
438+ The returned ` Frequencies` object is an ` AbstractVector`
434439containing the frequency bin centers at every sample point. `fs`
435440is the sample rate of the input signal.
436441"""
437442rfftfreq (n:: Int , fs:: Number = 1 ) = Frequencies ((n >> 1 )+ 1 , (n >> 1 )+ 1 , fs/ n)
438443
439- fftshift (x:: Frequencies ) = (x. nreal - x. n: x. nreal - 1 )* x. multiplier
444+ fftshift (x:: Frequencies ) = (x. n_nonnegative - x. n: x. n_nonnegative - 1 )* x. multiplier
440445
441446
442447# #############################################################################
0 commit comments