Skip to content

Commit

Permalink
Fixed factor in derivative of Kaiser windows; test using AD
Browse files Browse the repository at this point in the history
  • Loading branch information
jagot committed Apr 5, 2024
1 parent 9168f6f commit 707cbf9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ function window_derivative(w::Kaiser, x)
abs(2x) > 1 && return zero(x)
a = π*w.α
f = (1 - (2x)^2)
pf = 2a*x/(besseli(0,a)*f)
pf = 4a*x/(besseli(0,a)*f)
-pf*besseli(1, a*f)
end

Expand Down
8 changes: 6 additions & 2 deletions test/apodized_fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
ElectricFields.BlackmanHarris(),
ElectricFields.Kaiser(3), ElectricFields.Kaiser(2),
ElectricFields.Rect(), Zero(), One())
w = ElectricFields.window_value.(window, x)
wx = Base.Fix1(ElectricFields.window_value, window)
w = wx.(x)
∂w = ElectricFields.window_derivative.(window, x)

@test all(iszero, w[pre_sel])
Expand All @@ -103,6 +104,9 @@
# the derivative, just that the behaviour is reasonable.
@test all((0), ∂w[mid_sel1])
@test all((0), ∂w[mid_sel2])
# Here we however compare the analytic derivatives with
# AD.
test_approx_eq(ForwardDiff.derivative.(wx, x[2:end-1]), ∂w[2:end-1])
end

@test all(iszero, w[post_sel])
Expand Down Expand Up @@ -135,7 +139,7 @@
# For the same reason, the intensity is not exactly the original
# intensity (flat for this particular field) times the window
# value squared, hence the high tolerance.
@test abs2.(w[mid_sel]) Iwv[mid_sel] rtol=5e-2
test_approx_eq(abs2.(w[mid_sel]), Iwv[mid_sel], rtol=0.2)
@test all(iszero, Fwv[post_sel])

@test all(iszero, Awv[pre_sel])
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using UnitfulAtomic
using LinearAlgebra
using IntervalSets
using FFTW
using ForwardDiff
using PrettyTables

function test_approx_eq(a, b; on_fail::Union{Nothing,Function}=nothing, isbroken=false, kwargs...)
Expand Down

0 comments on commit 707cbf9

Please sign in to comment.