1
$\begingroup$

I am working on a project in which I am required to use Interpolation to create equally spaced position values as the position samples are not equally spaced due to varying train speed.

So, the total length of my data is 93636218. After interpolation, the length has reduced to 5506829. This is creating problem for me as I am unable to insert the interpolated values into my original data. I have used the following code for interpolation:

x = np.array(data['Position [m]'])
y = np.array(sensor data)
spacing = 0.01
position_equally_spaced_x = np.arange(x[0], x[-1], spacing)
sensor data_new = interp1d(x, y)(position_equally_spaced_x)
$\endgroup$
7
  • $\begingroup$ Why must the interpolated values be inserted back into the original data? There seems to be something missing in the problem statement. Does the code do the expected interpolation? $\endgroup$
    – Peter K.
    Oct 21, 2022 at 12:53
  • $\begingroup$ I need to insert the column back to the original data because there are other columns of my original data which I need to use for my classification problem $\endgroup$ Oct 21, 2022 at 13:17
  • $\begingroup$ @PeterK. I believe that she wants to convert an evenly spaced in time sequence into an evenly spaced in position sequence, and that the time samples don't always line up with the desired positions. $\endgroup$
    – TimWescott
    Oct 21, 2022 at 14:26
  • $\begingroup$ Is there a reason that simple linear interpolation doesn't work? $\endgroup$
    – TimWescott
    Oct 21, 2022 at 14:27
  • $\begingroup$ Yes exactly @TimWescott. Interpolation is necessary to remove noise in position space. But then it creates problem because the output of filtered position space data is not similar to my original data. And even some values are also not similar when compared to the original data $\endgroup$ Oct 21, 2022 at 14:36

1 Answer 1

2
$\begingroup$

After interpolation, the length has reduced to 5506829.

The length of your interpolation vector is $L = \frac{x[N-1]-x[0]}{\Delta}$ where ${\Delta}$ is the spacing $N$ the length of your $x$ vector. If you want the length of the interpolation vector to be the same size you need to choose the spacing accordingly, i.e. $L=N$. We get

$$\Delta = \frac{x[N-1]-x[0]}{N}$$

I need to insert the column back to the original data because there are other columns of my original data

That's unclear: This only make sense if all columns us the same x-coordinates, so you should already know what these are.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.