Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resample multi-channel signals #42

Merged
merged 5 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dsp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ 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, rate) = signal(resample(samples(x), rate; dims=1), rate * framerate(x))
sresample(x, 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
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,18 @@ 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)
mchitre marked this conversation as resolved.
Show resolved Hide resolved
@test framerate(x1) == 3 * framerate(x) / 2
x1 = resample([x x], 3//2; dims=1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x1 = resample([x x], 3//2; dims=1)
x1 = resample([x x], 3//2)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dims=1 is removed.

@test framerate(x1) == 3 * framerate(x) / 2
x1 = resample([x x], 3//2, [1,1,1]; dims=1)
mchitre marked this conversation as resolved.
Show resolved Hide resolved
@test framerate(x1) == 3 * framerate(x) / 2

x = signal(randn(rng, 100), 10kHz)
x1 = signal(vcat(zeros(1000), x/2, zeros(1000)), 10kHz)
Expand Down
Loading