Skip to content

Commit

Permalink
Fix setphase!(::Union{FIRInterpolator, FIRRational}, ϕ) for patholo…
Browse files Browse the repository at this point in the history
…gical cases

For odd number of phases `Nφ` and even length of the filter kernel, the old
code would yield `qidx` above `Nφ`, namely equal tp `Nφ+1`, which would result
in a `BoundsError` during `resample`. Rewrite the code to reduce `qidx` to `1`
in this case and increase `inputDeficit` by one instead. All other
constellations should be unaffected.
  • Loading branch information
martinholters committed Nov 20, 2024
1 parent 3d87980 commit ee30bf2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Filters/stream_filt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ end

function setphase!(kernel::Union{FIRInterpolator, FIRRational}, ϕ::Real)
ϕ >= zero(ϕ) || throw(ArgumentError("ϕ must be >= 0"))
(ϕ, xThrowaway) = modf)
kernel.inputDeficit += round(Int, xThrowaway)
kernel.ϕIdx = round*(kernel.Nϕ) + 1.0)
xThrowaway, ϕIdx = divrem(round(Int, ϕ * kernel.Nϕ), kernel.)
kernel.inputDeficit += xThrowaway
kernel.ϕIdx = ϕIdx + 1
nothing
end

Expand Down
4 changes: 4 additions & 0 deletions test/filt_stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,7 @@ end
test_rational(h, x, interpolation)
end
end

# check that these don't throw; the output should actually probably be longer
@test resample(1:2, 3, [zeros(2); 1; zeros(3)]) == [1, 0, 0, 2] # [1, 0, 0, 2, 0, 0]
@test resample(1:2, 3//2, [zeros(2); 1; zeros(3)]) == [1, 0] # [1, 0, 0]

0 comments on commit ee30bf2

Please sign in to comment.