-
Notifications
You must be signed in to change notification settings - Fork 110
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
Stream data to digital filter / live IIR filter #548
Comments
Options I see: use The documentation here is quite unhelpful, unfortunately: for example, the two definitions of |
Yes, in addition to what @mbaz mentioned, I believe julia> p = PolynomialRatio([1:3;], [2:10;]);
julia> a = LiveDigitalFilter{Float64}(p)
LiveDigitalFilter: n=0 | value=0.0
julia> _fit!(a, 10), _fit!(a, 23), _fit!(a, -1)
(5.0, 14.0, 6.5)
julia> _fit!(a, 2), _fit!(a, 3), _fit!(a, 4)
(-15.75, -37.375, 19.8125)
julia> sf = DF2TFilter(p);
julia> filt(sf, [10,23,-1])
3-element Vector{Float64}:
5.0
14.0
6.5
julia> filt(sf, [2,3,4])
3-element Vector{Float64}:
-15.75
-37.375
19.8125 |
I think type annotations within the docstring function definitions would be helpful? |
@wheeheee I'd do p = PolynomialRatio([1:3;], [2:10;])
ldf1 = LiveDigitalFilter{Float64}(p)
fit!(ldf1, Float64[10, 23, -1])
fit!(ldf1, Float64[2, 3, 4])
println(value(ldf1)) # or println(ldf1) What is odd with The main advantage I see with working with OnlineStatsBase is that our filter can easily integrates with all online algorithm statistics that https://joshday.github.io/OnlineStats.jl/ provides Maybe something like that mutable struct LiveDigitalFilter2{T} <: AbstractLiveFilter{T}
value::T
n::Int
coeff
function LiveDigitalFilter2{T}(coeff) where {T}
new{T}(0, 0, coeff)
end
end
function OnlineStatsBase._fit!(f::LiveDigitalFilter2, x)
f.n += 1
f.value = filt(f.coeff, [x])[end]
end (not sure if coeff is the appropriate name field... not sure what type should be used also) and we can use it like ldf2 = LiveDigitalFilter2{Float64}(DF2TFilter(p))
fit!(ldf2, Float64[10, 23, -1])
fit!(ldf2, Float64[2, 3, 4])
println(value(ldf2)) # or println(ldf2) or with mutable struct LiveDigitalFilter2{T} <: AbstractLiveFilter{T}
value::T
n::Int
coeff
out::Vector
function LiveDigitalFilter2{T}(coeff) where {T}
new{T}(0, 0, coeff, T[0])
end
end
function OnlineStatsBase._fit!(f::LiveDigitalFilter2, x)
f.n += 1
filt!(f.out, f.coeff, [x])
f.value = f.out[end]
end This might be useful. If user wants to preserve older output values, b can be wrapped into You are right. Type annotions would be helpful. Moreover I think doc would be much better with some examples, some plots, some notebooks... it will help beginners to better understand how to start with this library. |
Yes, type annotations is what is needed. |
Hello,
Following discussion started at https://discourse.julialang.org/t/scipy-signal-iirfilter-equivalent-in-dsp-jl-and-more/110783/4 I wonder if DSP.jl provides structure of digital filter which can be used for streaming input data ie processing live data and not a vector of precalculated values ?
ie is there some kind of filter which preserve its state each time a new input is coming.
I did this Pluto.jl notebook https://gist.github.com/scls19fr/0ae16d92ca39d3eb9c42cc0fc618c723 for experimenting this kind of problem (both for filtering a vector of input signal and for displaying streamed signal and output of filter thanks to PlutoUI Clock).
I end up to convert idea mentioned https://www.samproell.io/posts/yarppg/yarppg-live-digital-filter/ with Julia.
OnlineStatsBase.jl API looks interesting for this kind of work (this is API which is used by OnlineStats.jl
So I did
Notebook run on my side at around 10fps.
Any opinion?
The text was updated successfully, but these errors were encountered: