Here's a low pass filter in blocks, courtesy of Wikipedia
// Return RC low-pass filter output samples, given input samples,
// time interval dt, and time constant RC
function lowpass(real[0..n] x, real dt, real RC)
var real[0..n] y
var real α := dt / (RC + dt)
y[0] := α * x[0]
for i from 1 to n
y[i] := α * x[i] + (1-α) * y[i-1]
return y
The loop that calculates each of the n outputs can be refactored into the equivalent:
for i from 1 to n
y[i] := y[i-1] + α * (x[i] - y[i-1])
and here are the blocks, assuming a non-empty list of x values, and dt and RC as described at that article.
