Digital filters are used to apply a mathematical operation to a sampled signal. One of the common formulations is the "direct form II transposed" which can represent both infinite impulse response (IIR) and finite impulse response (FIR) filters, as well as being more numerically stable than other forms. [1]

Task

Filter a signal using an order 3 low-pass Butterworth filter. The coefficients for the filter are a=[1.00000000, -2.77555756e-16, 3.33333333e-01, -1.85037171e-17] and b = [0.16666667, 0.5, 0.5, 0.16666667]

The signal that needs filtering is the following vector: [-0.917843918645, 0.141984778794, 1.20536903482, 0.190286794412, -0.662370894973, -1.00700480494, -0.404707073677 ,0.800482325044, 0.743500089861, 1.01090520172, 0.741527555207, 0.277841675195, 0.400833448236, -0.2085993586, -0.172842103641, -0.134316096293, 0.0259303398477, 0.490105989562, 0.549391221511, 0.9047198589]

Butter=: {{
  t=. (#n) +/ .*&(|.n)\(}.n*0),y
  A=.|.}.m
  for_i.}.i.#y do.
    t=. t i}~ (i{t) - (i{.t) +/ .* (-i){.A
  end.
  t%{.m
}}
 
 
sig=: ". rplc&('-_') {{)n
  -0.917843918645, 0.141984778794, 1.20536903482, 
   0.190286794412,-0.662370894973,-1.00700480494,
  -0.404707073677, 0.800482325044, 0.743500089861,
   1.01090520172,  0.741527555207, 0.277841675195,
   0.400833448236,-0.2085993586,  -0.172842103641,
  -0.134316096293, 0.0259303398477,0.490105989562,
   0.549391221511, 0.9047198589
}}-.LF
 
a=: 1.00000000 _2.77555756e_16 3.33333333e_01 _1.85037171e_17
b=: 0.16666667 0.5 0.5 0.16666667
 
   4 5$ a Butter b sig
_0.152974 _0.435258 _0.136043 0.697503   0.656445
_0.435482  _1.08924 _0.537677  0.51705    1.05225
 0.961854   0.69569  0.424356 0.196262 _0.0278351
_0.211722 _0.174746 0.0692584 0.385446   0.651771