Interpolate X-Y coordinates with variable velocity to specified sampling frequency

13 次查看(过去 30 天)
Can anyone help me interpolate between XY position coordinates with varying velocities between the coordinates. For example, I have a 3xn array with X-Y coordinates (mm) and a linear velocity (mm/s) for traveling from i to i+1 coordinates. I would like to resample these data via linear interpolation at 60 Hz as a series of XY cooridnates in the time domain. For context, these are coordinates for a CNC machine where you specifiy the desired coordinates and a rate at which to move to those coordinates. I would like to calculate intermediate coordinates at 60 Hz.
Thank you.
  1 个评论
Cris LaPierre
Cris LaPierre 2021-6-3
You need to figure out the distance between the two points, and then the number of time steps (at 60 Hz) is needed to cover that distance at the indicated velocity. Only then can you use interpolation to figure out you X and Y values at each time step.
Because the velocities will change from one position to the next, you will likely need to do this in a loop.

请先登录,再进行评论。

采纳的回答

J. Alex Lee
J. Alex Lee 2021-6-3
编辑:J. Alex Lee 2021-6-3
I don't think you need loops...so assume your data is called XYV, and according to how you describe, I guess the last velocity point will be meaningless (i-th row velocity means the velocity it took to get from coordinates in row i to row i+1)
XYV = [
0,1,2,3;
0,2,5,8;
1,5,3,NaN]
XYV = 3×4
0 1 2 3 0 2 5 8 1 5 3 NaN
Distance traveled between rows is
dxy = diff(XYV(1:2,:),[],2)
dxy = 2×3
1 1 1 2 3 3
d = sqrt(sum(dxy.^2))
d = 1×3
2.2361 3.1623 3.1623
The time it took to move in each row
trow = d./XYV(3,1:end-1)
trow = 1×3
2.2361 0.6325 1.0541
So the timestamp for each row is
t = [0,cumsum(trow)]
t = 1×4
0 2.2361 2.8685 3.9226
And then you can do linear interpolations
tI = 0:1/60:t(end);
xI = interp1(t,XYV(1,:),tI);
yI = interp1(t,XYV(2,:),tI);
  2 个评论
Michael McGeehan
Michael McGeehan 2021-6-3
Thanks for your response. All of this makes sense to me except the tI and interpolation steps. My data start with 3x200 dimensions (200 coordinates), but at those steps, it becomes 1x14 for the tI, xI, and yI variables. I've attached a sample variable for reference.
Thank you for the help.
J. Alex Lee
J. Alex Lee 2021-6-3
  • Actually the velocity at i-th row corresponds to speed between the point at (i-1)th and (i)th row, rather than i and i+1 as you noted above. The actual data makes much more sense, incidentally.
  • So you need to shift the index
trow = d./XYV(3,2:end)
  • the speeds are such that your ending time is 0.1807 seconds (if above is correct). 60Hz sampling is every 0.0167 seconds, so you will only get few times between the start and end (11 when I ran it)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by