MATLAB Answers

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

조회 수: 4(최근 30일)
Michael McGeehan
Michael McGeehan 2021년 6월 2일
댓글: J. Alex Lee 2021년 6월 3일
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 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 = [
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
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개)




Community Treasure Hunt

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

Start Hunting!

Translated by