Filtering only big changes (Processing)

PeterH:

Quick_questions:

smoothed = ((weight * smoothed) + newSample) / (weight + 1);

I'm sure you get the idea.

actually I dont get the idea, could you elaborate?

The idea is that the input is a sequence of values which are varying slightly. The output is a value which represents the average of recent values so that it only changes relatively slowly. In the code I posted, smoothed is the output value and newSample is the new value. Weight determines how slowly the smoothed value changes. A weight of zero means the smoothed value is always equal to the newValue - no smoothing at all. Bigger numbers mean more smoothing - the smoothed value will change more slowly. If you don't get how it achieves this then make up a sequence of input numbers and run the calculation through in your head to see what it does.
[/quote]

I get it, I understand the concept, again I dont know how to conver it from "concepts" to codes that work in my particular case, I tried this (similar to your example, I got it from wikipedia)

 import processing.serial.*;
 
 Serial myPort;        // The serial port
 int xPos = 1;         // horizontal position of the graph
 float [] Smooth0 = new float[5];
 float [] Smooth1 = new float[5];
 float [] inByte = new float[5];
 float [] inByte1 = new float[5];
 void setup () {
 // set the window size:
 size(800, 600);   
 myPort = new Serial(this, "COM4", 115200);
 // don't generate a serialEvent() unless you get a newline character:
 myPort.bufferUntil('\n');
 // set inital background:
 background(0);
 }
 void draw () {
 // everything happens in the serialEvent()
 }
 
 void serialEvent (Serial myPort)
 {
 // get the ASCII string:

 String inString = myPort.readStringUntil('\n');
 
 if (inString != null && inString.length() > 0) {
 // trim off any whitespace:
 inString = trim(inString);
 String [] inputStringArr = split(inString, ",");
 
 // convert to an int and map to the screen height:
 
 inByte1[0] = float(inputStringArr[0])-500; 
 inByte1[1] = float(inputStringArr[1])-500;
 inByte1[2] = float(inputStringArr[2])-500;
 inByte1[3] = float(inputStringArr[3])-500;
 inByte1[4] = float(inputStringArr[4])-500;
 
 // FILTER VALUES TO SMOOTHEN LINE USING SIMPLE MOVING AVERAGE

 inByte[0] = inByte1[0] + ((inByte1[0]-inByte[0])/2);
 inByte[1] = inByte1[1] + ((inByte1[1]-inByte[1])/2);
 inByte[1] = inByte1[2] + ((inByte1[2]-inByte[2])/2);
 inByte[1] = inByte1[3] + ((inByte1[3]-inByte[3])/2);
 inByte[1] = inByte1[4] + ((inByte1[4]-inByte[4])/2);
 
 inByte[0] = map(inByte[0], 0, 1023, 0, height);
 inByte[1] = map(inByte[1], 0, 1023, 0, height);
 inByte[2] = map(inByte[2], 0, 1023, 0, height);
 inByte[3] = map(inByte[3], 0, 1023, 0, height);
 inByte[4] = map(inByte[4], 0, 1023, 0, height);
 }

I declared the variables outside, however the values are declared inside the serialevent, but with those particular commands, I get crazier things. so I dont know whats up =/


thank you for the replies BTW