diff --git a/src/dsp.jl b/src/dsp.jl index e35c32b..7606b17 100644 --- a/src/dsp.jl +++ b/src/dsp.jl @@ -655,7 +655,8 @@ times are computed based on a matched filter. If it is set to `false`, an iterative optimization is performed to find more accruate arrival times. Returns named tuple `(time=t, amplitude=a)` where `t` is a vector of arrival -times and `a` is a vector of complex amplitudes of the arrivals. +times and `a` is a vector of complex amplitudes of the arrivals. The arrivals +are sorted in ascending order of arrival times. # Examples: ```julia-repl @@ -689,7 +690,8 @@ function findsignal(r, s, n=1; prominance=0.2, coarse=false) p = p[ndx] if coarse t = time(Float64.(p), s) - return (time=t, amplitude=samples(mfo[p])) + ndx = sortperm(t) + return (time=t[ndx], amplitude=samples(mfo[p[ndx]])) end # iterative fine arrival time estimation margin = 5 # arrival time may vary up to margin from coarse estimates @@ -716,7 +718,8 @@ function findsignal(r, s, n=1; prominance=0.2, coarse=false) pp = v[1:length(p)] .+ i t = time(pp, s) a = complex.(v[length(p)+1:2*length(p)], v[2*length(p)+1:3*length(p)]) - (time=t, amplitude=a) + ndx = sortperm(t) + (time=t[ndx], amplitude=a[ndx]) end """ diff --git a/test/runtests.jl b/test/runtests.jl index 2c47621..a4e1b14 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -637,6 +637,11 @@ end @test t ≈ [0.000775, 0.001545, 0.003124] atol=1e-5 @test real(a) / real(a[1]) ≈ [1.0, -0.8, 0.6] atol=1e-2 + y = compose(real(x), time([32.75, 64.25, 129.0], x), [0.8, -0.7, 1.0]; duration=0.2) + t, a = findsignal(x, y, 3; coarse=false) + @test t ≈ [0.000775, 0.001545, 0.003124] atol=2e-6 + @test real(a) / real(a[3]) ≈ [0.8, -0.7, 1.0] atol=1e-2 + @test delay!([1,2,3,4], -1) == [2,3,4,0] @test delay!([1,2,3,4], 1) == [0,1,2,3]