Skip to content

Commit

Permalink
fix(dsp): bug fix for #48
Browse files Browse the repository at this point in the history
  • Loading branch information
mchitre committed Nov 6, 2024
1 parent e49039c commit 8a4ee16
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SignalAnalysis"
uuid = "df1fea92-c066-49dd-8b36-eace3378ea47"
authors = ["Mandar Chitre <[email protected]>"]
version = "0.9.1"
version = "0.9.2"

[deps]
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
Expand Down
12 changes: 10 additions & 2 deletions src/dsp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export fir, removedc, removedc!, demon
export upconvert, downconvert, rrcosfir, rcosfir
export mseq, gmseq, circconv, circcorr, goertzel, pll, hadamard
export mfilter, findsignal, dzt, idzt
export istft, whiten, filt, filtfilt, resample, delay!, compose
export istft, whiten, filt, filtfilt, resample, delay, delay!, compose

"""
$(SIGNATURES)
Expand Down Expand Up @@ -683,7 +683,7 @@ function delay!(x, v::Real; npad=32)
ifft!(X)
for (i, j) zip(eachindex(x), 1:length(x))
k = j - vi + npad
if k < 1 || k > length(X) ÷ 2
if k < 1 || k > length(X)
x[i] = 0
elseif eltype(x) <: Complex
x[i] = X[k]
Expand All @@ -696,6 +696,14 @@ end

delay!(x, t::Units.Unitful.Time; kwargs...) = delay!(x, inseconds(t) * framerate(x); kwargs...)

"""
delay(x, v)
Create a delayed version of signal `x` with `v` units of delay.
See [`delay!`](@ref) for details.
"""
delay(x, v; kwargs...) = delay!(copy(x), v; kwargs)

"""
$(SIGNATURES)
Finds up to `n` strongest copies of reference signal `r` in signal `s`. The reference
Expand Down
12 changes: 12 additions & 0 deletions test/tests-core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ function test_dsp()
delay!(x, 10.7)
delay!(x, 21.3)
@test samples(x) y atol=0.05

x = signal(vcat(zeros(128), [1.0, 2.0, 3.0, 2.0, 1.0], zeros(128)), 100.0)
y = copy(samples(x))
delay!(x, 0.1s)
delay!(x, -10)
Expand All @@ -684,6 +686,8 @@ function test_dsp()
delay!(x, 10.7)
delay!(x, 21.3)
@test samples(x) y atol=0.05

x = signal(vcat(zeros(128), ComplexF64[1.0, 2.0, 3.0, 2.0, 1.0], zeros(128)), 100.0)
y = copy(samples(x))
delay!(x, 0.1s)
delay!(x, -10)
Expand All @@ -698,11 +702,19 @@ function test_dsp()
delay!(x, 10.7)
delay!(x, 21.3)
@test samples(x) y atol=0.05

x = signal(vcat(zeros(ComplexF32, 128), ComplexF32[1.0, 2.0, 3.0, 2.0, 1.0], zeros(ComplexF32, 128)), 100.0)
y = copy(samples(x))
delay!(x, 0.1s)
delay!(x, -10)
@test samples(x) y atol=1e-3

x = signal(Float64[1,2,3,4,5,6,7,0],3)
y = copy(samples(x))
delay!(x, 0.9999999)
delay!(x, -0.9999999)
@test samples(x) y atol=1e-3

x = rand(rng, ComplexF64, 4096)
@test vec(dzt(x, length(x))) == x
@test dzt(x, 1) fft(x) / sqrt(length(x))
Expand Down

2 comments on commit 8a4ee16

@mchitre
Copy link
Member Author

@mchitre mchitre commented on 8a4ee16 Nov 6, 2024

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/118816

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.2 -m "<description of version>" 8a4ee1626b0e75001b34e0a6b9a34f5a11a788f9
git push origin v0.9.2

Please sign in to comment.