Skip to content

Commit

Permalink
fix: resample multi-channel signal
Browse files Browse the repository at this point in the history
  • Loading branch information
ymtoo committed Aug 24, 2023
1 parent fa182dd commit 251e449
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/dsp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,10 @@ sfiltfilt(coef, x) = signal(filtfilt(coef, samples(x)), framerate(x))
Same as [`resample`](https://docs.juliadsp.org/stable/filters/#DSP.Filters.resample),
but correctly handles sampling rate conversion.
"""
sresample(x, rate) = signal(resample(samples(x), rate), rate * framerate(x))
sresample(x, rate, coef) = signal(resample(samples(x), rate, coef), rate * framerate(x))
sresample(x::AbstractVector, rate) = signal(resample(samples(x), rate), rate * framerate(x))
sresample(x::AbstractVector, rate, coef) = signal(resample(samples(x), rate, coef), rate * framerate(x))
sresample(x::AbstractMatrix, rate) = signal(resample(samples(x), rate; dims=1), rate * framerate(x))
sresample(x::AbstractMatrix, rate, coef) = signal(resample(samples(x), rate, coef; dims=1), rate * framerate(x))

# overload DSP versions of the above functions
DSP.filt(f::AbstractVector{<:Number}, x::SampledSignal) = sfilt(f, x)
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,12 @@ end
@test framerate(x1) == framerate(x)
x1 = sresample(x, 3//2)
@test framerate(x1) == 3 * framerate(x) / 2
x1 = sresample(x, 3//2, [1,1,1])
@test framerate(x1) == 3 * framerate(x) / 2
x1 = sresample([x x], 3//2)
@test framerate(x1) == 3 * framerate(x) / 2
x1 = sresample([x x], 3//2, [1,1,1])
@test framerate(x1) == 3 * framerate(x) / 2
x1 = resample(x, 3//2)
@test framerate(x1) == 3 * framerate(x) / 2

Expand Down

0 comments on commit 251e449

Please sign in to comment.