Skip to content

Commit

Permalink
Merge a2e7c4e into 68ce876
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Oct 8, 2020
2 parents 68ce876 + a2e7c4e commit 5415b3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/definitions.jl
Expand Up @@ -421,6 +421,10 @@ Broadcast.broadcasted(::typeof(*), x::Number, f::Frequencies) = Broadcast.broadc
Broadcast.broadcasted(::typeof(/), f::Frequencies, x::Number) = Frequencies(f.n_nonnegative, f.n, f.multiplier / x)
Broadcast.broadcasted(::typeof(\), x::Number, f::Frequencies) = Broadcast.broadcasted(/, f, x)

Base.maximum(f::Frequencies) = ifelse(f.multiplier >= 0, (f.n_nonnegative - 1) * f.multiplier, (f.n_nonnegative - f.n) * f.multiplier)
Base.minimum(f::Frequencies) = ifelse(f.multiplier >= 0, (f.n_nonnegative - f.n) * f.multiplier, (f.n_nonnegative - 1) * f.multiplier)
Base.extrema(f::Frequencies) = (minimum(f), maximum(f))

"""
fftfreq(n, fs=1)
Return the discrete Fourier transform (DFT) sample frequencies for a DFT of length `n`. The returned
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Expand Up @@ -114,6 +114,18 @@ end
@test 2 \ fftfreq(4, 1) === fftfreq(4, 1/2)
@test 2 .\ fftfreq(4, 1) === fftfreq(4, 1/2)
end

@testset "extrema" begin
function check_extrema(freqs)
for f in [minimum, maximum, extrema]
@test f(freqs) == f(collect(freqs)) == f(fftshift(freqs))
end
end
for f in (fftfreq, rfftfreq), n in (8, 9), multiplier in (2, 1/3, -1/7)
freqs = f(n, multiplier)
check_extrema(freqs)
end
end
end

@testset "normalization" begin
Expand Down

0 comments on commit 5415b3d

Please sign in to comment.