Interpolate X-Y coordinates with variable velocity to specified sampling frequency
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Michael McGeehan
el 2 de Jun. de 2021
Comentada: J. Alex Lee
el 3 de Jun. de 2021
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 comentario
Cris LaPierre
el 3 de Jun. de 2021
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.
Respuesta aceptada
J. Alex Lee
el 3 de Jun. de 2021
Editada: J. Alex Lee
el 3 de Jun. de 2021
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]
Distance traveled between rows is
dxy = diff(XYV(1:2,:),[],2)
d = sqrt(sum(dxy.^2))
The time it took to move in each row
trow = d./XYV(3,1:end-1)
So the timestamp for each row is
t = [0,cumsum(trow)]
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 comentarios
J. Alex Lee
el 3 de Jun. de 2021
- 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)
Más respuestas (0)
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!