-
Notifications
You must be signed in to change notification settings - Fork 49
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
Add Butterworth Filter #242
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #242 +/- ##
==========================================
+ Coverage 92.14% 92.17% +0.02%
==========================================
Files 12 12
Lines 1642 1648 +6
==========================================
+ Hits 1513 1519 +6
Misses 129 129
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs and tests are needed.
Some docstrings in ImageFiltering are written in Julia pre-1.0 age, so you can follow the guideline in https://docs.julialang.org/en/v1/manual/documentation/#man-documentation. I personally prefer a verbose docstring, e.g., the docstring for Gabor
in #235. You can also follow how unit tests are written in that PR.
Style fix Co-authored-by: Johnny Chen <[email protected]>
#Citation | ||
Selesnick, Ivan W., and C. Sidney Burrus. "Generalized digital Butterworth filter design." IEEE Transactions on signal processing 46.6 (1998): 1688-1694. | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line here would cause ?Kernel.butterworth
giving nothing.
@@ -509,6 +509,26 @@ moffat(α::Real, β::Real) = moffat(α, β, ceil(Int, (α*2*sqrt | |||
sum(x.^2) | |||
end | |||
|
|||
""" | |||
butterworth(n,Wn,ls{tuple}) -> k |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation, and ::
for type annotation.
butterworth(n,Wn,ls{tuple}) -> k | |
butterworth(n, Wn, ls::Dims) -> k |
@@ -509,6 +509,26 @@ moffat(α::Real, β::Real) = moffat(α, β, ceil(Int, (α*2*sqrt | |||
sum(x.^2) | |||
end | |||
|
|||
""" | |||
butterworth(n,Wn,ls{tuple}) -> k | |||
Returns a multidimensional dimensional Butterworth kernel contained in an OffsetArray(::Matrix{Float64}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one extra new line after the signature.
Returns a multidimensional dimensional Butterworth kernel contained in an OffsetArray(::Matrix{Float64}) | |
Returns a multidimensional dimensional Butterworth kernel contained in an OffsetArray(::Matrix{Float64}) |
- `n` is the order of the filter | ||
- `Wn` is the normalized cutoff frequency | ||
- `ls` is the size of the kernel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need indentation for the markdown list
- `n` is the order of the filter | |
- `Wn` is the normalized cutoff frequency | |
- `ls` is the size of the kernel | |
- `n` is the order of the filter | |
- `Wn` is the normalized cutoff frequency | |
- `ls` is the size of the kernel |
|
||
- `n` is the order of the filter | ||
- `Wn` is the normalized cutoff frequency | ||
- `ls` is the size of the kernel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why you use ls
for kernel size instead of sz
? The former seems to come from the math equation of butterworth kernel. Can you also add the equation to the docstring so that people immediately knows what n
, Wn
, ls
means and how they affects the results?
@. 1/(1+(sqrt(2)-1)*(df(R)/Wn)^nn) | ||
end | ||
|
||
butterworth(n::Real, Wn::Real, ls::Integer) = butterworth(n, Wn, (ls,ls)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This convenient method only makes sense when butterworth
is 2D only; otherwise, we should not add it.
@test Kernel.butterworth(a,b,(3,3)) == Kernel.butterworth(a,b,3) | ||
@test Kernel.butterworth(a,b,(4,4)) == Kernel.butterworth(a,b,4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need some numerical tests here, can you test against one or two results generated from other frameworks that has butterworth
implemented or manual calculated results? Also do remember to add a comment on how the references are generated.
We also need to test that the kernel axis are "centered". For instance, the axes should be (-1:1, -1:1)
when kernel size is (3, 3)
. Also need to test the even case as well.
Selesnick, Ivan W., and C. Sidney Burrus. "Generalized digital Butterworth filter design." IEEE Transactions on signal processing 46.6 (1998): 1688-1694. | ||
""" | ||
|
||
function butterworth(n::Real, Wn::Real, ls::Tuple{Integer,Integer}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like if we do
function butterworth(n::Real, Wn::Real, ls::Tuple{Integer,Integer}) | |
function butterworth(n::Real, Wn::Real, ls::NTuple{N,Integer}) where N |
we immediately get a N-dimensional implementation as the docstring says: "multidimensional dimensional Butterworth kernel". Can you check this and if it works, add 1d and 3d tests? Also don't forget to update the docstring OffsetArray(::Matrix{Float64})
.
In response to feature request #240
Please let me know if there are any fixes to be done on the code.