Smooth a graph in Processing

edited April 2017 in Questions about Code

I am making a program to generate a battery discharge graph for accessing the capacity of batteries (because Excel is too slow and troublesome).

I average a group of values together to make my graph smoother, and I am wondering if there are other methods to draw smoother graphs in Processing. I heard of methods like regression and best-fit curves, but I never knew how they can be implemented in Processing, and to be honest, I am math ability is abysmal.

Any input and advices will be welcome!

Here is my graph:

Here is the one generated by the electronic dummy load software:

I would prefer to generate my own graph to control the design and be able to output in a vector file.

And here is a part of my code:

String fname = "Trustfire 14500 900mAh 0.5A.csv";
CellData cellData = new CellData();
float[] voltage;
float[] capacity;

void setup(){
  size(800, 600);
  background(255);
  cellData.readCSV(fname);

  voltage = cellData.toMappedArray("voltage", 550, 50);
  voltage = bandAvg(voltage, 50);

  capacity = cellData.toMappedArray("capacity", 50, 750);
  capacity = bandAvg(capacity, 50);


  beginShape();
  for (int i=0; i<voltage.length; i++){
    vertex(capacity[i],voltage[i]);    
  }
  endShape();


}

void draw(){
}

Answers

Sign In or Register to comment.