@@ -400,15 +400,20 @@ end
400
400
401
401
402
402
struct Frequencies{T<: Number } <: AbstractVector{T}
403
- nreal :: Int
403
+ n_nonnegative :: Int
404
404
n:: Int
405
405
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
406
411
end
407
412
408
413
unsafe_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 )
412
417
unsafe_getindex (x, i)
413
418
end
414
419
@@ -420,23 +425,23 @@ Base.step(x::Frequencies) = x.multiplier
420
425
421
426
"""
422
427
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
425
430
bin centers at every sample point. `fs` is the sample rate of the
426
431
input signal.
427
432
"""
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)
429
434
430
435
"""
431
436
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`
434
439
containing the frequency bin centers at every sample point. `fs`
435
440
is the sample rate of the input signal.
436
441
"""
437
442
rfftfreq (n:: Int , fs:: Number = 1 ) = Frequencies ((n >> 1 )+ 1 , (n >> 1 )+ 1 , fs/ n)
438
443
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
440
445
441
446
442
447
# #############################################################################
0 commit comments