Hi,
I am happily using gnuplot since literally decades all the time.
Today I discovered a new feature: Contrary to what the FAQ says, I CAN filter data (e.g. a time series) with an IIR filter within gnuplot before plotting. This is beacuse gnuplot implements the C-style sequence in expressions in parentheses, separated by commas. For example
f(x) = (a=sin(b), c=cos(d), e)
performs the calculations for a and c and returns e as function value.
Using this I can make an IIR filter:
a0 = 1.552667371109573390e-03
a1 = 6.410598353401319484e-03
b1 = -1.900560403882284977e+00
b2 = 9.085236696067958695e-01
x1 = 0.0
y1 = 0.0
y2 = 0.0
y0 = 0.0
f(x0) = (y0 = a0x0 + a1x1 - b1y1 - b2y2, x1 = x0, y2 = y1, y1 = y0, y0)
plot "datafile" using 0:(f($2)) with lines
This particular filter is a second order lowpass at 0.015 * sampling frequency.
This works for version gnuplot version 5.2
Thanks for the cintinuing great work!
With best greetings,
Gerhard
Very nice! Could you explain how those coefficients are calculated, practically? I tried reading up on IIR filters, but the texts I found are gibberish to me. This could be a nice demo script.
FIR filters also aren't hard, I'll work out and upload an example of a script I've written in the next days. Just need two arrays for the coefficients and the sampling buffer, and gnuplot's summation operator.