Skip to content

Commit

Permalink
Test special cases of sum-of-cosines windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jagot committed Mar 9, 2024
1 parent 626a4ac commit c8cc612
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -604,16 +604,16 @@ function cosine_sum_window(name, a, pretty_name)
W(x) = $($eq).
```
"""
struct $(name) <: AbstractWindow end
struct $(name) <: ElectricFields.AbstractWindow end

Base.show(io::IO, ::$(name)) = write(io, $(pretty_name))

function window_value(::$(name), x)
function ElectricFields.window_value(::$(name), x)
abs(2x) > 1 && return zero(x)
$(fex)
end

function window_derivative(::$(name), x)
function ElectricFields.window_derivative(::$(name), x)
abs(2x) > 1 && return zero(x)
$(dex)
end
Expand Down
10 changes: 8 additions & 2 deletions test/apodized_fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@
mid_sel2 = findall((7.5 .. 14.0), t)
post_sel = findall(>(14.0), t)

ElectricFields.@cosine_sum_window Zero () "Zero"
ElectricFields.@cosine_sum_window One (1.0,) "One"

@testset "Window: $(window)" for window in (ElectricFields.Hann(), ElectricFields.Hamming(),
ElectricFields.Blackman(),
ElectricFields.BlackmanExact(),
ElectricFields.Nuttall(),
ElectricFields.BlackmanNuttall(),
ElectricFields.BlackmanHarris(),
ElectricFields.Kaiser(3), ElectricFields.Kaiser(2),
ElectricFields.Rect())
ElectricFields.Rect(), Zero(), One())
w = ElectricFields.window_value.(window, x)
∂w = ElectricFields.window_derivative.(window, x)

@test all(iszero, w[pre_sel])
@test all(iszero, ∂w[pre_sel])

if window isa ElectricFields.Rect
if window isa Union{ElectricFields.Rect,One}
@test all(isone, w[mid_sel])
@test all(iszero, ∂w[mid_sel])
elseif window isa Zero
@test all(iszero, w[mid_sel])
@test all(iszero, ∂w[mid_sel])
else
@test all(<(1), w[mid_sel])
# This is of course not a proper test of the accuracy of
Expand Down

0 comments on commit c8cc612

Please sign in to comment.