Skip to content

hanningfix #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: fix#124
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/bases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ n400(; sfreq = 100) = -hanning(0.4, 0.4, sfreq)
"""
generate a hanning window

duration: in s
offset: in s, defines hanning peak
width: in s
offset: in s, defines hanning peak, must be > round(width/2)
sfreq: sampling rate in Hz
"""
function DSP.hanning(duration, offset, sfreq)
signal = hanning(Int(round(duration * sfreq)))
return pad_array(signal, -Int(round(offset * sfreq / 2)), 0)
function DSP.hanning(width, offset, sfreq)
width = width * sfreq
offset = offset * sfreq
signal = hanning(Int(round(width)))
pad_by = Int(round(offset - length(signal) / 2))

pad_by < 0 ? error("offset has to be > round(width/2)") : ""
return pad_array(signal, -pad_by, 0)
end

## pupil
Expand Down
10 changes: 9 additions & 1 deletion test/bases.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
using UnfoldSim
@testset "hanning" begin
@test UnfoldSim.hanning(0.021, 0.04, 1000)[40] == 1.0
@test UnfoldSim.hanning(0.021, 0.04, 1000)[41] == 1.0 # why 41 not 40? beacuse round(0.5) = 0 and round(1.5) = 2 -- and we are living on the edge!
@test UnfoldSim.hanning(0.011, 0.04, 1000)[40] == 1.0
@test UnfoldSim.hanning(0.011, 0.02, 1000)[20] == 1.0
@test_throws Exception UnfoldSim.hanning(0.011, 0.0, 1000)
end

@testset "p100,N170,p300,n400" begin
sfreq = 1000
@test argmax(p100(; sfreq)) == 0.1 * sfreq
@test argmin(n170(; sfreq)) == 0.17 * sfreq
@test argmax(p300(; sfreq)) == 0.3 * sfreq
@test argmin(n400(; sfreq)) == 0.4 * sfreq
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
end
end

Loading