Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
- foreach
- move test_quinn
- eps -> atol
  • Loading branch information
wheeheee committed Dec 13, 2024
1 parent 6b26a6c commit d920d2f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
3 changes: 1 addition & 2 deletions test/FilterTestHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ function tffilter_accuracy(f1, f2, accurate_f)
accuracy_check(loss(a1, accurate_a), loss(a2, accurate_a), "a")
end

function zpkfilter_accuracy(f1, f2, accurate_f; relerr=1, compare_gain_at=nothing, eps=0.0)
function zpkfilter_accuracy(f1, f2, accurate_f; relerr=1, compare_gain_at=nothing, atol=0.0)
z1, p1 = sort(f1.z; lt), sort(f1.p; lt)
z2, p2 = sort(f2.z; lt), sort(f2.p; lt)
accurate_z, accurate_p = sort(accurate_f.z; lt), sort(accurate_f.p; lt)
atol = eps
if !isempty(z1) || !isempty(z2) || !isempty(accurate_z)
@test (z1, accurate_z; atol)
@test (z2, accurate_z; atol)
Expand Down
11 changes: 6 additions & 5 deletions test/estimation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,23 @@ end
end

@testset "quinn" begin
### real input
fs = 100
t = range(0, 5; step=1/fs)
fr = 28.3
sr = cospi.(2 * fr * t .+ 1 / 4.2)
function test_quinn(f, s, args...)
(f_est_real, maxiter) = quinn(s, args...)
@test maxiter == false
@test isapprox(f_est_real, f; atol=1e-3)
return nothing
end
### real input
fs = 100
t = range(0, 5; step=1/fs)
fr = 28.3
sr = cospi.(2 * fr * t .+ 1 / 4.2)
test_quinn(fr, sr, 50, fs)
# use default initial guess
test_quinn(fr, sr, fs) # initial guess given by Jacobsen
# use default fs
test_quinn(fr / fs, sr) # fs = 1.0, initial guess given by Jacobsen

### complex input
fc = -40.3
sc = cispi.(2 * fc * t .+ 1 / 1.4)
Expand Down
2 changes: 1 addition & 1 deletion test/filt_stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function test_arbitrary(Th, x, resampleRate, numFilters::Integer)

results = (naiveResult, statelessResult, statefulResult, piecewiseResult)
commonLen = minimum(length, results)
resize!.(results, commonLen)
foreach(x -> resize!(x, commonLen), results)

@test naiveResult statelessResult
@test naiveResult statefulResult
Expand Down
4 changes: 2 additions & 2 deletions test/filter_design.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ end

f = Elliptic(20, 0.1, 10)
zpkfilter_eq(f, matlab_f)
zpkfilter_accuracy(f, matlab_f, Elliptic(BigFloat, 20, 0.1, 10), eps=1e-9)
zpkfilter_accuracy(f, matlab_f, Elliptic(BigFloat, 20, 0.1, 10), atol=1e-9)

# 19 pole elliptic filter prototype with 0.1 dB passband ripple and 10
# dB stopband ripple from MATLAB 2013b:
Expand Down Expand Up @@ -309,7 +309,7 @@ end

f = Elliptic(19, 0.1, 10)
zpkfilter_eq(f, matlab_f)
zpkfilter_accuracy(f, matlab_f, Elliptic(BigFloat, 19, 0.1, 10), eps=4e-9)
zpkfilter_accuracy(f, matlab_f, Elliptic(BigFloat, 19, 0.1, 10), atol=4e-9)
end

#
Expand Down

0 comments on commit d920d2f

Please sign in to comment.