KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm having issues interpolating a data file, which i have converted from .csv into an X array and Y array where X[0] corresponds to point Y[0] for example. I need to interpolate between the values to give me a smooth file at the end. I am using a Picoscope to output the function which means each line is equally spaced in time, so only using Y values, which is why I'm trying to do this in a strange way when you see my code. The kind of values it has to deal with are: 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 where 2 Y values next to each other are the same its a straight line between them but when they vary like from X = 10 on wards it becomes a sine wave in this example. I have been looking at the equations for interpolation etc and other posts on here but i haven't done that sort of maths for years and sadly i can't figure it out any more, because there's 2 unknowns and i can't think how to program that into c#. What i have is: 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[
Tags (comma-separated)
Save Edits
Cancel