Interpolating between two 3d time dependent positions
20 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
River Vorse
le 1 Juin 2021
Commenté : Tahariet Sharon
le 8 Mar 2023
I'm trying to interpolate between 3d position values seperated by a 1 minute timestep. I have an array of position data <x,y,z> of size [500,000 x 3]. Each row of 3 values <x,y,z> represents a point in 3d space at a specific time (ex. 2 minutes). I'm trying to interpolate between each value so that I have a timestep in my data of 1 second. So I want to generate 59 pts between minute 1 and minute 2. For example: If t1 = 1min, <x1,y1,z1> = <1,1,1> and t2 = 2min, <x2,y2,z2> = <2,2,2>, then t3 = 1min 30 seconds and <x3,y3,z3> might equal ~ <1.5,1.5,1.5> using a linear interpolation method. My inclination is to use interpn(). Could anyone direct me how to set this up?
1 commentaire
Tahariet Sharon
le 8 Mar 2023
I have the same problem, only that instead of 3 points in space I have a whole 3D matrix in space at a given point.
I have 10 points in time for different configuations of the 3D matrix, and I want to interpolate several time points between each data point. How to go about this?
Réponse acceptée
Adam Danz
le 1 Juin 2021
Modifié(e) : Adam Danz
le 1 Juin 2021
There are multiple ways to do this. Here I show how to put your (x,y,z) coordinates into a timeseries and use resample to interpolate the 3D coordinates.
Main functions
Create an mx3 matrix of [x,y,z] coordinates
xyz is the only input in this demo. The rest of the demo can be copy-pasted.
th = linspace(0,31.5,50)';
xyz = [sin(th),cos(th),th];
Create a timeseries object at 2-minute intervals and interpolate at 60-sec intervals
Create an mx1 vector of time stamps at 2-minute intervals
timestamps = (0:2:size(xyz,1)*2-1)'; % minutes; col vector!x
Create a timeseries object
ts = timeseries(xyz, timestamps, 'Name', 'XYZdata'); % name optional
ts.TimeInfo.Units = 'Minutes';
Create an nx1 vector of time stamps at 1-second resolution. The vector spans the range of timestamps in your raw-data.
timestampsInterp = ts.Time(1) : 1/60 : ts.Time(end);
Interpolate, or resample at the new timestamps created above. Interpolation is linear by default; see the timeseries interpolation method in ts.DataInfo.Interpolation. See other interpolation options in resample>interpmethod and timeseries>DataInfo.
tsInt = resample(ts,timestampsInterp);
Extract the interpolated xyz data to an nx3 matrix (xyzInt). Note that this step could be skipped and you could work with the interpolated timeseries object directly.
xyzInt = tsInt.Data;
Plot the original and interpolated data
If you're planning on plotting your data, you may want to plot a subsection of the data since it is much larger than these demo data and will take a long time to render and will comsume much memory.
figure()
plot3(xyz(:,1),xyz(:,2),xyz(:,3),'bo','LineWidth',2,'DisplayName','Original (2-min)')
hold on
plot3(xyzInt(:,1),xyzInt(:,2),xyzInt(:,3),'r.','MarkerSize',3,'DisplayName','Interpolated (1-sec)')
grid on
legend('Location','SouthOutside')
Store the new interpolated data in a timetable
This, of course, is optional but it will be useful if you're planning on doing further time-based analysis.
TT = array2timetable(tsInt.Data,...
'RowTimes',seconds(tsInt.Time*60), ...
'VariableNames', {'x','y','z'});
head(TT) % view the first few rows
2 commentaires
Adam Danz
le 2 Juin 2021
Another approach may be to convert the data to a timetable at 2 min intervals and use retime to interpolate to seconds.
Tahariet Sharon
le 8 Mar 2023
I have the same problem, only that instead of 3 points in space I have a whole 3D matrix in space at a given point.
I have 10 points in time for different configuations of the 3D matrix, and I want to interpolate several time points between each data point. How to go about this?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!