Smoothing noisy input data. Are there good ways?
in
Programming Questions
•
2 years ago
Hey everyone,
I am looking for a good way to smooth noisy input. I will use noisy devices - a gyro and video tracked cursor data - they produce very jumpy data.
So far i have tried putting values in an array and averaging them. Works passably with small deviations. But i am guessing there should be something like a "lowpass filter" way of doing it, or even some others that i don't know.
Any ideas are very appreciated. (also on improving current code)
below is my code so far...
- int buffSz = 10;
- int[] myBufferX = new int[buffSz];
- int[] myBufferY = new int[buffSz];
- void setup() {
- size(400, 400);
- smooth();
- }
- void draw() {
- background(0);
- strokeWeight(2);
- stroke(255);
- fill(255);
- addInt(width/2+(int)random(20), height/2+(int)random(20));
- //println("avr X " +avrX());
- //println("avr Y " +avrY());
- ellipse(avrX(), avrY(), 40, 40);
- }
- //FIFO queue
- void addInt(int newIntX, int newIntY) {
- for (int i=buffSz-1; i>0; i--) {
- myBufferX[i] = myBufferX[i-1];
- }
- for (int j=buffSz-1; j>0; j--) {
- myBufferY[j] = myBufferY[j-1];
- }
- myBufferX[0] = newIntX;
- myBufferY[0] = newIntY;
- }
- //average of Y coordinates
- int avrX() {
- int total=0;
- int avrX=mouseX;
- for (int i=buffSz-1; i>=0; i--) {
- total+=myBufferX[i];
- avrX=total/buffSz;
- }
- return avrX;
- }
- // average of Y coordinates
- int avrY() {
- int total=0;
- int avrY=mouseY;
- for (int b=buffSz-1; b>=0; b--) {
- total+=myBufferY[b];
- avrY=total/buffSz;
- //println(avrY);
- }
- return avrY;
- }
1