We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
For drawing a line, you can check bezier curves:
You can use check
https://forum.processing.org/two/search?Search=bezier
For example:
https://forum.processing.org/two/discussion/21355/fixed-make-bezier-curve-pass-through-control-points/p1
https://forum.processing.org/two/discussion/comment/91900/#Comment_91900
https://forum.processing.org/two/discussion/comment/92127/#Comment_92127
However for smoothing, you can try any option available in the web. For example: https://en.wikipedia.org/wiki/Smoothing
I am not sure if Processing has any library that would do something like that. For best fit, you need to know beforehand the behavior of the discharge of your battery. As you see, your battery discharges almost linearly from 0 to 660 and then afterward it drops faster. For a best fit, you need to know a function what will have that shape and that you can controlled with a finite number of parameters. In theory, it is possible to try to characterize the discharge of a battery. In practice, it depends on the age of the battery, charge and discharge cycles it went through, quality of battery materials, etc. etc. etc. It is lots of work and for smoothing I will just focus on a windows averaging algorithm which can be implemented easily in Java.
Kf
@cygig -- what kind of data resolution are you smoothing? How many sample values along the x axis are you trying to fit a curve to?
My first recommendation would be to look at the Curves Tutorial.
Option 1: Spline. In particular look at its example of splines drawn with
curveVertex()
-- these can be your data points.Option 2: Bézier. Depending on your data resolution, you could also choose to render bezier curves through sets of your points, although this is trickier -- you need to find the control points to fit the curve to your data points. There is a recent discussion of how to do this for four points here:
...and I think the method could be extended to n points. If you are interested in digging in to these kinds of approaches then check out the very interesting ArcLengthParameterization example sketch.
Only if you are interested, example analysis on Li-ion batteries for example
http://www-personal.umich.edu/~hpeng/DSCC2013_Weng.pdf
http://www.mdpi.com/1996-1073/8/4/2889/pdf
Kf
Awesome guys! Good to have such a helpful community for beginners like me.