I have a jagged float array chunks (float[][] chunks
), and I want to interpolate each chunk of floats (with length n) with a sample rate of x. For example, if chunks[0]
was {1f, 5f, 10f}
so n = 3 and lets say x = 12, I want:
1.0000
1.7273
2.4545
3.1818
3.9091
4.6364
5.4545
6.3636
7.2727
8.1818
9.0909
10.0000
I've found a way of doing this using the library MathNet.Numerics
, but it is very ineffecient. My code is below.
double[] d = new double[n];
d[0] = 1d;
for (int i = 1; i < d.Length; i++)
d[i] = d[i - 1] + (double)(x - 1)/(double)(n - 1);
for (int c = 0; c < chunks.Length; c++)
for (int j = 0; j < x; j++)
doubles.Add(Convert.ToSingle(Interpolate.Linear(d, chunks[c].Select(y => Convert.ToDouble(y))).Interpolate(j + 1)));
I then parse back the List<double>
into a jagged array.
This code basically mimics having a 2d plane for the interpolation, rather than just interpolating the numbers themselves (at least I think). MathNet.Numerics.Interpolate.Linear()
takes two double arrays, and this was the only way I managed to get proper results. However, it takes forever. Is there a better way to do this?