Skip to content

Commit ce1e15c

Browse files
authored
Accommodate AbstractFFTs PR 26 (#322)
Bound FFTW to 1.1 to avoid conflicting export of Frequencies et al., set verion to 0.6.1.
1 parent 1ca3c74 commit ce1e15c

File tree

7 files changed

+15
-75
lines changed

7 files changed

+15
-75
lines changed

Project.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DSP"
22
uuid = "717857b8-e6f2-59f4-9121-6e50c889abd2"
3-
version = "0.6.0"
3+
version = "0.6.1"
44

55
[deps]
66
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
@@ -12,7 +12,11 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1212
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1313

1414
[compat]
15-
Polynomials = ">= 0.1.0"
15+
FFTW = "1.1"
16+
OffsetArrays = "0.11"
17+
Polynomials = "0.6"
18+
Reexport = "0.2"
19+
SpecialFunctions = "0.8"
1620
julia = "1"
1721

1822
[extras]

docs/src/util.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ end
99
unwrap
1010
unwrap!
1111
hilbert
12-
fftfreq
13-
rfftfreq
1412
nextfastfft
1513
pow2db
1614
amp2db

src/deprecated.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ Base.@deprecate_binding TFFilter PolynomialRatio
44
Base.@deprecate_binding BiquadFilter Biquad
55
Base.@deprecate_binding SOSFilter SecondOrderSections
66

7+
Base.@deprecate Frequencies(nreal::Int, n::Int, multiplier::Float64) FFTW.Frequencies(nreal, n, multiplier)
8+
Base.@deprecate fftfreq(n::Int, fs::Real=1) FFTW.fftfreq(n, fs)
9+
Base.@deprecate rfftfreq(n::Int, fs::Real=1) FFTW.rfftfreq(n, fs)
10+
711
@deprecate conv2 conv

src/periodograms.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using ..Util, ..Windows
66
export arraysplit, nextfastfft, periodogram, welch_pgram, mt_pgram,
77
spectrogram, power, freq, stft
88
using FFTW
9+
import FFTW: Frequencies, fftfreq, rfftfreq
910

1011
## ARRAY SPLITTER
1112

@@ -218,11 +219,11 @@ See also: [`fftfreq`](@ref), [`rfftfreq`](@ref)
218219
freq(p::TFR) = p.freq
219220
freq(p::Periodogram2) = (p.freq1, p.freq2)
220221
FFTW.fftshift(p::Periodogram{T,F}) where {T,F<:Frequencies} =
221-
Periodogram(p.freq.nreal == p.freq.n ? p.power : fftshift(p.power), fftshift(p.freq))
222+
Periodogram(p.freq.n_nonnegative == p.freq.n ? p.power : fftshift(p.power), fftshift(p.freq))
222223
FFTW.fftshift(p::Periodogram{T,F}) where {T,F<:AbstractRange} = p
223224
# 2-d
224225
FFTW.fftshift(p::Periodogram2{T,F1,F2}) where {T,F1<:Frequencies,F2<:Frequencies} =
225-
Periodogram2(p.freq1.nreal == p.freq1.n ? fftshift(p.power,2) : fftshift(p.power), fftshift(p.freq1), fftshift(p.freq2))
226+
Periodogram2(p.freq1.n_nonnegative == p.freq1.n ? fftshift(p.power,2) : fftshift(p.power), fftshift(p.freq1), fftshift(p.freq2))
226227
FFTW.fftshift(p::Periodogram2{T,F1,F2}) where {T,F1<:AbstractRange,F2<:Frequencies} =
227228
Periodogram2(fftshift(p.power,2), p.freq1, fftshift(p.freq2))
228229
FFTW.fftshift(p::Periodogram2{T,F1,F2}) where {T,F1<:AbstractRange,F2<:AbstractRange} = p
@@ -442,7 +443,7 @@ struct Spectrogram{T,F<:Union{Frequencies,AbstractRange}} <: TFR{T}
442443
time::FloatRange{Float64}
443444
end
444445
FFTW.fftshift(p::Spectrogram{T,F}) where {T,F<:Frequencies} =
445-
Spectrogram(p.freq.nreal == p.freq.n ? p.power : fftshift(p.power, 1), fftshift(p.freq), p.time)
446+
Spectrogram(p.freq.n_nonnegative == p.freq.n ? p.power : fftshift(p.power, 1), fftshift(p.freq), p.time)
446447
FFTW.fftshift(p::Spectrogram{T,F}) where {T,F<:AbstractRange} = p
447448

448449
"""

src/util.jl

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -108,53 +108,6 @@ fftabs2type(::Type{Complex{T}}) where {T<:FFTW.fftwReal} = T
108108
fftabs2type(::Type{T}) where {T<:FFTW.fftwReal} = T
109109
fftabs2type(::Type{T}) where {T<:Union{Real,Complex}} = Float64
110110

111-
## FREQUENCY VECTOR
112-
113-
struct Frequencies <: AbstractVector{Float64}
114-
nreal::Int
115-
n::Int
116-
multiplier::Float64
117-
end
118-
119-
unsafe_getindex(x::Frequencies, i::Int) =
120-
(i-1+ifelse(i <= x.nreal, 0, -x.n))*x.multiplier
121-
function Base.getindex(x::Frequencies, i::Int)
122-
(i >= 1 && i <= x.n) || throw(BoundsError())
123-
unsafe_getindex(x, i)
124-
end
125-
if isdefined(Base, :iterate)
126-
function Base.iterate(x::Frequencies, i::Int=1)
127-
i > x.n ? nothing : (unsafe_getindex(x,i), i + 1)
128-
end
129-
else
130-
Base.start(x::Frequencies) = 1
131-
Base.next(x::Frequencies, i::Int) = (unsafe_getindex(x, i), i+1)
132-
Base.done(x::Frequencies, i::Int) = i > x.n
133-
end
134-
Base.size(x::Frequencies) = (x.n,)
135-
Base.step(x::Frequencies) = x.multiplier
136-
137-
"""
138-
fftfreq(n, fs=1)
139-
140-
Return discrete fourier transform sample frequencies. The returned
141-
Frequencies object is an AbstractVector containing the frequency
142-
bin centers at every sample point. `fs` is the sample rate of the
143-
input signal.
144-
"""
145-
fftfreq(n::Int, fs::Real=1) = Frequencies(((n-1) >> 1)+1, n, fs/n)
146-
147-
"""
148-
rfftfreq(n, fs=1)
149-
150-
Return discrete fourier transform sample frequencies for use with
151-
`rfft`. The returned Frequencies object is an AbstractVector
152-
containing the frequency bin centers at every sample point. `fs`
153-
is the sample rate of the input signal.
154-
"""
155-
rfftfreq(n::Int, fs::Real=1) = Frequencies((n >> 1)+1, (n >> 1)+1, fs/n)
156-
FFTW.fftshift(x::Frequencies) = (x.nreal-x.n:x.nreal-1)*x.multiplier
157-
158111
# Get next fast FFT size for a given signal length
159112
const FAST_FFT_SIZES = [2, 3, 5, 7]
160113
"""

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using DSP, FFTW, Test
2+
import DSP: Frequencies, fftfreq, rfftfreq
23

34
using Random: seed!
45

test/util.jl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,6 @@ using Statistics: mean
5050
end
5151

5252
@testset "fft helpers" begin
53-
## FFTFREQ
54-
@test fftfreq(1) [0.]
55-
@test fftfreq(2) [0., -1/2]
56-
@test fftfreq(2, 1/2) [0., -1/4]
57-
@test fftfreq(3) [0., 1/3, -1/3]
58-
@test fftfreq(3, 1/2) [0., 1/6, -1/6]
59-
@test fftfreq(6) [0., 1/6, 1/3, -1/2, -1/3, -1/6]
60-
@test fftfreq(7) [0., 1/7, 2/7, 3/7, -3/7, -2/7, -1/7]
61-
62-
@test rfftfreq(1) [0.]
63-
@test rfftfreq(2) [0., 1/2]
64-
@test rfftfreq(2, 1/2) [0., 1/4]
65-
@test rfftfreq(3) [0., 1/3]
66-
@test rfftfreq(3, 1/2) [0., 1/6]
67-
@test rfftfreq(6) [0., 1/6, 1/3, 1/2]
68-
@test rfftfreq(7) [0., 1/7, 2/7, 3/7]
69-
70-
for n = 1:7
71-
@test fftshift(fftfreq(n)) fftshift([fftfreq(n);])
72-
end
73-
7453
@test meanfreq(sin.(2*π*10*(0:1e-3:10*π)),1e3) 10.0 rtol=1e-3
7554

7655
# nextfastfft

0 commit comments

Comments
 (0)