Skip to content

Commit

Permalink
feat(dsp): ensure that the findsignal() output is sorted by arrival time
Browse files Browse the repository at this point in the history
  • Loading branch information
mchitre committed Aug 19, 2023
1 parent 3f10bed commit bfd4b48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/dsp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

"""
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit bfd4b48

Please sign in to comment.