Filter function in J

In Matlab the filter is a function that enables convert a LCCDE in time domain to a computable function. That is, for array a n and b n , input signal x ( t ) , compute y ( t ) so that the relation below hold.

a 1 y ( t ) + a 2 y ( t 1 ) + . . . + a n ( t n + 1 ) = b 1 x ( t ) + b 2 x ( t 1 ) + . . . + b x ( t n + 1 )

As a Functional/Array programmer, it is not difficult to discover the data dependency and get

y ( t ) = b × x ( t t n + 1 ) a 2 n × y ( t 1 t n + 1 ) a 1
and the fact that
b × x ( t t n + 1 )
can be parallelized.
  |comp_b=. [+/@:*(-@i.@#@[) |.!.0"0 1]

The actual y is dependent on the previous n-1 results. This gives the relation to be used by fold (F..):

  |a_1=.{.a
  |a_n=.}.a
  |fn=.],~a_1%~[-a_n+/@:*(#a_n){.]

Finally, assemble all together gives:

  |filter =: {{
  |'a b'=.m
  |comp_b=. [+/@:*(-@i.@#@[) |.!.0"0 1]
  | 
  |a_1=.{.a
  |a_n=.}.a
  |fn=.],~a_1%~[-a_n+/@:*(#a_n){.]
  |(0$0) |.F..fn b comp_b y
  |}}

Bibliography

[filter] 1-D digital filter. Mathworks. https://www.mathworks.com/help/matlab/ref/filter.html.

[nuvoc] NuVoc. J Wiki. https://code.jsoftware.com/wiki/NuVoc.