-
Notifications
You must be signed in to change notification settings - Fork 50
Add Butterworth Filter #242
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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}) | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one extra new line after the signature.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| - `n` is the order of the filter | ||||||||||||||
| - `Wn` is the normalized cutoff frequency | ||||||||||||||
| - `ls` is the size of the kernel | ||||||||||||||
|
Comment on lines
+516
to
+518
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need indentation for the markdown list
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why you use |
||||||||||||||
| #Citation | ||||||||||||||
| Selesnick, Ivan W., and C. Sidney Burrus. "Generalized digital Butterworth filter design." IEEE Transactions on signal processing 46.6 (1998): 1688-1694. | ||||||||||||||
| """ | ||||||||||||||
|
|
||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line here would cause
Suggested change
|
||||||||||||||
| function butterworth(n::Real, Wn::Real, ls::Tuple{Integer,Integer}) | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like if we do
Suggested change
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 |
||||||||||||||
| ws = map(n->(ceil(Int,n)>>1), ls) | ||||||||||||||
| R = CartesianIndices(map(w->IdentityUnitRange(-w:w), ws)) | ||||||||||||||
| nn = 2*n | ||||||||||||||
| @. 1/(1+(sqrt(2)-1)*(df(R)/Wn)^nn) | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| butterworth(n::Real, Wn::Real, ls::Integer) = butterworth(n, Wn, (ls,ls)) | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This convenient method only makes sense when |
||||||||||||||
|
|
||||||||||||||
| """ | ||||||||||||||
| reflect(kernel) --> reflectedkernel | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,6 +238,14 @@ using ImageFiltering: IdentityUnitRange | |
| fwhm = ceil(Int, (α*2*sqrt(2^(1/β) - 1)) * 4) | ||
| @test Kernel.moffat(α, β) == Kernel.moffat(α, β, (fwhm, fwhm)) | ||
| end | ||
|
|
||
| @testset "butterworth" begin | ||
| a = rand() | ||
| b = rand() | ||
| @test Kernel.butterworth(a,b,(3,3)) == Kernel.butterworth(a,b,3) | ||
| @test Kernel.butterworth(a,b,(4,4)) == Kernel.butterworth(a,b,4) | ||
|
Comment on lines
+245
to
+246
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 We also need to test that the kernel axis are "centered". For instance, the axes should be |
||
| end | ||
|
|
||
| end | ||
|
|
||
| nothing | ||
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.