How to apply a butterworth filter in a loop?

What did you try? The documentation may lack examples written out for you, but it documents the relevant functions.

For example, this code applies your filter 1 element at a time:

butterF = DSP.Filters.DF2TFilter(butter)
results2 = zeros(N)
for i = 1:N
    @views filt!(results2[i:i], butterF, measurements[i:i])
end

(Bigger batches should be more efficient, but the complexity should still be linear in N.)

3 Likes