Filtering only big changes (Processing)

mistergreen:
If you want to smooth out the peaks and valleys, you take the average or median of a group of data . Cycle through the entire data set.

You can then stretch and shift the visualization however you want through addition, subtraction, multiplication, etc...like how you would manipulate a sine curve.

I understand "HOW TO" , however what I want help with is making a code.

I've tried multiple equations but they give me either worse noise or error messages, what I think is the problem is what PaulS said earlier about the fact that my declaration of variables is inside the serialevent, and as soon as the cycle repeats, my "old values" are erased and therefore theres no old value to compare to