Going back to your original example, my impression is that the way of thinking it is not the natural way to think it in Julia. You defined a
type for a filter, where it would be more natural to define a function directly, such as:
function IIRfilter(xv;state=nothing,alpha=0.5) @assert 0 <= alpha <= 1 "alpha must be between 0 and 1" xf = similar(xv) if state == nothing state = xv[begin] end for i in eachindex(xv) xf[i] = alpha*state + (1 - alpha)*xv[i] state = xf[i] end return xf end
and use it with:
xv = rand(3000) xf = IIRfilter(xv,alpha=0.9)
maybe in Julia we separe more the data (
xv) from the action over the data (the filter). This is not directly related to the original post, but maybe is a way to start moving to a more function-centered programming, which will be more natural in Julia.
Another small things:
This can be written as (and
collect there will create an unnecessary vector):
for i in 1:N xf[i] = filter(f,xv[i]) end
xf = filter.(f,xv)
. indicates broadcasting. (maybe this does not work in your case because the operations depend on the previous state).
rand(N) (there is a difference in Julia between a matrix with one column and a vector, probably you want a vector there).