Reputation: 35149
Given a collection of discrete [x, y] points, can you derive a continuous function that approximates the [x, y] points and meets two constraints:
?
This is really an embedded system question, but let me explain. I need to interface a piece of analog hardware that cough could have been designed better. But -- as usual -- it's the embedded system engineer's responsibility to correct for shortcomings in the hardware.
Consequently, I need to formulate an accurate model for the following function:
The blue dots are taken from actual measurement, the red line is scipy's cubic interpolation between the dots.
The problem is that the resulting 82+ control points create far too much data to stuff into the client's dinky little microcontroller. (I'm displaying a subset of the total dataset.)
So my question is: How can I minimize the number of spline control points and stay within some given MSE?
Here's the set of x and y points used in the above graph.
x = [ 3.387, 3.552, 3.714, 3.868, 4.012, 4.15 , 4.278, 4.407,
4.529, 4.646, 4.757, 4.852, 4.924, 4.974, 5.012, 5.046,
5.084, 5.148, 5.267, 5.426, 5.593, 5.75 , 5.9 , 6.03 ,
6.145, 6.26 , 6.37 , 6.48 , 6.6 , 6.72 , 6.83 , 6.945,
7.055, 7.175, 7.29 , 7.405, 7.52 , 7.63 , 7.75 , 7.86 ,
7.98 , 8.09 ]
y = [ 0.05 , 0.055, 0.06 , 0.065, 0.07 , 0.075, 0.08 , 0.085,
0.09 , 0.095, 0.1 , 0.105, 0.11 , 0.115, 0.12 , 0.125,
0.13 , 0.135, 0.14 , 0.145, 0.15 , 0.155, 0.16 , 0.165,
0.17 , 0.175, 0.18 , 0.185, 0.19 , 0.195, 0.2 , 0.205,
0.21 , 0.215, 0.22 , 0.225, 0.23 , 0.235, 0.24 , 0.245,
0.25 , 0.255]
Note that I'm not wedded to cubic splines in particular. I'm open to any compact representation for approximating the [x, y] function that isn't computationally expensive to expand on the microcontroller.
Upvotes: 0
Views: 535
Reputation: 7862
I think cubic spline is probably the approach that best answers your question But I also think that the question "can you derive a continuous function" and what you really want to do are not exactly the same thing.
For how to best thin your data points, I think that will require some knowledge of the system such as the expected resolution in loop current and duty cycle. From the graph, you could probably use every other or even every third point and get good results.
But as @JamesPhillips suggests, it also looks like that you might be able to find piece-wise linear or cubic regions for the response. If that's sufficient, then you could record the region bounds and slope/intercept/quadratic for the sub-curves, which you probably can fit in the microcontroller memory.
Upvotes: 0
Reputation: 4647
When I noticed that the portion of the graph where loop current greater than 6.0 appears linear, I thought one possible approach is to to split the data set into pieces and fit those individually. Here is my attempt at doing this, with a high end piece, a low end piece, and two middle pieces. Single precision should be OK, and the client hardware can already perform numeric multiplication for the splines:
if x > 6.0
a = -9.7949290874469949E-02
b = 4.3620505659335194E-02
y = a + bx
else if x < 4.5:
a = 2.0780250294624176E-02
b = -1.1030255807503962E-02
c = 5.8098518234878981E-03
y = a + bx + cx^2
else if x < 5.2:
a = 1.9299476875427801E+00
b = -8.2789734912004187E-01
c = 9.3133373338805447E-02
y = a + bx + cx^2
else:
a = 5.2371635939198503E-02
b = 3.4449759555560976E-03
c = 2.5067846229176044E-03
y = a + bx + cx^2
Upvotes: 1