C# Lineare Interpolation

Habe ich Probleme, interpolieren Datei mit Daten, die ich aus umgewandelt .csv in einem array X-und Y-array, wobei X[0] entspricht Punkt Y[0] zum Beispiel.

Ich muss interpolieren zwischen den Werten zu geben, der mir doch glatt die Datei am Ende.
Ich bin mit einem Picoscope, um die Ausgabe der Funktion, was bedeutet, dass jede Zeile mit gleichem Abstand in der Zeit, so nur mit Y-Werten, das ist, warum ich bin versucht, dies zu tun in einer seltsamen Art und Weise, wenn Sie sehen, mein code.

Die Art der Werte, die es zu bewältigen hat, sind:

X     Y
0     0
2.5   0
2.5   12000
7.5   12000
7.5   3000
10    3000
10    6000
11    6625.254
12    7095.154

So, in dem 2 Y-Werte, die nebeneinander die gleichen sein eine gerade Linie zwischen Ihnen, aber wenn Sie variieren, wie die von X = 10 auf den Stationen, es wird ein Sinus in diesem Beispiel.

Schaue ich die Gleichungen für die interpolation etc. und andere Beiträge hier, aber ich habe nicht getan, dass diese Art der Mathematik für Jahre und leider kann ich nicht herausfinden, weil es gibt 2 unbekannte, und ich kann mir nicht vorstellen, wie Programm, dass in c#.

Was ich habe ist:

int a = 0, d = 0, q = 0;
bool up = false;
double times = 0, change = 0, points = 0, pointchange = 0; 
double[] newy = new double[8192];
while (a < sizeoffile-1 && d < 8192)
{
    Console.Write("...");
    if (Y[a] == Y[a+1])//if the 2 values are the same add correct number of lines in to make it last the correct time
    {
        times = (X[a] - X[a + 1]);//number of repetitions
        if ((X[a + 1] - X[a]) > times)//if that was a negative number try the other way around
            times = (X[a + 1] - X[a]);//number of repetitions 
        do
        {
            newy[d] = Y[a];//add the values to the newy array which replaces y later on in the program
            d++;//increment newy position
            q++;//reduce number of reps in this loop
        }
        while (q < times + 1 && d < 8192);
        q = 0;//reset reps
    }
    else if (Y[a] != Y[a + 1])//if the 2 values are not the same interpolate between them
    {
        change = (Y[a] - Y[a + 1]);//work out difference between the values
        up = true;//the waveform is increasing
        if ((Y[a + 1] - Y[a]) > change)//if that number was a negative try the other way around
        {
            change = (Y[a + 1] - Y[a]);//work out difference bwteen values
            up = false;//the waveform is decreasing
        }
        points = (X[a] - X[a + 1]);//work out amount of time between given points
        if ((X[a + 1] - X[a]) > points)//if that was a negative try other way around
            points = (X[a + 1] - X[a]);///work out amount of time between given points
        pointchange = (change / points);//calculate the amount per point in time the value changes by
        if (points > 1)//any lower and the values cause errors
        {
            newy[d] = Y[a];//load first point
            d++;
            do
            {
                if (up == true)//
                    newy[d] = ((newy[d - 1]) + pointchange);
                else if (up == false)
                    newy[d] = ((newy[d - 1]) - pointchange);
                d++;
                q++;
            }
            while (q < points + 1 && d < 8192);
            q = 0;
        }
        else if (points != 0 && points > 0)
        {
            newy[d] = Y[a];//load first point
            d++;
        }
    }
    a++;
}

und dies schafft eine enge Wellenform, aber es ist immer noch sehr steppy.

So kann jeder sehen, warum dies ist nicht sehr genau?
Wie verbessern Sie Ihre Genauigkeit?
Oder eine andere Möglichkeit dies zu tun, verwenden von arrays?

Dank für das schauen 🙂

InformationsquelleAutor user1548411 | 2012-10-11
Schreibe einen Kommentar