Skip to content

Commit

Permalink
Fix a bunch of deprecations on Julia 0.7 (#177)
Browse files Browse the repository at this point in the history
* `Range` -> `AbstractRange` (requires Compat 0.32 on Julia 0.6)
* use `where` syntax for parametric functions
* `2.^` -> `2 .^`
* `+` -> `.+` (where necessary)
  • Loading branch information
martinholters authored and ararslan committed Sep 27, 2017
1 parent f2c056d commit 3b44986
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
julia 0.6-rc1
Compat 0.32
Polynomials 0.1.0
Reexport
SpecialFunctions
Expand Down
2 changes: 1 addition & 1 deletion src/Filters/filt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ filt(h::AbstractArray, x::AbstractArray) =
# fftfilt and filt
#

const FFT_LENGTHS = 2.^(1:28)
const FFT_LENGTHS = 2 .^ (1:28)
# FFT times computed on a Core i7-3930K @4.4GHz
# The real time doesn't matter, just the relative difference
const FFT_TIMES = [6.36383e-7, 6.3779e-7 , 6.52212e-7, 6.65282e-7, 7.12794e-7, 7.63172e-7,
Expand Down
4 changes: 2 additions & 2 deletions src/lpc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function implements the mathematics published in [1].
(DAFX 2003 article, Lagrange et al)
http://www.sylvain-marchand.info/Publications/dafx03.pdf
"""
function lpc{T <: Number}(x::AbstractVector{T}, p::Int, ::LPCBurg)
function lpc(x::AbstractVector{T}, p::Int, ::LPCBurg) where T <: Number
ef = x # forward error
eb = x # backwards error
a = [1; zeros(T, p)] # prediction coefficients
Expand Down Expand Up @@ -62,7 +62,7 @@ function implements the mathematics described in [1].
[1] - The Wiener (RMS) Error Criterion in Filter Design and Prediction
(Studies in Applied Mathematics 1947 article, N. Levison)
"""
function lpc{T <: Number}(x::AbstractVector{T}, p::Int, ::LPCLevinson)
function lpc(x::AbstractVector{<:Number}, p::Int, ::LPCLevinson)
R_xx = xcorr(x,x)[length(x):end]
a = zeros(p,p)
prediction_err = zeros(1,p)
Expand Down
17 changes: 9 additions & 8 deletions src/periodograms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Periodograms
using ..DSP: @importffts
using ..Util, ..Windows
using Compat: AbstractRange
export arraysplit, nextfastfft, periodogram, welch_pgram, mt_pgram,
spectrogram, power, freq, stft
@importffts
Expand Down Expand Up @@ -178,11 +179,11 @@ end

## PERIODOGRAMS
abstract type TFR{T} end
struct Periodogram{T,F<:Union{Frequencies,Range}} <: TFR{T}
struct Periodogram{T,F<:Union{Frequencies,AbstractRange}} <: TFR{T}
power::Vector{T}
freq::F
end
struct Periodogram2{T,F1<:Union{Frequencies,Range},F2<:Union{Frequencies,Range}} <: TFR{T}
struct Periodogram2{T,F1<:Union{Frequencies,AbstractRange},F2<:Union{Frequencies,AbstractRange}} <: TFR{T}
power::Matrix{T}
freq1::F1
freq2::F2
Expand All @@ -192,13 +193,13 @@ freq(p::TFR) = p.freq
freq(p::Periodogram2) = (p.freq1, p.freq2)
fftshift(p::Periodogram{T,F}) where {T,F<:Frequencies} =
Periodogram(p.freq.nreal == p.freq.n ? p.power : fftshift(p.power), fftshift(p.freq))
fftshift(p::Periodogram{T,F}) where {T,F<:Range} = p
fftshift(p::Periodogram{T,F}) where {T,F<:AbstractRange} = p
# 2-d
fftshift(p::Periodogram2{T,F1,F2}) where {T,F1<:Frequencies,F2<:Frequencies} =
Periodogram2(p.freq1.nreal == p.freq1.n ? fftshift(p.power,2) : fftshift(p.power), fftshift(p.freq1), fftshift(p.freq2))
fftshift(p::Periodogram2{T,F1,F2}) where {T,F1<:Range,F2<:Frequencies} =
fftshift(p::Periodogram2{T,F1,F2}) where {T,F1<:AbstractRange,F2<:Frequencies} =
Periodogram2(fftshift(p.power,2), p.freq1, fftshift(p.freq2))
fftshift(p::Periodogram2{T,F1,F2}) where {T,F1<:Range,F2<:Range} = p
fftshift(p::Periodogram2{T,F1,F2}) where {T,F1<:AbstractRange,F2<:AbstractRange} = p

# Compute the periodogram of a signal S, defined as 1/N*X[s(n)]^2, where X is the
# DTFT of the signal S.
Expand Down Expand Up @@ -340,14 +341,14 @@ end
const FloatRange{T} = StepRangeLen{T,Base.TwicePrecision{T},Base.TwicePrecision{T}}
end

struct Spectrogram{T,F<:Union{Frequencies,Range}} <: TFR{T}
struct Spectrogram{T,F<:Union{Frequencies,AbstractRange}} <: TFR{T}
power::Matrix{T}
freq::F
time::FloatRange{Float64}
end
fftshift(p::Spectrogram{T,F}) where {T,F<:Frequencies} =
Spectrogram(p.freq.nreal == p.freq.n ? p.power : fftshift(p.power, 1), fftshift(p.freq), p.time)
fftshift(p::Spectrogram{T,F}) where {T,F<:Range} = p
fftshift(p::Spectrogram{T,F}) where {T,F<:AbstractRange} = p
Base.time(p::Spectrogram) = p.time

function spectrogram(s::AbstractVector{T}, n::Int=length(s)>>3, noverlap::Int=n>>1;
Expand All @@ -357,7 +358,7 @@ function spectrogram(s::AbstractVector{T}, n::Int=length(s)>>3, noverlap::Int=n>

out = stft(s, n, noverlap, PSDOnly(); onesided=onesided, nfft=nfft, fs=fs, window=window)
Spectrogram(out, onesided ? rfftfreq(nfft, fs) : fftfreq(nfft, fs),
((0:size(out,2)-1)*(n-noverlap)+n/2)/fs)
(n/2 : n-noverlap : (size(out,2)-1)*(n-noverlap)+n/2) / fs)

end

Expand Down
2 changes: 1 addition & 1 deletion test/FilterTestHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ end

# Show the poles and zeros in each biquad
# This is not currently used for testing, but is useful for debugging
function sosfilter_poles_zeros{T}(sos::SecondOrderSections{T})
function sosfilter_poles_zeros(sos::SecondOrderSections)
z = fill(complex(nan(T)), 2, length(sos.biquads))
p = fill(complex(nan(T)), 2, length(sos.biquads))
for (i, biquad) in enumerate(sos.biquads)
Expand Down
2 changes: 1 addition & 1 deletion test/filt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ f = DSP.digitalfilter(DSP.Bandpass(0.1, 0.3), DSP.Butterworth(2))
# fftfilt/filt
#

for xlen in 2.^(7:18).-1, blen in 2.^(1:6).-1
for xlen in 2 .^ (7:18) .- 1, blen in 2 .^ (1:6) .- 1
b = randn(blen)
for x in (rand(xlen), rand(xlen, 2))
filtres = filt(b, [1.0], x)
Expand Down

0 comments on commit 3b44986

Please sign in to comment.