From 33bc2b666e13dc01ed5cc7a89643f69b73cb428a Mon Sep 17 00:00:00 2001 From: "behinger (s-ccs 001)" Date: Fri, 13 Dec 2024 17:05:40 +0100 Subject: [PATCH 1/2] hanning upgrade --- src/bases.jl | 15 ++++++++++----- test/bases.jl | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/bases.jl b/src/bases.jl index 2dbeffc9..fa8770b5 100644 --- a/src/bases.jl +++ b/src/bases.jl @@ -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 diff --git a/test/bases.jl b/test/bases.jl index 1ac947a2..ea153c1a 100644 --- a/test/bases.jl +++ b/test/bases.jl @@ -1,6 +1,6 @@ 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) From 5d383114e59fa747ebb5d6ca6f6c0fc0958a8507 Mon Sep 17 00:00:00 2001 From: "behinger (s-ccs 001)" Date: Fri, 13 Dec 2024 17:08:37 +0100 Subject: [PATCH 2/2] checking stuff --- test/bases.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/bases.jl b/test/bases.jl index ea153c1a..6b0ae558 100644 --- a/test/bases.jl +++ b/test/bases.jl @@ -4,4 +4,12 @@ using UnfoldSim @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 \ No newline at end of file