How to do a lowpass signal filtering in Processing?

just filter math

// low pass filter
// numeric recursive filter first order
// kll 1/2019

float framerate = 20, inval, fil;         // tune framerate
float A=0.1, B = 1.0 - A;                 // filter tuning A
int   bd=2, xpos=0;
color bg = color(0, 0, 60);               // oszi look
color in_c = color(200, 200, 0);
color fil_c= color(0, 200, 0);

void setup() {
  size(600, 200);
  inval = height - mouseY;
  fil = inval;
  frameRate(framerate);
  noSmooth();
  background(bg);
  println("fil = inval * "+A+" + fil * "+B);
  println("reading mouseY");
}

void draw() {
  //surface.setTitle("LPF "+nf(frameRate, 1, 1)+" FPS");
  inval = height - mouseY;              // get data
  fil = inval * A + fil * B;            // the filter!
  scope(inval, fil);                    // show it
}

void scope(float inval, float fil) {
  stroke(bg);                         // clean line
  line(xpos, 0, xpos, height);
  stroke(in_c);
  ellipse(xpos, height-inval, bd, bd);
  stroke(fil_c);
  ellipse(xpos, height-fil, bd, bd);
  xpos++;  if (xpos >= width ) xpos = 0;
}
2 Likes